summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp84
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h1
2 files changed, 79 insertions, 6 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 098dbdc..1dfcc4c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -1,1098 +1,1170 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <libetpan/libetpan.h> 2#include <libetpan/libetpan.h>
3#include <qpe/global.h> 3#include <qpe/global.h>
4 4
5#include "imapwrapper.h" 5#include "imapwrapper.h"
6#include "mailtypes.h" 6#include "mailtypes.h"
7#include "logindialog.h" 7#include "logindialog.h"
8 8
9IMAPwrapper::IMAPwrapper( IMAPaccount *a ) 9IMAPwrapper::IMAPwrapper( IMAPaccount *a )
10 : AbstractMail() 10 : AbstractMail()
11{ 11{
12 account = a; 12 account = a;
13 m_imap = 0; 13 m_imap = 0;
14 m_Lastmbox = ""; 14 m_Lastmbox = "";
15} 15}
16 16
17IMAPwrapper::~IMAPwrapper() 17IMAPwrapper::~IMAPwrapper()
18{ 18{
19 logout(); 19 logout();
20} 20}
21 21
22/* to avoid to often select statements in loops etc. 22/* to avoid to often select statements in loops etc.
23 we trust that we are logged in and connection is established!*/ 23 we trust that we are logged in and connection is established!*/
24int IMAPwrapper::selectMbox(const QString&mbox) 24int IMAPwrapper::selectMbox(const QString&mbox)
25{ 25{
26 if (mbox == m_Lastmbox) { 26 if (mbox == m_Lastmbox) {
27 return MAILIMAP_NO_ERROR; 27 return MAILIMAP_NO_ERROR;
28 } 28 }
29 int err = mailimap_select( m_imap, (char*)mbox.latin1()); 29 int err = mailimap_select( m_imap, (char*)mbox.latin1());
30 if ( err != MAILIMAP_NO_ERROR ) { 30 if ( err != MAILIMAP_NO_ERROR ) {
31 qDebug("error selecting mailbox: %s",m_imap->imap_response); 31 qDebug("error selecting mailbox: %s",m_imap->imap_response);
32 m_Lastmbox = ""; 32 m_Lastmbox = "";
33 return err; 33 return err;
34 } 34 }
35 m_Lastmbox = mbox; 35 m_Lastmbox = mbox;
36 return err; 36 return err;
37} 37}
38 38
39void IMAPwrapper::imap_progress( size_t current, size_t maximum ) 39void IMAPwrapper::imap_progress( size_t current, size_t maximum )
40{ 40{
41 qDebug( "IMAP: %i of %i", current, maximum ); 41 qDebug( "IMAP: %i of %i", current, maximum );
42} 42}
43 43
44bool IMAPwrapper::start_tls(bool force_tls)
45{
46 int err;
47 bool try_tls;
48 mailimap_capability_data * cap_data = 0;
49
50 err = mailimap_capability(m_imap,&cap_data);
51 if (err != MAILIMAP_NO_ERROR) {
52 Global::statusMessage("error getting capabilities!");
53 qDebug("error getting capabilities!");
54 return false;
55 }
56 clistiter * cur;
57 for(cur = clist_begin(cap_data->cap_list) ; cur != NULL;cur = clist_next(cur)) {
58 struct mailimap_capability * cap;
59 cap = (struct mailimap_capability *)clist_content(cur);
60 if (cap->cap_type == MAILIMAP_CAPABILITY_NAME) {
61 if (strcasecmp(cap->cap_data.cap_name, "STARTTLS") == 0) {
62 try_tls = true;
63 break;
64 }
65 }
66 }
67 if (cap_data) {
68 mailimap_capability_data_free(cap_data);
69 }
70 if (try_tls) {
71 err = mailimap_starttls(m_imap);
72 if (err != MAILIMAP_NO_ERROR && force_tls) {
73 Global::statusMessage(tr("Server has no TLS support!"));
74 qDebug("Server has no TLS support!");
75 try_tls = false;
76 } else {
77 mailstream_low * low;
78 mailstream_low * new_low;
79 low = mailstream_get_low(m_imap->imap_stream);
80 if (!low) {
81 try_tls = false;
82 } else {
83 int fd = mailstream_low_get_fd(low);
84 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
85 mailstream_low_free(low);
86 mailstream_set_low(m_imap->imap_stream, new_low);
87 } else {
88 try_tls = false;
89 }
90 }
91 }
92 }
93 return try_tls;
94}
95
44void IMAPwrapper::login() 96void IMAPwrapper::login()
45{ 97{
46 const char *server, *user, *pass; 98 const char *server, *user, *pass;
47 uint16_t port; 99 uint16_t port;
48 int err = MAILIMAP_NO_ERROR; 100 int err = MAILIMAP_NO_ERROR;
49 101
50 if (account->getOffline()) return; 102 if (account->getOffline()) return;
51 /* we are connected this moment */ 103 /* we are connected this moment */
52 /* TODO: setup a timer holding the line or if connection closed - delete the value */ 104 /* TODO: setup a timer holding the line or if connection closed - delete the value */
53 if (m_imap) { 105 if (m_imap) {
54 err = mailimap_noop(m_imap); 106 err = mailimap_noop(m_imap);
55 if (err!=MAILIMAP_NO_ERROR) { 107 if (err!=MAILIMAP_NO_ERROR) {
56 logout(); 108 logout();
57 } else { 109 } else {
58 mailstream_flush(m_imap->imap_stream); 110 mailstream_flush(m_imap->imap_stream);
59 return; 111 return;
60 } 112 }
61 } 113 }
62 server = account->getServer().latin1(); 114 server = account->getServer().latin1();
63 port = account->getPort().toUInt(); 115 port = account->getPort().toUInt();
64 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 116 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
65 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 117 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
66 login.show(); 118 login.show();
67 if ( QDialog::Accepted == login.exec() ) { 119 if ( QDialog::Accepted == login.exec() ) {
68 // ok 120 // ok
69 user = login.getUser().latin1(); 121 user = login.getUser().latin1();
70 pass = login.getPassword().latin1(); 122 pass = login.getPassword().latin1();
71 } else { 123 } else {
72 // cancel 124 // cancel
73 qDebug( "IMAP: Login canceled" ); 125 qDebug( "IMAP: Login canceled" );
74 return; 126 return;
75 } 127 }
76 } else { 128 } else {
77 user = account->getUser().latin1(); 129 user = account->getUser().latin1();
78 pass = account->getPassword().latin1(); 130 pass = account->getPassword().latin1();
79 } 131 }
80 132
81 m_imap = mailimap_new( 20, &imap_progress ); 133 m_imap = mailimap_new( 20, &imap_progress );
82 134
83
84
85 /* connect */ 135 /* connect */
86
87 bool ssl = false; 136 bool ssl = false;
137 bool try_tls = false;
138 bool force_tls = false;
88 139
89 if ( account->ConnectionType() == 2 ) { 140 if ( account->ConnectionType() == 2 ) {
90 ssl = true; 141 ssl = true;
91 } 142 }
143 if (account->ConnectionType()==1) {
144 force_tls = true;
145 }
92 146
93 if ( ssl ) { 147 if ( ssl ) {
94 qDebug( "using ssl" ); 148 qDebug( "using ssl" );
95 err = mailimap_ssl_connect( m_imap, (char*)server, port ); 149 err = mailimap_ssl_connect( m_imap, (char*)server, port );
96 } else { 150 } else {
97 err = mailimap_socket_connect( m_imap, (char*)server, port ); 151 err = mailimap_socket_connect( m_imap, (char*)server, port );
98 } 152 }
99 153
100 if ( err != MAILIMAP_NO_ERROR && 154 if ( err != MAILIMAP_NO_ERROR &&
101 err != MAILIMAP_NO_ERROR_AUTHENTICATED && 155 err != MAILIMAP_NO_ERROR_AUTHENTICATED &&
102 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { 156 err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) {
103 QString failure = ""; 157 QString failure = "";
104 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { 158 if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) {
105 failure="Connection refused"; 159 failure="Connection refused";
106 } else { 160 } else {
107 failure="Unknown failure"; 161 failure="Unknown failure";
108 } 162 }
109 Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); 163 Global::statusMessage(tr("error connecting imap server: %1").arg(failure));
110 mailimap_free( m_imap ); 164 mailimap_free( m_imap );
111 m_imap = 0; 165 m_imap = 0;
112 return; 166 return;
113 } 167 }
114 168
169 if (!ssl) {
170 try_tls = start_tls(force_tls);
171 }
172
173 bool ok = true;
174 if (force_tls && !try_tls) {
175 Global::statusMessage(tr("Server has no TLS support!"));
176 qDebug("Server has no TLS support!");
177 ok = false;
178 }
179
180
115 /* login */ 181 /* login */
116 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); 182
117 if ( err != MAILIMAP_NO_ERROR ) { 183 if (ok) {
118 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); 184 err = mailimap_login_simple( m_imap, (char*)user, (char*)pass );
185 if ( err != MAILIMAP_NO_ERROR ) {
186 Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response));
187 ok = false;
188 }
189 }
190 if (!ok) {
119 err = mailimap_close( m_imap ); 191 err = mailimap_close( m_imap );
120 mailimap_free( m_imap ); 192 mailimap_free( m_imap );
121 m_imap = 0; 193 m_imap = 0;
122 } 194 }
123} 195}
124 196
125void IMAPwrapper::logout() 197void IMAPwrapper::logout()
126{ 198{
127 int err = MAILIMAP_NO_ERROR; 199 int err = MAILIMAP_NO_ERROR;
128 if (!m_imap) return; 200 if (!m_imap) return;
129 err = mailimap_logout( m_imap ); 201 err = mailimap_logout( m_imap );
130 err = mailimap_close( m_imap ); 202 err = mailimap_close( m_imap );
131 mailimap_free( m_imap ); 203 mailimap_free( m_imap );
132 m_imap = 0; 204 m_imap = 0;
133 m_Lastmbox = ""; 205 m_Lastmbox = "";
134} 206}
135 207
136void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) 208void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
137{ 209{
138 int err = MAILIMAP_NO_ERROR; 210 int err = MAILIMAP_NO_ERROR;
139 clist *result = 0; 211 clist *result = 0;
140 clistcell *current; 212 clistcell *current;
141 mailimap_fetch_type *fetchType = 0; 213 mailimap_fetch_type *fetchType = 0;
142 mailimap_set *set = 0; 214 mailimap_set *set = 0;
143 215
144 login(); 216 login();
145 if (!m_imap) { 217 if (!m_imap) {
146 return; 218 return;
147 } 219 }
148 /* select mailbox READONLY for operations */ 220 /* select mailbox READONLY for operations */
149 err = selectMbox(mailbox); 221 err = selectMbox(mailbox);
150 if ( err != MAILIMAP_NO_ERROR ) { 222 if ( err != MAILIMAP_NO_ERROR ) {
151 return; 223 return;
152 } 224 }
153 225
154 int last = m_imap->imap_selection_info->sel_exists; 226 int last = m_imap->imap_selection_info->sel_exists;
155 227
156 if (last == 0) { 228 if (last == 0) {
157 Global::statusMessage(tr("Mailbox has no mails")); 229 Global::statusMessage(tr("Mailbox has no mails"));
158 return; 230 return;
159 } else { 231 } else {
160 } 232 }
161 233
162 /* the range has to start at 1!!! not with 0!!!! */ 234 /* the range has to start at 1!!! not with 0!!!! */
163 set = mailimap_set_new_interval( 1, last ); 235 set = mailimap_set_new_interval( 1, last );
164 fetchType = mailimap_fetch_type_new_fetch_att_list_empty(); 236 fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
165 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope()); 237 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
166 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags()); 238 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
167 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate()); 239 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
168 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size()); 240 mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
169 241
170 err = mailimap_fetch( m_imap, set, fetchType, &result ); 242 err = mailimap_fetch( m_imap, set, fetchType, &result );
171 mailimap_set_free( set ); 243 mailimap_set_free( set );
172 mailimap_fetch_type_free( fetchType ); 244 mailimap_fetch_type_free( fetchType );
173 245
174 QString date,subject,from; 246 QString date,subject,from;
175 247
176 if ( err == MAILIMAP_NO_ERROR ) { 248 if ( err == MAILIMAP_NO_ERROR ) {
177 mailimap_msg_att * msg_att; 249 mailimap_msg_att * msg_att;
178 int i = 0; 250 int i = 0;
179 for (current = clist_begin(result); current != 0; current=clist_next(current)) { 251 for (current = clist_begin(result); current != 0; current=clist_next(current)) {
180 ++i; 252 ++i;
181 msg_att = (mailimap_msg_att*)current->data; 253 msg_att = (mailimap_msg_att*)current->data;
182 RecMail*m = parse_list_result(msg_att); 254 RecMail*m = parse_list_result(msg_att);
183 if (m) { 255 if (m) {
184 m->setNumber(i); 256 m->setNumber(i);
185 m->setMbox(mailbox); 257 m->setMbox(mailbox);
186 m->setWrapper(this); 258 m->setWrapper(this);
187 target.append(m); 259 target.append(m);
188 } 260 }
189 } 261 }
190 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count())); 262 Global::statusMessage(tr("Mailbox has %1 mails").arg(target.count()));
191 } else { 263 } else {
192 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); 264 Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response));
193 } 265 }
194 if (result) mailimap_fetch_list_free(result); 266 if (result) mailimap_fetch_list_free(result);
195} 267}
196 268
197QList<Folder>* IMAPwrapper::listFolders() 269QList<Folder>* IMAPwrapper::listFolders()
198{ 270{
199 const char *path, *mask; 271 const char *path, *mask;
200 int err = MAILIMAP_NO_ERROR; 272 int err = MAILIMAP_NO_ERROR;
201 clist *result = 0; 273 clist *result = 0;
202 clistcell *current = 0; 274 clistcell *current = 0;
203 clistcell*cur_flag = 0; 275 clistcell*cur_flag = 0;
204 mailimap_mbx_list_flags*bflags = 0; 276 mailimap_mbx_list_flags*bflags = 0;
205 277
206 QList<Folder> * folders = new QList<Folder>(); 278 QList<Folder> * folders = new QList<Folder>();
207 folders->setAutoDelete( false ); 279 folders->setAutoDelete( false );
208 login(); 280 login();
209 if (!m_imap) { 281 if (!m_imap) {
210 return folders; 282 return folders;
211 } 283 }
212 284
213/* 285/*
214 * First we have to check for INBOX 'cause it sometimes it's not inside the path. 286 * First we have to check for INBOX 'cause it sometimes it's not inside the path.
215 * We must not forget to filter them out in next loop! 287 * We must not forget to filter them out in next loop!
216 * it seems like ugly code. and yes - it is ugly code. but the best way. 288 * it seems like ugly code. and yes - it is ugly code. but the best way.
217 */ 289 */
218 QString temp; 290 QString temp;
219 mask = "INBOX" ; 291 mask = "INBOX" ;
220 mailimap_mailbox_list *list; 292 mailimap_mailbox_list *list;
221 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); 293 err = mailimap_list( m_imap, (char*)"", (char*)mask, &result );
222 QString del; 294 QString del;
223 bool selectable = true; 295 bool selectable = true;
224 bool no_inferiors = false; 296 bool no_inferiors = false;
225 if ( err == MAILIMAP_NO_ERROR ) { 297 if ( err == MAILIMAP_NO_ERROR ) {
226 current = result->first; 298 current = result->first;
227 for ( int i = result->count; i > 0; i-- ) { 299 for ( int i = result->count; i > 0; i-- ) {
228 list = (mailimap_mailbox_list *) current->data; 300 list = (mailimap_mailbox_list *) current->data;
229 // it is better use the deep copy mechanism of qt itself 301 // it is better use the deep copy mechanism of qt itself
230 // instead of using strdup! 302 // instead of using strdup!
231 temp = list->mb_name; 303 temp = list->mb_name;
232 del = list->mb_delimiter; 304 del = list->mb_delimiter;
233 current = current->next; 305 current = current->next;
234 if ( (bflags = list->mb_flag) ) { 306 if ( (bflags = list->mb_flag) ) {
235 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 307 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
236 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 308 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
237 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 309 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
238 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 310 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
239 no_inferiors = true; 311 no_inferiors = true;
240 } 312 }
241 } 313 }
242 } 314 }
243 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 315 folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
244 } 316 }
245 } else { 317 } else {
246 qDebug("error fetching folders: %s",m_imap->imap_response); 318 qDebug("error fetching folders: %s",m_imap->imap_response);
247 } 319 }
248 mailimap_list_result_free( result ); 320 mailimap_list_result_free( result );
249 321
250/* 322/*
251 * second stage - get the other then inbox folders 323 * second stage - get the other then inbox folders
252 */ 324 */
253 mask = "*" ; 325 mask = "*" ;
254 path = account->getPrefix().latin1(); 326 path = account->getPrefix().latin1();
255 if (!path) path = ""; 327 if (!path) path = "";
256 qDebug(path); 328 qDebug(path);
257 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); 329 err = mailimap_list( m_imap, (char*)path, (char*)mask, &result );
258 if ( err == MAILIMAP_NO_ERROR ) { 330 if ( err == MAILIMAP_NO_ERROR ) {
259 current = result->first; 331 current = result->first;
260 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { 332 for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) {
261 no_inferiors = false; 333 no_inferiors = false;
262 list = (mailimap_mailbox_list *) current->data; 334 list = (mailimap_mailbox_list *) current->data;
263 // it is better use the deep copy mechanism of qt itself 335 // it is better use the deep copy mechanism of qt itself
264 // instead of using strdup! 336 // instead of using strdup!
265 temp = list->mb_name; 337 temp = list->mb_name;
266 if (temp.lower()=="inbox") 338 if (temp.lower()=="inbox")
267 continue; 339 continue;
268 if (temp.lower()==account->getPrefix().lower()) 340 if (temp.lower()==account->getPrefix().lower())
269 continue; 341 continue;
270 if ( (bflags = list->mb_flag) ) { 342 if ( (bflags = list->mb_flag) ) {
271 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& 343 selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&&
272 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); 344 bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT);
273 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { 345 for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) {
274 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { 346 if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) {
275 no_inferiors = true; 347 no_inferiors = true;
276 } 348 }
277 } 349 }
278 } 350 }
279 del = list->mb_delimiter; 351 del = list->mb_delimiter;
280 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); 352 folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix()));
281 } 353 }
282 } else { 354 } else {
283 qDebug("error fetching folders %s",m_imap->imap_response); 355 qDebug("error fetching folders %s",m_imap->imap_response);
284 } 356 }
285 if (result) mailimap_list_result_free( result ); 357 if (result) mailimap_list_result_free( result );
286 return folders; 358 return folders;
287} 359}
288 360
289RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) 361RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
290{ 362{
291 RecMail * m = 0; 363 RecMail * m = 0;
292 mailimap_msg_att_item *item=0; 364 mailimap_msg_att_item *item=0;
293 clistcell *current,*c,*cf; 365 clistcell *current,*c,*cf;
294 mailimap_msg_att_dynamic*flist; 366 mailimap_msg_att_dynamic*flist;
295 mailimap_flag_fetch*cflag; 367 mailimap_flag_fetch*cflag;
296 int size; 368 int size;
297 QBitArray mFlags(7); 369 QBitArray mFlags(7);
298 QStringList addresslist; 370 QStringList addresslist;
299 371
300 if (!m_att) { 372 if (!m_att) {
301 return m; 373 return m;
302 } 374 }
303 m = new RecMail(); 375 m = new RecMail();
304 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) { 376 for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
305 current = c; 377 current = c;
306 size = 0; 378 size = 0;
307 item = (mailimap_msg_att_item*)current->data; 379 item = (mailimap_msg_att_item*)current->data;
308 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) { 380 if (item->att_type!=MAILIMAP_MSG_ATT_ITEM_STATIC) {
309 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn; 381 flist = (mailimap_msg_att_dynamic*)item->att_data.att_dyn;
310 if (!flist->att_list) { 382 if (!flist->att_list) {
311 continue; 383 continue;
312 } 384 }
313 cf = flist->att_list->first; 385 cf = flist->att_list->first;
314 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) { 386 for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
315 cflag = (mailimap_flag_fetch*)cf->data; 387 cflag = (mailimap_flag_fetch*)cf->data;
316 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) { 388 if (cflag->fl_type==MAILIMAP_FLAG_FETCH_OTHER && cflag->fl_flag!=0) {
317 switch (cflag->fl_flag->fl_type) { 389 switch (cflag->fl_flag->fl_type) {
318 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */ 390 case MAILIMAP_FLAG_ANSWERED: /* \Answered flag */
319 mFlags.setBit(FLAG_ANSWERED); 391 mFlags.setBit(FLAG_ANSWERED);
320 break; 392 break;
321 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */ 393 case MAILIMAP_FLAG_FLAGGED: /* \Flagged flag */
322 mFlags.setBit(FLAG_FLAGGED); 394 mFlags.setBit(FLAG_FLAGGED);
323 break; 395 break;
324 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */ 396 case MAILIMAP_FLAG_DELETED: /* \Deleted flag */
325 mFlags.setBit(FLAG_DELETED); 397 mFlags.setBit(FLAG_DELETED);
326 break; 398 break;
327 case MAILIMAP_FLAG_SEEN: /* \Seen flag */ 399 case MAILIMAP_FLAG_SEEN: /* \Seen flag */
328 mFlags.setBit(FLAG_SEEN); 400 mFlags.setBit(FLAG_SEEN);
329 break; 401 break;
330 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */ 402 case MAILIMAP_FLAG_DRAFT: /* \Draft flag */
331 mFlags.setBit(FLAG_DRAFT); 403 mFlags.setBit(FLAG_DRAFT);
332 break; 404 break;
333 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */ 405 case MAILIMAP_FLAG_KEYWORD: /* keyword flag */
334 break; 406 break;
335 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */ 407 case MAILIMAP_FLAG_EXTENSION: /* \extension flag */
336 break; 408 break;
337 default: 409 default:
338 break; 410 break;
339 } 411 }
340 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) { 412 } else if (cflag->fl_type==MAILIMAP_FLAG_FETCH_RECENT) {
341 mFlags.setBit(FLAG_RECENT); 413 mFlags.setBit(FLAG_RECENT);
342 } 414 }
343 } 415 }
344 continue; 416 continue;
345 } 417 }
346 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) { 418 if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
347 mailimap_envelope * head = item->att_data.att_static->att_data.att_env; 419 mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
348 m->setDate(head->env_date); 420 m->setDate(head->env_date);
349 m->setSubject(convert_String((const char*)head->env_subject)); 421 m->setSubject(convert_String((const char*)head->env_subject));
350 //m->setSubject(head->env_subject); 422 //m->setSubject(head->env_subject);
351 if (head->env_from!=NULL) { 423 if (head->env_from!=NULL) {
352 addresslist = address_list_to_stringlist(head->env_from->frm_list); 424 addresslist = address_list_to_stringlist(head->env_from->frm_list);
353 if (addresslist.count()) { 425 if (addresslist.count()) {
354 m->setFrom(addresslist.first()); 426 m->setFrom(addresslist.first());
355 } 427 }
356 } 428 }
357 if (head->env_to!=NULL) { 429 if (head->env_to!=NULL) {
358 addresslist = address_list_to_stringlist(head->env_to->to_list); 430 addresslist = address_list_to_stringlist(head->env_to->to_list);
359 m->setTo(addresslist); 431 m->setTo(addresslist);
360 } 432 }
361 if (head->env_cc!=NULL) { 433 if (head->env_cc!=NULL) {
362 addresslist = address_list_to_stringlist(head->env_cc->cc_list); 434 addresslist = address_list_to_stringlist(head->env_cc->cc_list);
363 m->setCC(addresslist); 435 m->setCC(addresslist);
364 } 436 }
365 if (head->env_bcc!=NULL) { 437 if (head->env_bcc!=NULL) {
366 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); 438 addresslist = address_list_to_stringlist(head->env_bcc->bcc_list);
367 m->setBcc(addresslist); 439 m->setBcc(addresslist);
368 } 440 }
369 if (head->env_reply_to!=NULL) { 441 if (head->env_reply_to!=NULL) {
370 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 442 addresslist = address_list_to_stringlist(head->env_reply_to->rt_list);
371 if (addresslist.count()) { 443 if (addresslist.count()) {
372 m->setReplyto(addresslist.first()); 444 m->setReplyto(addresslist.first());
373 } 445 }
374 } 446 }
375 m->setMsgid(QString(head->env_message_id)); 447 m->setMsgid(QString(head->env_message_id));
376 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { 448 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
377#if 0 449#if 0
378 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; 450 mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
379 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); 451 QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
380 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec); 452 qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
381 qDebug(da.toString()); 453 qDebug(da.toString());
382#endif 454#endif
383 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { 455 } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
384 size = item->att_data.att_static->att_data.att_rfc822_size; 456 size = item->att_data.att_static->att_data.att_rfc822_size;
385 } 457 }
386 } 458 }
387 /* msg is already deleted */ 459 /* msg is already deleted */
388 if (mFlags.testBit(FLAG_DELETED) && m) { 460 if (mFlags.testBit(FLAG_DELETED) && m) {
389 delete m; 461 delete m;
390 m = 0; 462 m = 0;
391 } 463 }
392 if (m) { 464 if (m) {
393 m->setFlags(mFlags); 465 m->setFlags(mFlags);
394 m->setMsgsize(size); 466 m->setMsgsize(size);
395 } 467 }
396 return m; 468 return m;
397} 469}
398 470
399RecBody IMAPwrapper::fetchBody(const RecMail&mail) 471RecBody IMAPwrapper::fetchBody(const RecMail&mail)
400{ 472{
401 RecBody body; 473 RecBody body;
402 const char *mb; 474 const char *mb;
403 int err = MAILIMAP_NO_ERROR; 475 int err = MAILIMAP_NO_ERROR;
404 clist *result = 0; 476 clist *result = 0;
405 clistcell *current; 477 clistcell *current;
406 mailimap_fetch_att *fetchAtt = 0; 478 mailimap_fetch_att *fetchAtt = 0;
407 mailimap_fetch_type *fetchType = 0; 479 mailimap_fetch_type *fetchType = 0;
408 mailimap_set *set = 0; 480 mailimap_set *set = 0;
409 mailimap_body*body_desc = 0; 481 mailimap_body*body_desc = 0;
410 482
411 mb = mail.getMbox().latin1(); 483 mb = mail.getMbox().latin1();
412 484
413 login(); 485 login();
414 if (!m_imap) { 486 if (!m_imap) {
415 return body; 487 return body;
416 } 488 }
417 err = selectMbox(mail.getMbox()); 489 err = selectMbox(mail.getMbox());
418 if ( err != MAILIMAP_NO_ERROR ) { 490 if ( err != MAILIMAP_NO_ERROR ) {
419 return body; 491 return body;
420 } 492 }
421 493
422 /* the range has to start at 1!!! not with 0!!!! */ 494 /* the range has to start at 1!!! not with 0!!!! */
423 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); 495 set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
424 fetchAtt = mailimap_fetch_att_new_bodystructure(); 496 fetchAtt = mailimap_fetch_att_new_bodystructure();
425 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); 497 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
426 err = mailimap_fetch( m_imap, set, fetchType, &result ); 498 err = mailimap_fetch( m_imap, set, fetchType, &result );
427 mailimap_set_free( set ); 499 mailimap_set_free( set );
428 mailimap_fetch_type_free( fetchType ); 500 mailimap_fetch_type_free( fetchType );
429 501
430 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
431 mailimap_msg_att * msg_att; 503 mailimap_msg_att * msg_att;
432 msg_att = (mailimap_msg_att*)current->data; 504 msg_att = (mailimap_msg_att*)current->data;
433 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; 505 mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data;
434 QValueList<int> path; 506 QValueList<int> path;
435 body_desc = item->att_data.att_static->att_data.att_body; 507 body_desc = item->att_data.att_static->att_data.att_body;
436 traverseBody(mail,body_desc,body,0,path); 508 traverseBody(mail,body_desc,body,0,path);
437 } else { 509 } else {
438 qDebug("error fetching body: %s",m_imap->imap_response); 510 qDebug("error fetching body: %s",m_imap->imap_response);
439 } 511 }
440 if (result) mailimap_fetch_list_free(result); 512 if (result) mailimap_fetch_list_free(result);
441 return body; 513 return body;
442} 514}
443 515
444QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 516QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
445{ 517{
446 QStringList l; 518 QStringList l;
447 QString from; 519 QString from;
448 bool named_from; 520 bool named_from;
449 clistcell *current = NULL; 521 clistcell *current = NULL;
450 mailimap_address * current_address=NULL; 522 mailimap_address * current_address=NULL;
451 if (!list) { 523 if (!list) {
452 return l; 524 return l;
453 } 525 }
454 unsigned int count = 0; 526 unsigned int count = 0;
455 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 527 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
456 from = ""; 528 from = "";
457 named_from = false; 529 named_from = false;
458 current_address=(mailimap_address*)current->data; 530 current_address=(mailimap_address*)current->data;
459 if (current_address->ad_personal_name){ 531 if (current_address->ad_personal_name){
460 from+=convert_String((const char*)current_address->ad_personal_name); 532 from+=convert_String((const char*)current_address->ad_personal_name);
461 from+=" "; 533 from+=" ";
462 named_from = true; 534 named_from = true;
463 } 535 }
464 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 536 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
465 from+="<"; 537 from+="<";
466 } 538 }
467 if (current_address->ad_mailbox_name) { 539 if (current_address->ad_mailbox_name) {
468 from+=QString(current_address->ad_mailbox_name); 540 from+=QString(current_address->ad_mailbox_name);
469 from+="@"; 541 from+="@";
470 } 542 }
471 if (current_address->ad_host_name) { 543 if (current_address->ad_host_name) {
472 from+=QString(current_address->ad_host_name); 544 from+=QString(current_address->ad_host_name);
473 } 545 }
474 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 546 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
475 from+=">"; 547 from+=">";
476 } 548 }
477 l.append(QString(from)); 549 l.append(QString(from));
478 if (++count > 99) { 550 if (++count > 99) {
479 break; 551 break;
480 } 552 }
481 } 553 }
482 return l; 554 return l;
483} 555}
484 556
485encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 557encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
486{ 558{
487 encodedString*res=new encodedString; 559 encodedString*res=new encodedString;
488 int err; 560 int err;
489 mailimap_fetch_type *fetchType; 561 mailimap_fetch_type *fetchType;
490 mailimap_set *set; 562 mailimap_set *set;
491 clistcell*current,*cur; 563 clistcell*current,*cur;
492 mailimap_section_part * section_part = 0; 564 mailimap_section_part * section_part = 0;
493 mailimap_section_spec * section_spec = 0; 565 mailimap_section_spec * section_spec = 0;
494 mailimap_section * section = 0; 566 mailimap_section * section = 0;
495 mailimap_fetch_att * fetch_att = 0; 567 mailimap_fetch_att * fetch_att = 0;
496 568
497 login(); 569 login();
498 if (!m_imap) { 570 if (!m_imap) {
499 return res; 571 return res;
500 } 572 }
501 if (!internal_call) { 573 if (!internal_call) {
502 err = selectMbox(mail.getMbox()); 574 err = selectMbox(mail.getMbox());
503 if ( err != MAILIMAP_NO_ERROR ) { 575 if ( err != MAILIMAP_NO_ERROR ) {
504 return res; 576 return res;
505 } 577 }
506 } 578 }
507 set = mailimap_set_new_single(mail.getNumber()); 579 set = mailimap_set_new_single(mail.getNumber());
508 580
509 clist*id_list = 0; 581 clist*id_list = 0;
510 582
511 /* if path == empty then its a request for the whole rfc822 mail and generates 583 /* if path == empty then its a request for the whole rfc822 mail and generates
512 a "fetch <id> (body[])" statement on imap server */ 584 a "fetch <id> (body[])" statement on imap server */
513 if (path.count()>0 ) { 585 if (path.count()>0 ) {
514 id_list = clist_new(); 586 id_list = clist_new();
515 for (unsigned j=0; j < path.count();++j) { 587 for (unsigned j=0; j < path.count();++j) {
516 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 588 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
517 *p_id = path[j]; 589 *p_id = path[j];
518 clist_append(id_list,p_id); 590 clist_append(id_list,p_id);
519 } 591 }
520 section_part = mailimap_section_part_new(id_list); 592 section_part = mailimap_section_part_new(id_list);
521 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 593 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
522 } 594 }
523 595
524 section = mailimap_section_new(section_spec); 596 section = mailimap_section_new(section_spec);
525 fetch_att = mailimap_fetch_att_new_body_section(section); 597 fetch_att = mailimap_fetch_att_new_body_section(section);
526 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 598 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
527 599
528 clist*result = 0; 600 clist*result = 0;
529 601
530 err = mailimap_fetch( m_imap, set, fetchType, &result ); 602 err = mailimap_fetch( m_imap, set, fetchType, &result );
531 mailimap_set_free( set ); 603 mailimap_set_free( set );
532 mailimap_fetch_type_free( fetchType ); 604 mailimap_fetch_type_free( fetchType );
533 605
534 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 606 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
535 mailimap_msg_att * msg_att; 607 mailimap_msg_att * msg_att;
536 msg_att = (mailimap_msg_att*)current->data; 608 msg_att = (mailimap_msg_att*)current->data;
537 mailimap_msg_att_item*msg_att_item; 609 mailimap_msg_att_item*msg_att_item;
538 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 610 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
539 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 611 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
540 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 612 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
541 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 613 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
542 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 614 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
543 /* detach - we take over the content */ 615 /* detach - we take over the content */
544 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 616 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
545 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 617 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
546 } 618 }
547 } 619 }
548 } 620 }
549 } else { 621 } else {
550 qDebug("error fetching text: %s",m_imap->imap_response); 622 qDebug("error fetching text: %s",m_imap->imap_response);
551 } 623 }
552 if (result) mailimap_fetch_list_free(result); 624 if (result) mailimap_fetch_list_free(result);
553 return res; 625 return res;
554} 626}
555 627
556/* current_recursion is for recursive calls. 628/* current_recursion is for recursive calls.
557 current_count means the position inside the internal loop! */ 629 current_count means the position inside the internal loop! */
558void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 630void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
559 int current_recursion,QValueList<int>recList,int current_count) 631 int current_recursion,QValueList<int>recList,int current_count)
560{ 632{
561 if (!body || current_recursion>=10) { 633 if (!body || current_recursion>=10) {
562 return; 634 return;
563 } 635 }
564 switch (body->bd_type) { 636 switch (body->bd_type) {
565 case MAILIMAP_BODY_1PART: 637 case MAILIMAP_BODY_1PART:
566 { 638 {
567 QValueList<int>countlist = recList; 639 QValueList<int>countlist = recList;
568 countlist.append(current_count); 640 countlist.append(current_count);
569 RecPart currentPart; 641 RecPart currentPart;
570 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 642 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
571 QString id(""); 643 QString id("");
572 currentPart.setPositionlist(countlist); 644 currentPart.setPositionlist(countlist);
573 for (unsigned int j = 0; j < countlist.count();++j) { 645 for (unsigned int j = 0; j < countlist.count();++j) {
574 id+=(j>0?" ":""); 646 id+=(j>0?" ":"");
575 id+=QString("%1").arg(countlist[j]); 647 id+=QString("%1").arg(countlist[j]);
576 } 648 }
577 qDebug("ID = %s",id.latin1()); 649 qDebug("ID = %s",id.latin1());
578 currentPart.setIdentifier(id); 650 currentPart.setIdentifier(id);
579 fillSinglePart(currentPart,part1); 651 fillSinglePart(currentPart,part1);
580 /* important: Check for is NULL 'cause a body can be empty! 652 /* important: Check for is NULL 'cause a body can be empty!
581 And we put it only into the mail if it is the FIRST part */ 653 And we put it only into the mail if it is the FIRST part */
582 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 654 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
583 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 655 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
584 target_body.setDescription(currentPart); 656 target_body.setDescription(currentPart);
585 target_body.setBodytext(body_text); 657 target_body.setBodytext(body_text);
586 if (countlist.count()>1) { 658 if (countlist.count()>1) {
587 target_body.addPart(currentPart); 659 target_body.addPart(currentPart);
588 } 660 }
589 } else { 661 } else {
590 target_body.addPart(currentPart); 662 target_body.addPart(currentPart);
591 } 663 }
592 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 664 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
593 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 665 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
594 } 666 }
595 } 667 }
596 break; 668 break;
597 case MAILIMAP_BODY_MPART: 669 case MAILIMAP_BODY_MPART:
598 { 670 {
599 QValueList<int>countlist = recList; 671 QValueList<int>countlist = recList;
600 clistcell*current=0; 672 clistcell*current=0;
601 mailimap_body*current_body=0; 673 mailimap_body*current_body=0;
602 unsigned int ccount = 1; 674 unsigned int ccount = 1;
603 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 675 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
604 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 676 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
605 current_body = (mailimap_body*)current->data; 677 current_body = (mailimap_body*)current->data;
606 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 678 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
607 RecPart targetPart; 679 RecPart targetPart;
608 targetPart.setType("multipart"); 680 targetPart.setType("multipart");
609 fillMultiPart(targetPart,mailDescription); 681 fillMultiPart(targetPart,mailDescription);
610 countlist.append(current_count); 682 countlist.append(current_count);
611 targetPart.setPositionlist(countlist); 683 targetPart.setPositionlist(countlist);
612 target_body.addPart(targetPart); 684 target_body.addPart(targetPart);
613 QString id(""); 685 QString id("");
614 for (unsigned int j = 0; j < countlist.count();++j) { 686 for (unsigned int j = 0; j < countlist.count();++j) {
615 id+=(j>0?" ":""); 687 id+=(j>0?" ":"");
616 id+=QString("%1").arg(countlist[j]); 688 id+=QString("%1").arg(countlist[j]);
617 } 689 }
618 qDebug("ID(mpart) = %s",id.latin1()); 690 qDebug("ID(mpart) = %s",id.latin1());
619 } 691 }
620 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount); 692 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
621 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 693 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
622 countlist = recList; 694 countlist = recList;
623 } 695 }
624 ++ccount; 696 ++ccount;
625 } 697 }
626 } 698 }
627 break; 699 break;
628 default: 700 default:
629 break; 701 break;
630 } 702 }
631} 703}
632 704
633void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 705void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
634{ 706{
635 if (!Description) { 707 if (!Description) {
636 return; 708 return;
637 } 709 }
638 switch (Description->bd_type) { 710 switch (Description->bd_type) {
639 case MAILIMAP_BODY_TYPE_1PART_TEXT: 711 case MAILIMAP_BODY_TYPE_1PART_TEXT:
640 target_part.setType("text"); 712 target_part.setType("text");
641 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 713 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
642 break; 714 break;
643 case MAILIMAP_BODY_TYPE_1PART_BASIC: 715 case MAILIMAP_BODY_TYPE_1PART_BASIC:
644 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 716 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
645 break; 717 break;
646 case MAILIMAP_BODY_TYPE_1PART_MSG: 718 case MAILIMAP_BODY_TYPE_1PART_MSG:
647 target_part.setType("message"); 719 target_part.setType("message");
648 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 720 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
649 break; 721 break;
650 default: 722 default:
651 break; 723 break;
652 } 724 }
653} 725}
654 726
655void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 727void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
656{ 728{
657 if (!which) { 729 if (!which) {
658 return; 730 return;
659 } 731 }
660 QString sub; 732 QString sub;
661 sub = which->bd_media_text; 733 sub = which->bd_media_text;
662 qDebug("Type= text/%s",which->bd_media_text); 734 qDebug("Type= text/%s",which->bd_media_text);
663 target_part.setSubtype(sub.lower()); 735 target_part.setSubtype(sub.lower());
664 target_part.setLines(which->bd_lines); 736 target_part.setLines(which->bd_lines);
665 fillBodyFields(target_part,which->bd_fields); 737 fillBodyFields(target_part,which->bd_fields);
666} 738}
667 739
668void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 740void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
669{ 741{
670 if (!which) { 742 if (!which) {
671 return; 743 return;
672 } 744 }
673 target_part.setSubtype("rfc822"); 745 target_part.setSubtype("rfc822");
674 qDebug("Message part"); 746 qDebug("Message part");
675 /* we set this type to text/plain */ 747 /* we set this type to text/plain */
676 target_part.setLines(which->bd_lines); 748 target_part.setLines(which->bd_lines);
677 fillBodyFields(target_part,which->bd_fields); 749 fillBodyFields(target_part,which->bd_fields);
678} 750}
679 751
680void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which) 752void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
681{ 753{
682 if (!which) return; 754 if (!which) return;
683 QString sub = which->bd_media_subtype; 755 QString sub = which->bd_media_subtype;
684 target_part.setSubtype(sub.lower()); 756 target_part.setSubtype(sub.lower());
685 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) { 757 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
686 clistcell*cur = 0; 758 clistcell*cur = 0;
687 mailimap_single_body_fld_param*param=0; 759 mailimap_single_body_fld_param*param=0;
688 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 760 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
689 param = (mailimap_single_body_fld_param*)cur->data; 761 param = (mailimap_single_body_fld_param*)cur->data;
690 if (param) { 762 if (param) {
691 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 763 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
692 } 764 }
693 } 765 }
694 } 766 }
695} 767}
696 768
697void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 769void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
698{ 770{
699 if (!which) { 771 if (!which) {
700 return; 772 return;
701 } 773 }
702 QString type,sub; 774 QString type,sub;
703 switch (which->bd_media_basic->med_type) { 775 switch (which->bd_media_basic->med_type) {
704 case MAILIMAP_MEDIA_BASIC_APPLICATION: 776 case MAILIMAP_MEDIA_BASIC_APPLICATION:
705 type = "application"; 777 type = "application";
706 break; 778 break;
707 case MAILIMAP_MEDIA_BASIC_AUDIO: 779 case MAILIMAP_MEDIA_BASIC_AUDIO:
708 type = "audio"; 780 type = "audio";
709 break; 781 break;
710 case MAILIMAP_MEDIA_BASIC_IMAGE: 782 case MAILIMAP_MEDIA_BASIC_IMAGE:
711 type = "image"; 783 type = "image";
712 break; 784 break;
713 case MAILIMAP_MEDIA_BASIC_MESSAGE: 785 case MAILIMAP_MEDIA_BASIC_MESSAGE:
714 type = "message"; 786 type = "message";
715 break; 787 break;
716 case MAILIMAP_MEDIA_BASIC_VIDEO: 788 case MAILIMAP_MEDIA_BASIC_VIDEO:
717 type = "video"; 789 type = "video";
718 break; 790 break;
719 case MAILIMAP_MEDIA_BASIC_OTHER: 791 case MAILIMAP_MEDIA_BASIC_OTHER:
720 default: 792 default:
721 if (which->bd_media_basic->med_basic_type) { 793 if (which->bd_media_basic->med_basic_type) {
722 type = which->bd_media_basic->med_basic_type; 794 type = which->bd_media_basic->med_basic_type;
723 } else { 795 } else {
724 type = ""; 796 type = "";
725 } 797 }
726 break; 798 break;
727 } 799 }
728 if (which->bd_media_basic->med_subtype) { 800 if (which->bd_media_basic->med_subtype) {
729 sub = which->bd_media_basic->med_subtype; 801 sub = which->bd_media_basic->med_subtype;
730 } else { 802 } else {
731 sub = ""; 803 sub = "";
732 } 804 }
733 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 805 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
734 target_part.setType(type.lower()); 806 target_part.setType(type.lower());
735 target_part.setSubtype(sub.lower()); 807 target_part.setSubtype(sub.lower());
736 fillBodyFields(target_part,which->bd_fields); 808 fillBodyFields(target_part,which->bd_fields);
737} 809}
738 810
739void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 811void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
740{ 812{
741 if (!which) return; 813 if (!which) return;
742 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 814 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
743 clistcell*cur; 815 clistcell*cur;
744 mailimap_single_body_fld_param*param=0; 816 mailimap_single_body_fld_param*param=0;
745 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 817 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
746 param = (mailimap_single_body_fld_param*)cur->data; 818 param = (mailimap_single_body_fld_param*)cur->data;
747 if (param) { 819 if (param) {
748 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 820 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
749 } 821 }
750 } 822 }
751 } 823 }
752 mailimap_body_fld_enc*enc = which->bd_encoding; 824 mailimap_body_fld_enc*enc = which->bd_encoding;
753 QString encoding(""); 825 QString encoding("");
754 switch (enc->enc_type) { 826 switch (enc->enc_type) {
755 case MAILIMAP_BODY_FLD_ENC_7BIT: 827 case MAILIMAP_BODY_FLD_ENC_7BIT:
756 encoding = "7bit"; 828 encoding = "7bit";
757 break; 829 break;
758 case MAILIMAP_BODY_FLD_ENC_8BIT: 830 case MAILIMAP_BODY_FLD_ENC_8BIT:
759 encoding = "8bit"; 831 encoding = "8bit";
760 break; 832 break;
761 case MAILIMAP_BODY_FLD_ENC_BINARY: 833 case MAILIMAP_BODY_FLD_ENC_BINARY:
762 encoding="binary"; 834 encoding="binary";
763 break; 835 break;
764 case MAILIMAP_BODY_FLD_ENC_BASE64: 836 case MAILIMAP_BODY_FLD_ENC_BASE64:
765 encoding="base64"; 837 encoding="base64";
766 break; 838 break;
767 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 839 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
768 encoding="quoted-printable"; 840 encoding="quoted-printable";
769 break; 841 break;
770 case MAILIMAP_BODY_FLD_ENC_OTHER: 842 case MAILIMAP_BODY_FLD_ENC_OTHER:
771 default: 843 default:
772 if (enc->enc_value) { 844 if (enc->enc_value) {
773 char*t=enc->enc_value; 845 char*t=enc->enc_value;
774 encoding=QString(enc->enc_value); 846 encoding=QString(enc->enc_value);
775 enc->enc_value=0L; 847 enc->enc_value=0L;
776 free(t); 848 free(t);
777 } 849 }
778 } 850 }
779 if (which->bd_description) { 851 if (which->bd_description) {
780 target_part.setDescription(QString(which->bd_description)); 852 target_part.setDescription(QString(which->bd_description));
781 } 853 }
782 target_part.setEncoding(encoding); 854 target_part.setEncoding(encoding);
783 target_part.setSize(which->bd_size); 855 target_part.setSize(which->bd_size);
784} 856}
785 857
786void IMAPwrapper::deleteMail(const RecMail&mail) 858void IMAPwrapper::deleteMail(const RecMail&mail)
787{ 859{
788 mailimap_flag_list*flist; 860 mailimap_flag_list*flist;
789 mailimap_set *set; 861 mailimap_set *set;
790 mailimap_store_att_flags * store_flags; 862 mailimap_store_att_flags * store_flags;
791 int err; 863 int err;
792 login(); 864 login();
793 if (!m_imap) { 865 if (!m_imap) {
794 return; 866 return;
795 } 867 }
796 err = selectMbox(mail.getMbox()); 868 err = selectMbox(mail.getMbox());
797 if ( err != MAILIMAP_NO_ERROR ) { 869 if ( err != MAILIMAP_NO_ERROR ) {
798 return; 870 return;
799 } 871 }
800 flist = mailimap_flag_list_new_empty(); 872 flist = mailimap_flag_list_new_empty();
801 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 873 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
802 store_flags = mailimap_store_att_flags_new_set_flags(flist); 874 store_flags = mailimap_store_att_flags_new_set_flags(flist);
803 set = mailimap_set_new_single(mail.getNumber()); 875 set = mailimap_set_new_single(mail.getNumber());
804 err = mailimap_store(m_imap,set,store_flags); 876 err = mailimap_store(m_imap,set,store_flags);
805 mailimap_set_free( set ); 877 mailimap_set_free( set );
806 mailimap_store_att_flags_free(store_flags); 878 mailimap_store_att_flags_free(store_flags);
807 879
808 if (err != MAILIMAP_NO_ERROR) { 880 if (err != MAILIMAP_NO_ERROR) {
809 qDebug("error deleting mail: %s",m_imap->imap_response); 881 qDebug("error deleting mail: %s",m_imap->imap_response);
810 return; 882 return;
811 } 883 }
812 qDebug("deleting mail: %s",m_imap->imap_response); 884 qDebug("deleting mail: %s",m_imap->imap_response);
813 /* should we realy do that at this moment? */ 885 /* should we realy do that at this moment? */
814 err = mailimap_expunge(m_imap); 886 err = mailimap_expunge(m_imap);
815 if (err != MAILIMAP_NO_ERROR) { 887 if (err != MAILIMAP_NO_ERROR) {
816 qDebug("error deleting mail: %s",m_imap->imap_response); 888 qDebug("error deleting mail: %s",m_imap->imap_response);
817 } 889 }
818 qDebug("Delete successfull %s",m_imap->imap_response); 890 qDebug("Delete successfull %s",m_imap->imap_response);
819} 891}
820 892
821void IMAPwrapper::answeredMail(const RecMail&mail) 893void IMAPwrapper::answeredMail(const RecMail&mail)
822{ 894{
823 mailimap_flag_list*flist; 895 mailimap_flag_list*flist;
824 mailimap_set *set; 896 mailimap_set *set;
825 mailimap_store_att_flags * store_flags; 897 mailimap_store_att_flags * store_flags;
826 int err; 898 int err;
827 login(); 899 login();
828 if (!m_imap) { 900 if (!m_imap) {
829 return; 901 return;
830 } 902 }
831 err = selectMbox(mail.getMbox()); 903 err = selectMbox(mail.getMbox());
832 if ( err != MAILIMAP_NO_ERROR ) { 904 if ( err != MAILIMAP_NO_ERROR ) {
833 return; 905 return;
834 } 906 }
835 flist = mailimap_flag_list_new_empty(); 907 flist = mailimap_flag_list_new_empty();
836 mailimap_flag_list_add(flist,mailimap_flag_new_answered()); 908 mailimap_flag_list_add(flist,mailimap_flag_new_answered());
837 store_flags = mailimap_store_att_flags_new_add_flags(flist); 909 store_flags = mailimap_store_att_flags_new_add_flags(flist);
838 set = mailimap_set_new_single(mail.getNumber()); 910 set = mailimap_set_new_single(mail.getNumber());
839 err = mailimap_store(m_imap,set,store_flags); 911 err = mailimap_store(m_imap,set,store_flags);
840 mailimap_set_free( set ); 912 mailimap_set_free( set );
841 mailimap_store_att_flags_free(store_flags); 913 mailimap_store_att_flags_free(store_flags);
842 914
843 if (err != MAILIMAP_NO_ERROR) { 915 if (err != MAILIMAP_NO_ERROR) {
844 qDebug("error marking mail: %s",m_imap->imap_response); 916 qDebug("error marking mail: %s",m_imap->imap_response);
845 return; 917 return;
846 } 918 }
847} 919}
848 920
849QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) 921QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
850{ 922{
851 QString body(""); 923 QString body("");
852 encodedString*res = fetchRawPart(mail,path,internal_call); 924 encodedString*res = fetchRawPart(mail,path,internal_call);
853 encodedString*r = decode_String(res,enc); 925 encodedString*r = decode_String(res,enc);
854 delete res; 926 delete res;
855 if (r) { 927 if (r) {
856 if (r->Length()>0) { 928 if (r->Length()>0) {
857 body = r->Content(); 929 body = r->Content();
858 } 930 }
859 delete r; 931 delete r;
860 } 932 }
861 return body; 933 return body;
862} 934}
863 935
864QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) 936QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
865{ 937{
866 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); 938 return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
867} 939}
868 940
869encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) 941encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
870{ 942{
871 encodedString*res = fetchRawPart(mail,part.Positionlist(),false); 943 encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
872 encodedString*r = decode_String(res,part.Encoding()); 944 encodedString*r = decode_String(res,part.Encoding());
873 delete res; 945 delete res;
874 return r; 946 return r;
875} 947}
876 948
877encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) 949encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
878{ 950{
879 return fetchRawPart(mail,part.Positionlist(),false); 951 return fetchRawPart(mail,part.Positionlist(),false);
880} 952}
881 953
882int IMAPwrapper::deleteAllMail(const Folder*folder) 954int IMAPwrapper::deleteAllMail(const Folder*folder)
883{ 955{
884 login(); 956 login();
885 if (!m_imap) { 957 if (!m_imap) {
886 return 0; 958 return 0;
887 } 959 }
888 mailimap_flag_list*flist; 960 mailimap_flag_list*flist;
889 mailimap_set *set; 961 mailimap_set *set;
890 mailimap_store_att_flags * store_flags; 962 mailimap_store_att_flags * store_flags;
891 int err = selectMbox(folder->getName()); 963 int err = selectMbox(folder->getName());
892 if ( err != MAILIMAP_NO_ERROR ) { 964 if ( err != MAILIMAP_NO_ERROR ) {
893 return 0; 965 return 0;
894 } 966 }
895 967
896 int last = m_imap->imap_selection_info->sel_exists; 968 int last = m_imap->imap_selection_info->sel_exists;
897 if (last == 0) { 969 if (last == 0) {
898 Global::statusMessage(tr("Mailbox has no mails!")); 970 Global::statusMessage(tr("Mailbox has no mails!"));
899 return 0; 971 return 0;
900 } 972 }
901 flist = mailimap_flag_list_new_empty(); 973 flist = mailimap_flag_list_new_empty();
902 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 974 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
903 store_flags = mailimap_store_att_flags_new_set_flags(flist); 975 store_flags = mailimap_store_att_flags_new_set_flags(flist);
904 set = mailimap_set_new_interval( 1, last ); 976 set = mailimap_set_new_interval( 1, last );
905 err = mailimap_store(m_imap,set,store_flags); 977 err = mailimap_store(m_imap,set,store_flags);
906 mailimap_set_free( set ); 978 mailimap_set_free( set );
907 mailimap_store_att_flags_free(store_flags); 979 mailimap_store_att_flags_free(store_flags);
908 if (err != MAILIMAP_NO_ERROR) { 980 if (err != MAILIMAP_NO_ERROR) {
909 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 981 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
910 return 0; 982 return 0;
911 } 983 }
912 qDebug("deleting mail: %s",m_imap->imap_response); 984 qDebug("deleting mail: %s",m_imap->imap_response);
913 /* should we realy do that at this moment? */ 985 /* should we realy do that at this moment? */
914 err = mailimap_expunge(m_imap); 986 err = mailimap_expunge(m_imap);
915 if (err != MAILIMAP_NO_ERROR) { 987 if (err != MAILIMAP_NO_ERROR) {
916 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); 988 Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response));
917 return 0; 989 return 0;
918 } 990 }
919 qDebug("Delete successfull %s",m_imap->imap_response); 991 qDebug("Delete successfull %s",m_imap->imap_response);
920 return 1; 992 return 1;
921} 993}
922 994
923int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) 995int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder)
924{ 996{
925 if (folder.length()==0) return 0; 997 if (folder.length()==0) return 0;
926 login(); 998 login();
927 if (!m_imap) {return 0;} 999 if (!m_imap) {return 0;}
928 QString pre = account->getPrefix(); 1000 QString pre = account->getPrefix();
929 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { 1001 if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) {
930 pre+=delemiter; 1002 pre+=delemiter;
931 } 1003 }
932 if (parentfolder) { 1004 if (parentfolder) {
933 pre += parentfolder->getDisplayName()+delemiter; 1005 pre += parentfolder->getDisplayName()+delemiter;
934 } 1006 }
935 pre+=folder; 1007 pre+=folder;
936 if (getsubfolder) { 1008 if (getsubfolder) {
937 if (delemiter.length()>0) { 1009 if (delemiter.length()>0) {
938 pre+=delemiter; 1010 pre+=delemiter;
939 } else { 1011 } else {
940 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 1012 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
941 return 0; 1013 return 0;
942 } 1014 }
943 } 1015 }
944 qDebug("Creating %s",pre.latin1()); 1016 qDebug("Creating %s",pre.latin1());
945 int res = mailimap_create(m_imap,pre.latin1()); 1017 int res = mailimap_create(m_imap,pre.latin1());
946 if (res != MAILIMAP_NO_ERROR) { 1018 if (res != MAILIMAP_NO_ERROR) {
947 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1019 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
948 return 0; 1020 return 0;
949 } 1021 }
950 return 1; 1022 return 1;
951} 1023}
952 1024
953int IMAPwrapper::deleteMbox(const Folder*folder) 1025int IMAPwrapper::deleteMbox(const Folder*folder)
954{ 1026{
955 if (!folder) return 0; 1027 if (!folder) return 0;
956 login(); 1028 login();
957 if (!m_imap) {return 0;} 1029 if (!m_imap) {return 0;}
958 int res = mailimap_delete(m_imap,folder->getName()); 1030 int res = mailimap_delete(m_imap,folder->getName());
959 if (res != MAILIMAP_NO_ERROR) { 1031 if (res != MAILIMAP_NO_ERROR) {
960 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 1032 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
961 return 0; 1033 return 0;
962 } 1034 }
963 return 1; 1035 return 1;
964} 1036}
965 1037
966void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 1038void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
967{ 1039{
968 mailimap_status_att_list * att_list =0; 1040 mailimap_status_att_list * att_list =0;
969 mailimap_mailbox_data_status * status=0; 1041 mailimap_mailbox_data_status * status=0;
970 clistiter * cur = 0; 1042 clistiter * cur = 0;
971 int r = 0; 1043 int r = 0;
972 int res = 0; 1044 int res = 0;
973 target_stat.message_count = 0; 1045 target_stat.message_count = 0;
974 target_stat.message_unseen = 0; 1046 target_stat.message_unseen = 0;
975 target_stat.message_recent = 0; 1047 target_stat.message_recent = 0;
976 login(); 1048 login();
977 if (!m_imap) { 1049 if (!m_imap) {
978 return; 1050 return;
979 } 1051 }
980 att_list = mailimap_status_att_list_new_empty(); 1052 att_list = mailimap_status_att_list_new_empty();
981 if (!att_list) return; 1053 if (!att_list) return;
982 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 1054 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
983 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 1055 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
984 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 1056 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
985 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 1057 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
986 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) { 1058 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
987 for (cur = clist_begin(status->st_info_list); 1059 for (cur = clist_begin(status->st_info_list);
988 cur != NULL ; cur = clist_next(cur)) { 1060 cur != NULL ; cur = clist_next(cur)) {
989 mailimap_status_info * status_info; 1061 mailimap_status_info * status_info;
990 status_info = (mailimap_status_info *)clist_content(cur); 1062 status_info = (mailimap_status_info *)clist_content(cur);
991 switch (status_info->st_att) { 1063 switch (status_info->st_att) {
992 case MAILIMAP_STATUS_ATT_MESSAGES: 1064 case MAILIMAP_STATUS_ATT_MESSAGES:
993 target_stat.message_count = status_info->st_value; 1065 target_stat.message_count = status_info->st_value;
994 break; 1066 break;
995 case MAILIMAP_STATUS_ATT_RECENT: 1067 case MAILIMAP_STATUS_ATT_RECENT:
996 target_stat.message_recent = status_info->st_value; 1068 target_stat.message_recent = status_info->st_value;
997 break; 1069 break;
998 case MAILIMAP_STATUS_ATT_UNSEEN: 1070 case MAILIMAP_STATUS_ATT_UNSEEN:
999 target_stat.message_unseen = status_info->st_value; 1071 target_stat.message_unseen = status_info->st_value;
1000 break; 1072 break;
1001 } 1073 }
1002 } 1074 }
1003 } else { 1075 } else {
1004 qDebug("Error retrieving status"); 1076 qDebug("Error retrieving status");
1005 } 1077 }
1006 if (status) mailimap_mailbox_data_status_free(status); 1078 if (status) mailimap_mailbox_data_status_free(status);
1007 if (att_list) mailimap_status_att_list_free(att_list); 1079 if (att_list) mailimap_status_att_list_free(att_list);
1008} 1080}
1009 1081
1010void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 1082void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
1011{ 1083{
1012 login(); 1084 login();
1013 if (!m_imap) return; 1085 if (!m_imap) return;
1014 if (!msg) return; 1086 if (!msg) return;
1015 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 1087 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
1016 if (r != MAILIMAP_NO_ERROR) { 1088 if (r != MAILIMAP_NO_ERROR) {
1017 Global::statusMessage("Error storing mail!"); 1089 Global::statusMessage("Error storing mail!");
1018 } 1090 }
1019} 1091}
1020 1092
1021const QString&IMAPwrapper::getType()const 1093const QString&IMAPwrapper::getType()const
1022{ 1094{
1023 return account->getType(); 1095 return account->getType();
1024} 1096}
1025 1097
1026const QString&IMAPwrapper::getName()const 1098const QString&IMAPwrapper::getName()const
1027{ 1099{
1028 qDebug("Get name: %s",account->getAccountName().latin1()); 1100 qDebug("Get name: %s",account->getAccountName().latin1());
1029 return account->getAccountName(); 1101 return account->getAccountName();
1030} 1102}
1031 1103
1032encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail) 1104encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
1033{ 1105{
1034 // dummy 1106 // dummy
1035 QValueList<int> path; 1107 QValueList<int> path;
1036 return fetchRawPart(mail,path,false); 1108 return fetchRawPart(mail,path,false);
1037} 1109}
1038 1110
1039void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1111void IMAPwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1040{ 1112{
1041 if (targetWrapper != this) { 1113 if (targetWrapper != this) {
1042 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); 1114 AbstractMail::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
1043 qDebug("Using generic"); 1115 qDebug("Using generic");
1044 return; 1116 return;
1045 } 1117 }
1046 mailimap_set *set = 0; 1118 mailimap_set *set = 0;
1047 login(); 1119 login();
1048 if (!m_imap) { 1120 if (!m_imap) {
1049 return; 1121 return;
1050 } 1122 }
1051 int err = selectMbox(fromFolder->getName()); 1123 int err = selectMbox(fromFolder->getName());
1052 if ( err != MAILIMAP_NO_ERROR ) { 1124 if ( err != MAILIMAP_NO_ERROR ) {
1053 return; 1125 return;
1054 } 1126 }
1055 int last = m_imap->imap_selection_info->sel_exists; 1127 int last = m_imap->imap_selection_info->sel_exists;
1056 set = mailimap_set_new_interval( 1, last ); 1128 set = mailimap_set_new_interval( 1, last );
1057 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1129 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1058 mailimap_set_free( set ); 1130 mailimap_set_free( set );
1059 if ( err != MAILIMAP_NO_ERROR ) { 1131 if ( err != MAILIMAP_NO_ERROR ) {
1060 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response); 1132 QString error_msg = tr("error copy mails: %1").arg(m_imap->imap_response);
1061 Global::statusMessage(error_msg); 1133 Global::statusMessage(error_msg);
1062 qDebug(error_msg); 1134 qDebug(error_msg);
1063 return; 1135 return;
1064 } 1136 }
1065 if (moveit) { 1137 if (moveit) {
1066 deleteAllMail(fromFolder); 1138 deleteAllMail(fromFolder);
1067 } 1139 }
1068} 1140}
1069 1141
1070void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) 1142void IMAPwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
1071{ 1143{
1072 if (targetWrapper != this) { 1144 if (targetWrapper != this) {
1073 qDebug("Using generic"); 1145 qDebug("Using generic");
1074 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit); 1146 AbstractMail::mvcpMail(mail,targetFolder,targetWrapper,moveit);
1075 return; 1147 return;
1076 } 1148 }
1077 mailimap_set *set = 0; 1149 mailimap_set *set = 0;
1078 login(); 1150 login();
1079 if (!m_imap) { 1151 if (!m_imap) {
1080 return; 1152 return;
1081 } 1153 }
1082 int err = selectMbox(mail.getMbox()); 1154 int err = selectMbox(mail.getMbox());
1083 if ( err != MAILIMAP_NO_ERROR ) { 1155 if ( err != MAILIMAP_NO_ERROR ) {
1084 return; 1156 return;
1085 } 1157 }
1086 set = mailimap_set_new_single(mail.getNumber()); 1158 set = mailimap_set_new_single(mail.getNumber());
1087 err = mailimap_copy(m_imap,set,targetFolder.latin1()); 1159 err = mailimap_copy(m_imap,set,targetFolder.latin1());
1088 mailimap_set_free( set ); 1160 mailimap_set_free( set );
1089 if ( err != MAILIMAP_NO_ERROR ) { 1161 if ( err != MAILIMAP_NO_ERROR ) {
1090 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response); 1162 QString error_msg = tr("error copy mail: %1").arg(m_imap->imap_response);
1091 Global::statusMessage(error_msg); 1163 Global::statusMessage(error_msg);
1092 qDebug(error_msg); 1164 qDebug(error_msg);
1093 return; 1165 return;
1094 } 1166 }
1095 if (moveit) { 1167 if (moveit) {
1096 deleteMail(mail); 1168 deleteMail(mail);
1097 } 1169 }
1098} 1170}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index c10f86a..0a1fe2c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,77 +1,78 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 28 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
29 29
30 virtual void deleteMail(const RecMail&mail); 30 virtual void deleteMail(const RecMail&mail);
31 virtual void answeredMail(const RecMail&mail); 31 virtual void answeredMail(const RecMail&mail);
32 virtual int deleteAllMail(const Folder*folder); 32 virtual int deleteAllMail(const Folder*folder);
33 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 33 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
34 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 34 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
35 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 35 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
36 36
37 virtual RecBody fetchBody(const RecMail&mail); 37 virtual RecBody fetchBody(const RecMail&mail);
38 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 38 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
39 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 39 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
40 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 40 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
41 virtual encodedString* fetchRawBody(const RecMail&mail); 41 virtual encodedString* fetchRawBody(const RecMail&mail);
42 42
43 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 43 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
44 virtual int deleteMbox(const Folder*folder); 44 virtual int deleteMbox(const Folder*folder);
45 45
46 static void imap_progress( size_t current, size_t maximum ); 46 static void imap_progress( size_t current, size_t maximum );
47 47
48 virtual void logout(); 48 virtual void logout();
49 virtual const QString&getType()const; 49 virtual const QString&getType()const;
50 virtual const QString&getName()const; 50 virtual const QString&getName()const;
51 51
52protected: 52protected:
53 RecMail*parse_list_result(mailimap_msg_att*); 53 RecMail*parse_list_result(mailimap_msg_att*);
54 void login(); 54 void login();
55 bool start_tls(bool force=true);
55 56
56 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); 57 virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
57 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); 58 virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
58 int selectMbox(const QString&mbox); 59 int selectMbox(const QString&mbox);
59 60
60 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 61 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
61 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 62 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
62 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 63 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
63 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 64 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
64 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); 65 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
65 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); 66 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
66 67
67 /* just helpers */ 68 /* just helpers */
68 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 69 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
69 static QStringList address_list_to_stringlist(clist*list); 70 static QStringList address_list_to_stringlist(clist*list);
70 71
71 72
72 IMAPaccount *account; 73 IMAPaccount *account;
73 mailimap *m_imap; 74 mailimap *m_imap;
74 QString m_Lastmbox; 75 QString m_Lastmbox;
75}; 76};
76 77
77#endif 78#endif