-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 25 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 25 |
2 files changed, 22 insertions, 28 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 0178e33..89ec7ab 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -150,42 +150,41 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
150 | } | 150 | } |
151 | } | 151 | } |
152 | } else { | 152 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 153 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 154 | } |
155 | if (result) mailimap_fetch_list_free(result); | 155 | if (result) mailimap_fetch_list_free(result); |
156 | } | 156 | } |
157 | 157 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 158 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 159 | { |
160 | const char *path, *mask; | 160 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 161 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result; | 162 | clist *result = 0; |
163 | clistcell *current; | 163 | clistcell *current = 0; |
164 | 164 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 165 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 166 | folders->setAutoDelete( false ); |
167 | login(); | 167 | login(); |
168 | if (!m_imap) { | 168 | if (!m_imap) { |
169 | return folders; | 169 | return folders; |
170 | } | 170 | } |
171 | 171 | ||
172 | /* | 172 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 174 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 175 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 176 | */ |
177 | QString temp; | 177 | QString temp; |
178 | mask = "INBOX" ; | 178 | mask = "INBOX" ; |
179 | result = clist_new(); | ||
180 | mailimap_mailbox_list *list; | 179 | mailimap_mailbox_list *list; |
181 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
182 | QString del; | 181 | QString del; |
183 | if ( err == MAILIMAP_NO_ERROR ) { | 182 | if ( err == MAILIMAP_NO_ERROR ) { |
184 | current = result->first; | 183 | current = result->first; |
185 | for ( int i = result->count; i > 0; i-- ) { | 184 | for ( int i = result->count; i > 0; i-- ) { |
186 | list = (mailimap_mailbox_list *) current->data; | 185 | list = (mailimap_mailbox_list *) current->data; |
187 | // it is better use the deep copy mechanism of qt itself | 186 | // it is better use the deep copy mechanism of qt itself |
188 | // instead of using strdup! | 187 | // instead of using strdup! |
189 | temp = list->mb_name; | 188 | temp = list->mb_name; |
190 | del = list->mb_delimiter; | 189 | del = list->mb_delimiter; |
191 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
@@ -193,25 +192,24 @@ QList<Folder>* IMAPwrapper::listFolders() | |||
193 | } | 192 | } |
194 | } else { | 193 | } else { |
195 | qDebug("error fetching folders: %s",m_imap->imap_response); | 194 | qDebug("error fetching folders: %s",m_imap->imap_response); |
196 | } | 195 | } |
197 | mailimap_list_result_free( result ); | 196 | mailimap_list_result_free( result ); |
198 | 197 | ||
199 | /* | 198 | /* |
200 | * second stage - get the other then inbox folders | 199 | * second stage - get the other then inbox folders |
201 | */ | 200 | */ |
202 | mask = "*" ; | 201 | mask = "*" ; |
203 | path = account->getPrefix().latin1(); | 202 | path = account->getPrefix().latin1(); |
204 | if (!path) path = ""; | 203 | if (!path) path = ""; |
205 | result = clist_new(); | ||
206 | qDebug(path); | 204 | qDebug(path); |
207 | bool selectable = true; | 205 | bool selectable = true; |
208 | mailimap_mbx_list_flags*bflags; | 206 | mailimap_mbx_list_flags*bflags; |
209 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
210 | if ( err == MAILIMAP_NO_ERROR ) { | 208 | if ( err == MAILIMAP_NO_ERROR ) { |
211 | current = result->first; | 209 | current = result->first; |
212 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
213 | list = (mailimap_mailbox_list *) current->data; | 211 | list = (mailimap_mailbox_list *) current->data; |
214 | // it is better use the deep copy mechanism of qt itself | 212 | // it is better use the deep copy mechanism of qt itself |
215 | // instead of using strdup! | 213 | // instead of using strdup! |
216 | temp = list->mb_name; | 214 | temp = list->mb_name; |
217 | if (temp.lower()=="inbox") | 215 | if (temp.lower()=="inbox") |
@@ -219,25 +217,25 @@ QList<Folder>* IMAPwrapper::listFolders() | |||
219 | if (temp.lower()==account->getPrefix().lower()) | 217 | if (temp.lower()==account->getPrefix().lower()) |
220 | continue; | 218 | continue; |
221 | if ( (bflags = list->mb_flag) ) { | 219 | if ( (bflags = list->mb_flag) ) { |
222 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
223 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
224 | } | 222 | } |
225 | del = list->mb_delimiter; | 223 | del = list->mb_delimiter; |
226 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
227 | } | 225 | } |
228 | } else { | 226 | } else { |
229 | qDebug("error fetching folders %s",m_imap->imap_response); | 227 | qDebug("error fetching folders %s",m_imap->imap_response); |
230 | } | 228 | } |
231 | mailimap_list_result_free( result ); | 229 | if (result) mailimap_list_result_free( result ); |
232 | return folders; | 230 | return folders; |
233 | } | 231 | } |
234 | 232 | ||
235 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 233 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
236 | { | 234 | { |
237 | RecMail * m = 0; | 235 | RecMail * m = 0; |
238 | mailimap_msg_att_item *item=0; | 236 | mailimap_msg_att_item *item=0; |
239 | clistcell *current,*c,*cf; | 237 | clistcell *current,*c,*cf; |
240 | mailimap_msg_att_dynamic*flist; | 238 | mailimap_msg_att_dynamic*flist; |
241 | mailimap_flag_fetch*cflag; | 239 | mailimap_flag_fetch*cflag; |
242 | int size; | 240 | int size; |
243 | QBitArray mFlags(7); | 241 | QBitArray mFlags(7); |
@@ -338,68 +336,67 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
338 | if (m) { | 336 | if (m) { |
339 | m->setFlags(mFlags); | 337 | m->setFlags(mFlags); |
340 | m->setMsgsize(size); | 338 | m->setMsgsize(size); |
341 | } | 339 | } |
342 | return m; | 340 | return m; |
343 | } | 341 | } |
344 | 342 | ||
345 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 343 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
346 | { | 344 | { |
347 | RecBody body; | 345 | RecBody body; |
348 | const char *mb; | 346 | const char *mb; |
349 | int err = MAILIMAP_NO_ERROR; | 347 | int err = MAILIMAP_NO_ERROR; |
350 | clist *result; | 348 | clist *result = 0; |
351 | clistcell *current; | 349 | clistcell *current; |
352 | mailimap_fetch_att *fetchAtt; | 350 | mailimap_fetch_att *fetchAtt = 0; |
353 | mailimap_fetch_type *fetchType; | 351 | mailimap_fetch_type *fetchType = 0; |
354 | mailimap_set *set; | 352 | mailimap_set *set = 0; |
355 | mailimap_body*body_desc; | 353 | mailimap_body*body_desc = 0; |
356 | 354 | ||
357 | mb = mail.getMbox().latin1(); | 355 | mb = mail.getMbox().latin1(); |
358 | 356 | ||
359 | login(); | 357 | login(); |
360 | if (!m_imap) { | 358 | if (!m_imap) { |
361 | return body; | 359 | return body; |
362 | } | 360 | } |
363 | 361 | ||
364 | err = mailimap_select( m_imap, (char*)mb); | 362 | err = mailimap_select( m_imap, (char*)mb); |
365 | if ( err != MAILIMAP_NO_ERROR ) { | 363 | if ( err != MAILIMAP_NO_ERROR ) { |
366 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 364 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
367 | return body; | 365 | return body; |
368 | } | 366 | } |
369 | 367 | ||
370 | result = clist_new(); | ||
371 | /* the range has to start at 1!!! not with 0!!!! */ | 368 | /* the range has to start at 1!!! not with 0!!!! */ |
372 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 369 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
373 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 370 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
374 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 371 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
375 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 372 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
376 | mailimap_set_free( set ); | 373 | mailimap_set_free( set ); |
377 | mailimap_fetch_type_free( fetchType ); | 374 | mailimap_fetch_type_free( fetchType ); |
378 | 375 | ||
379 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 376 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
380 | mailimap_msg_att * msg_att; | 377 | mailimap_msg_att * msg_att; |
381 | msg_att = (mailimap_msg_att*)current->data; | 378 | msg_att = (mailimap_msg_att*)current->data; |
382 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 379 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
383 | body_desc = item->att_data.att_static->att_data.att_body; | 380 | body_desc = item->att_data.att_static->att_data.att_body; |
384 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 381 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
385 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 382 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
386 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 383 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
387 | qDebug("Mulitpart mail"); | 384 | qDebug("Mulitpart mail"); |
388 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 385 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
389 | } | 386 | } |
390 | } else { | 387 | } else { |
391 | qDebug("error fetching body: %s",m_imap->imap_response); | 388 | qDebug("error fetching body: %s",m_imap->imap_response); |
392 | } | 389 | } |
393 | mailimap_fetch_list_free(result); | 390 | if (result) mailimap_fetch_list_free(result); |
394 | return body; | 391 | return body; |
395 | } | 392 | } |
396 | 393 | ||
397 | /* this routine is just called when the mail has only ONE part. | 394 | /* this routine is just called when the mail has only ONE part. |
398 | for filling the parts of a multi-part-message there are other | 395 | for filling the parts of a multi-part-message there are other |
399 | routines 'cause we can not simply fetch the whole body. */ | 396 | routines 'cause we can not simply fetch the whole body. */ |
400 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 397 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
401 | { | 398 | { |
402 | if (!mailDescription) { | 399 | if (!mailDescription) { |
403 | return; | 400 | return; |
404 | } | 401 | } |
405 | QString sub,body_text; | 402 | QString sub,body_text; |
@@ -500,49 +497,49 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
500 | for (unsigned j=0; j < path.count();++j) { | 497 | for (unsigned j=0; j < path.count();++j) { |
501 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 498 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
502 | *p_id = path[j]; | 499 | *p_id = path[j]; |
503 | clist_append(id_list,p_id); | 500 | clist_append(id_list,p_id); |
504 | } | 501 | } |
505 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 502 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
506 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 503 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
507 | mailimap_section * section = mailimap_section_new(section_spec); | 504 | mailimap_section * section = mailimap_section_new(section_spec); |
508 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 505 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
509 | 506 | ||
510 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 507 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
511 | 508 | ||
512 | clist*result = clist_new(); | 509 | clist*result = 0; |
513 | 510 | ||
514 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 511 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
515 | mailimap_set_free( set ); | 512 | mailimap_set_free( set ); |
516 | mailimap_fetch_type_free( fetchType ); | 513 | mailimap_fetch_type_free( fetchType ); |
517 | 514 | ||
518 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 515 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
519 | mailimap_msg_att * msg_att; | 516 | mailimap_msg_att * msg_att; |
520 | msg_att = (mailimap_msg_att*)current->data; | 517 | msg_att = (mailimap_msg_att*)current->data; |
521 | mailimap_msg_att_item*msg_att_item; | 518 | mailimap_msg_att_item*msg_att_item; |
522 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 519 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
523 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 520 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
524 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 521 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
525 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 522 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
526 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 523 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
527 | /* detach - we take over the content */ | 524 | /* detach - we take over the content */ |
528 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 525 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
529 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 526 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
530 | } | 527 | } |
531 | } | 528 | } |
532 | } | 529 | } |
533 | } else { | 530 | } else { |
534 | qDebug("error fetching text: %s",m_imap->imap_response); | 531 | qDebug("error fetching text: %s",m_imap->imap_response); |
535 | } | 532 | } |
536 | mailimap_fetch_list_free(result); | 533 | if (result) mailimap_fetch_list_free(result); |
537 | return res; | 534 | return res; |
538 | } | 535 | } |
539 | 536 | ||
540 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 537 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
541 | { | 538 | { |
542 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 539 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
543 | if (!mailDescription||current_recursion==10) { | 540 | if (!mailDescription||current_recursion==10) { |
544 | return; | 541 | return; |
545 | } | 542 | } |
546 | clistcell*current; | 543 | clistcell*current; |
547 | mailimap_body*current_body; | 544 | mailimap_body*current_body; |
548 | unsigned int count = 0; | 545 | unsigned int count = 0; |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 0178e33..89ec7ab 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -150,42 +150,41 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) | |||
150 | } | 150 | } |
151 | } | 151 | } |
152 | } else { | 152 | } else { |
153 | qDebug("Error fetching headers: %s",m_imap->imap_response); | 153 | qDebug("Error fetching headers: %s",m_imap->imap_response); |
154 | } | 154 | } |
155 | if (result) mailimap_fetch_list_free(result); | 155 | if (result) mailimap_fetch_list_free(result); |
156 | } | 156 | } |
157 | 157 | ||
158 | QList<Folder>* IMAPwrapper::listFolders() | 158 | QList<Folder>* IMAPwrapper::listFolders() |
159 | { | 159 | { |
160 | const char *path, *mask; | 160 | const char *path, *mask; |
161 | int err = MAILIMAP_NO_ERROR; | 161 | int err = MAILIMAP_NO_ERROR; |
162 | clist *result; | 162 | clist *result = 0; |
163 | clistcell *current; | 163 | clistcell *current = 0; |
164 | 164 | ||
165 | QList<Folder> * folders = new QList<Folder>(); | 165 | QList<Folder> * folders = new QList<Folder>(); |
166 | folders->setAutoDelete( false ); | 166 | folders->setAutoDelete( false ); |
167 | login(); | 167 | login(); |
168 | if (!m_imap) { | 168 | if (!m_imap) { |
169 | return folders; | 169 | return folders; |
170 | } | 170 | } |
171 | 171 | ||
172 | /* | 172 | /* |
173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. | 173 | * First we have to check for INBOX 'cause it sometimes it's not inside the path. |
174 | * We must not forget to filter them out in next loop! | 174 | * We must not forget to filter them out in next loop! |
175 | * it seems like ugly code. and yes - it is ugly code. but the best way. | 175 | * it seems like ugly code. and yes - it is ugly code. but the best way. |
176 | */ | 176 | */ |
177 | QString temp; | 177 | QString temp; |
178 | mask = "INBOX" ; | 178 | mask = "INBOX" ; |
179 | result = clist_new(); | ||
180 | mailimap_mailbox_list *list; | 179 | mailimap_mailbox_list *list; |
181 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); | 180 | err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); |
182 | QString del; | 181 | QString del; |
183 | if ( err == MAILIMAP_NO_ERROR ) { | 182 | if ( err == MAILIMAP_NO_ERROR ) { |
184 | current = result->first; | 183 | current = result->first; |
185 | for ( int i = result->count; i > 0; i-- ) { | 184 | for ( int i = result->count; i > 0; i-- ) { |
186 | list = (mailimap_mailbox_list *) current->data; | 185 | list = (mailimap_mailbox_list *) current->data; |
187 | // it is better use the deep copy mechanism of qt itself | 186 | // it is better use the deep copy mechanism of qt itself |
188 | // instead of using strdup! | 187 | // instead of using strdup! |
189 | temp = list->mb_name; | 188 | temp = list->mb_name; |
190 | del = list->mb_delimiter; | 189 | del = list->mb_delimiter; |
191 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); | 190 | folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); |
@@ -193,25 +192,24 @@ QList<Folder>* IMAPwrapper::listFolders() | |||
193 | } | 192 | } |
194 | } else { | 193 | } else { |
195 | qDebug("error fetching folders: %s",m_imap->imap_response); | 194 | qDebug("error fetching folders: %s",m_imap->imap_response); |
196 | } | 195 | } |
197 | mailimap_list_result_free( result ); | 196 | mailimap_list_result_free( result ); |
198 | 197 | ||
199 | /* | 198 | /* |
200 | * second stage - get the other then inbox folders | 199 | * second stage - get the other then inbox folders |
201 | */ | 200 | */ |
202 | mask = "*" ; | 201 | mask = "*" ; |
203 | path = account->getPrefix().latin1(); | 202 | path = account->getPrefix().latin1(); |
204 | if (!path) path = ""; | 203 | if (!path) path = ""; |
205 | result = clist_new(); | ||
206 | qDebug(path); | 204 | qDebug(path); |
207 | bool selectable = true; | 205 | bool selectable = true; |
208 | mailimap_mbx_list_flags*bflags; | 206 | mailimap_mbx_list_flags*bflags; |
209 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); | 207 | err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); |
210 | if ( err == MAILIMAP_NO_ERROR ) { | 208 | if ( err == MAILIMAP_NO_ERROR ) { |
211 | current = result->first; | 209 | current = result->first; |
212 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { | 210 | for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { |
213 | list = (mailimap_mailbox_list *) current->data; | 211 | list = (mailimap_mailbox_list *) current->data; |
214 | // it is better use the deep copy mechanism of qt itself | 212 | // it is better use the deep copy mechanism of qt itself |
215 | // instead of using strdup! | 213 | // instead of using strdup! |
216 | temp = list->mb_name; | 214 | temp = list->mb_name; |
217 | if (temp.lower()=="inbox") | 215 | if (temp.lower()=="inbox") |
@@ -219,25 +217,25 @@ QList<Folder>* IMAPwrapper::listFolders() | |||
219 | if (temp.lower()==account->getPrefix().lower()) | 217 | if (temp.lower()==account->getPrefix().lower()) |
220 | continue; | 218 | continue; |
221 | if ( (bflags = list->mb_flag) ) { | 219 | if ( (bflags = list->mb_flag) ) { |
222 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& | 220 | selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& |
223 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); | 221 | bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); |
224 | } | 222 | } |
225 | del = list->mb_delimiter; | 223 | del = list->mb_delimiter; |
226 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); | 224 | folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); |
227 | } | 225 | } |
228 | } else { | 226 | } else { |
229 | qDebug("error fetching folders %s",m_imap->imap_response); | 227 | qDebug("error fetching folders %s",m_imap->imap_response); |
230 | } | 228 | } |
231 | mailimap_list_result_free( result ); | 229 | if (result) mailimap_list_result_free( result ); |
232 | return folders; | 230 | return folders; |
233 | } | 231 | } |
234 | 232 | ||
235 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | 233 | RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) |
236 | { | 234 | { |
237 | RecMail * m = 0; | 235 | RecMail * m = 0; |
238 | mailimap_msg_att_item *item=0; | 236 | mailimap_msg_att_item *item=0; |
239 | clistcell *current,*c,*cf; | 237 | clistcell *current,*c,*cf; |
240 | mailimap_msg_att_dynamic*flist; | 238 | mailimap_msg_att_dynamic*flist; |
241 | mailimap_flag_fetch*cflag; | 239 | mailimap_flag_fetch*cflag; |
242 | int size; | 240 | int size; |
243 | QBitArray mFlags(7); | 241 | QBitArray mFlags(7); |
@@ -338,68 +336,67 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
338 | if (m) { | 336 | if (m) { |
339 | m->setFlags(mFlags); | 337 | m->setFlags(mFlags); |
340 | m->setMsgsize(size); | 338 | m->setMsgsize(size); |
341 | } | 339 | } |
342 | return m; | 340 | return m; |
343 | } | 341 | } |
344 | 342 | ||
345 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) | 343 | RecBody IMAPwrapper::fetchBody(const RecMail&mail) |
346 | { | 344 | { |
347 | RecBody body; | 345 | RecBody body; |
348 | const char *mb; | 346 | const char *mb; |
349 | int err = MAILIMAP_NO_ERROR; | 347 | int err = MAILIMAP_NO_ERROR; |
350 | clist *result; | 348 | clist *result = 0; |
351 | clistcell *current; | 349 | clistcell *current; |
352 | mailimap_fetch_att *fetchAtt; | 350 | mailimap_fetch_att *fetchAtt = 0; |
353 | mailimap_fetch_type *fetchType; | 351 | mailimap_fetch_type *fetchType = 0; |
354 | mailimap_set *set; | 352 | mailimap_set *set = 0; |
355 | mailimap_body*body_desc; | 353 | mailimap_body*body_desc = 0; |
356 | 354 | ||
357 | mb = mail.getMbox().latin1(); | 355 | mb = mail.getMbox().latin1(); |
358 | 356 | ||
359 | login(); | 357 | login(); |
360 | if (!m_imap) { | 358 | if (!m_imap) { |
361 | return body; | 359 | return body; |
362 | } | 360 | } |
363 | 361 | ||
364 | err = mailimap_select( m_imap, (char*)mb); | 362 | err = mailimap_select( m_imap, (char*)mb); |
365 | if ( err != MAILIMAP_NO_ERROR ) { | 363 | if ( err != MAILIMAP_NO_ERROR ) { |
366 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 364 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
367 | return body; | 365 | return body; |
368 | } | 366 | } |
369 | 367 | ||
370 | result = clist_new(); | ||
371 | /* the range has to start at 1!!! not with 0!!!! */ | 368 | /* the range has to start at 1!!! not with 0!!!! */ |
372 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); | 369 | set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() ); |
373 | fetchAtt = mailimap_fetch_att_new_bodystructure(); | 370 | fetchAtt = mailimap_fetch_att_new_bodystructure(); |
374 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); | 371 | fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt); |
375 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 372 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
376 | mailimap_set_free( set ); | 373 | mailimap_set_free( set ); |
377 | mailimap_fetch_type_free( fetchType ); | 374 | mailimap_fetch_type_free( fetchType ); |
378 | 375 | ||
379 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 376 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
380 | mailimap_msg_att * msg_att; | 377 | mailimap_msg_att * msg_att; |
381 | msg_att = (mailimap_msg_att*)current->data; | 378 | msg_att = (mailimap_msg_att*)current->data; |
382 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 379 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
383 | body_desc = item->att_data.att_static->att_data.att_body; | 380 | body_desc = item->att_data.att_static->att_data.att_body; |
384 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 381 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { |
385 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | 382 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); |
386 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | 383 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { |
387 | qDebug("Mulitpart mail"); | 384 | qDebug("Mulitpart mail"); |
388 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | 385 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); |
389 | } | 386 | } |
390 | } else { | 387 | } else { |
391 | qDebug("error fetching body: %s",m_imap->imap_response); | 388 | qDebug("error fetching body: %s",m_imap->imap_response); |
392 | } | 389 | } |
393 | mailimap_fetch_list_free(result); | 390 | if (result) mailimap_fetch_list_free(result); |
394 | return body; | 391 | return body; |
395 | } | 392 | } |
396 | 393 | ||
397 | /* this routine is just called when the mail has only ONE part. | 394 | /* this routine is just called when the mail has only ONE part. |
398 | for filling the parts of a multi-part-message there are other | 395 | for filling the parts of a multi-part-message there are other |
399 | routines 'cause we can not simply fetch the whole body. */ | 396 | routines 'cause we can not simply fetch the whole body. */ |
400 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | 397 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) |
401 | { | 398 | { |
402 | if (!mailDescription) { | 399 | if (!mailDescription) { |
403 | return; | 400 | return; |
404 | } | 401 | } |
405 | QString sub,body_text; | 402 | QString sub,body_text; |
@@ -500,49 +497,49 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
500 | for (unsigned j=0; j < path.count();++j) { | 497 | for (unsigned j=0; j < path.count();++j) { |
501 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 498 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
502 | *p_id = path[j]; | 499 | *p_id = path[j]; |
503 | clist_append(id_list,p_id); | 500 | clist_append(id_list,p_id); |
504 | } | 501 | } |
505 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); | 502 | mailimap_section_part * section_part = mailimap_section_part_new(id_list); |
506 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); | 503 | mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); |
507 | mailimap_section * section = mailimap_section_new(section_spec); | 504 | mailimap_section * section = mailimap_section_new(section_spec); |
508 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); | 505 | mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); |
509 | 506 | ||
510 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); | 507 | fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); |
511 | 508 | ||
512 | clist*result = clist_new(); | 509 | clist*result = 0; |
513 | 510 | ||
514 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 511 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
515 | mailimap_set_free( set ); | 512 | mailimap_set_free( set ); |
516 | mailimap_fetch_type_free( fetchType ); | 513 | mailimap_fetch_type_free( fetchType ); |
517 | 514 | ||
518 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 515 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
519 | mailimap_msg_att * msg_att; | 516 | mailimap_msg_att * msg_att; |
520 | msg_att = (mailimap_msg_att*)current->data; | 517 | msg_att = (mailimap_msg_att*)current->data; |
521 | mailimap_msg_att_item*msg_att_item; | 518 | mailimap_msg_att_item*msg_att_item; |
522 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 519 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
523 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 520 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
524 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 521 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
525 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 522 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
526 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 523 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
527 | /* detach - we take over the content */ | 524 | /* detach - we take over the content */ |
528 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 525 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
529 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); | 526 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
530 | } | 527 | } |
531 | } | 528 | } |
532 | } | 529 | } |
533 | } else { | 530 | } else { |
534 | qDebug("error fetching text: %s",m_imap->imap_response); | 531 | qDebug("error fetching text: %s",m_imap->imap_response); |
535 | } | 532 | } |
536 | mailimap_fetch_list_free(result); | 533 | if (result) mailimap_fetch_list_free(result); |
537 | return res; | 534 | return res; |
538 | } | 535 | } |
539 | 536 | ||
540 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 537 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
541 | { | 538 | { |
542 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 539 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
543 | if (!mailDescription||current_recursion==10) { | 540 | if (!mailDescription||current_recursion==10) { |
544 | return; | 541 | return; |
545 | } | 542 | } |
546 | clistcell*current; | 543 | clistcell*current; |
547 | mailimap_body*current_body; | 544 | mailimap_body*current_body; |
548 | unsigned int count = 0; | 545 | unsigned int count = 0; |