Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index a4e6228..d56d7f9 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -299,14 +299,15 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) | |||
299 | if (addresslist.count()) { | 299 | if (addresslist.count()) { |
300 | m->setReplyto(addresslist.first()); | 300 | m->setReplyto(addresslist.first()); |
301 | } | 301 | } |
302 | } | 302 | } |
303 | m->setMsgid(QString(head->env_message_id)); | 303 | m->setMsgid(QString(head->env_message_id)); |
304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { | 304 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) { |
305 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
306 | #if 0 | 305 | #if 0 |
306 | |||
307 | mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date; | ||
307 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); | 308 | QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec)); |
308 | 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); | 309 | 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); |
309 | qDebug(da.toString()); | 310 | qDebug(da.toString()); |
310 | #endif | 311 | #endif |
311 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { | 312 | } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) { |
312 | size = item->att_data.att_static->att_data.att_rfc822_size; | 313 | size = item->att_data.att_static->att_data.att_rfc822_size; |
@@ -388,26 +389,20 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai | |||
388 | RecPart singlePart; | 389 | RecPart singlePart; |
389 | QValueList<int> path; | 390 | QValueList<int> path; |
390 | fillSinglePart(singlePart,mailDescription); | 391 | fillSinglePart(singlePart,mailDescription); |
391 | switch (mailDescription->bd_type) { | 392 | switch (mailDescription->bd_type) { |
392 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 393 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
393 | path.append(1); | 394 | path.append(1); |
394 | body_text = fetchPart(mail,path,true); | 395 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
395 | if (singlePart.Encoding()=="quoted-printable") { | ||
396 | body_text = decode_quoted_printable(body_text.latin1()); | ||
397 | } | ||
398 | target_body.setBodytext(body_text); | 396 | target_body.setBodytext(body_text); |
399 | target_body.setDescription(singlePart); | 397 | target_body.setDescription(singlePart); |
400 | break; | 398 | break; |
401 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 399 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
402 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | 400 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); |
403 | path.append(1); | 401 | path.append(1); |
404 | body_text = fetchPart(mail,path,true); | 402 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); |
405 | if (singlePart.Encoding()=="quoted-printable") { | ||
406 | body_text = decode_quoted_printable(body_text.latin1()); | ||
407 | } | ||
408 | target_body.setBodytext(body_text); | 403 | target_body.setBodytext(body_text); |
409 | target_body.setDescription(singlePart); | 404 | target_body.setDescription(singlePart); |
410 | break; | 405 | break; |
411 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 406 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
412 | qDebug("Single attachment"); | 407 | qDebug("Single attachment"); |
413 | target_body.setBodytext(""); | 408 | target_body.setBodytext(""); |
@@ -458,31 +453,31 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
458 | break; | 453 | break; |
459 | } | 454 | } |
460 | } | 455 | } |
461 | return l; | 456 | return l; |
462 | } | 457 | } |
463 | 458 | ||
464 | QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | 459 | encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) |
465 | { | 460 | { |
466 | QString body(""); | 461 | encodedString*res=new encodedString; |
467 | const char*mb; | 462 | const char*mb; |
468 | int err; | 463 | int err; |
469 | mailimap_fetch_type *fetchType; | 464 | mailimap_fetch_type *fetchType; |
470 | mailimap_set *set; | 465 | mailimap_set *set; |
471 | clistcell*current,*cur; | 466 | clistcell*current,*cur; |
472 | 467 | ||
473 | login(); | 468 | login(); |
474 | if (!m_imap) { | 469 | if (!m_imap) { |
475 | return body; | 470 | return res; |
476 | } | 471 | } |
477 | if (!internal_call) { | 472 | if (!internal_call) { |
478 | mb = mail.getMbox().latin1(); | 473 | mb = mail.getMbox().latin1(); |
479 | err = mailimap_select( m_imap, (char*)mb); | 474 | err = mailimap_select( m_imap, (char*)mb); |
480 | if ( err != MAILIMAP_NO_ERROR ) { | 475 | if ( err != MAILIMAP_NO_ERROR ) { |
481 | qDebug("error selecting mailbox: %s",m_imap->imap_response); | 476 | qDebug("error selecting mailbox: %s",m_imap->imap_response); |
482 | return body; | 477 | return res; |
483 | } | 478 | } |
484 | } | 479 | } |
485 | set = mailimap_set_new_single(mail.getNumber()); | 480 | set = mailimap_set_new_single(mail.getNumber()); |
486 | clist*id_list=clist_new(); | 481 | clist*id_list=clist_new(); |
487 | for (unsigned j=0; j < path.count();++j) { | 482 | for (unsigned j=0; j < path.count();++j) { |
488 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); | 483 | uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); |
@@ -508,32 +503,23 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo | |||
508 | mailimap_msg_att_item*msg_att_item; | 503 | mailimap_msg_att_item*msg_att_item; |
509 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { | 504 | for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { |
510 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); | 505 | msg_att_item = (mailimap_msg_att_item*)clist_content(cur); |
511 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { | 506 | if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { |
512 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { | 507 | if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { |
513 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; | 508 | char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; |
509 | /* detach - we take over the content */ | ||
514 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; | 510 | msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; |
515 | if (text) { | 511 | res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); |
516 | if (enc=="quoted-printable") { | ||
517 | body = decode_quoted_printable(text); | ||
518 | } else { | ||
519 | body = QString(text); | ||
520 | } | ||
521 | free(text); | ||
522 | } else { | ||
523 | body = ""; | ||
524 | } | 512 | } |
525 | } | 513 | } |
526 | } | 514 | } |
527 | } | ||
528 | |||
529 | } else { | 515 | } else { |
530 | qDebug("error fetching text: %s",m_imap->imap_response); | 516 | qDebug("error fetching text: %s",m_imap->imap_response); |
531 | } | 517 | } |
532 | mailimap_fetch_list_free(result); | 518 | mailimap_fetch_list_free(result); |
533 | return body; | 519 | return res; |
534 | } | 520 | } |
535 | 521 | ||
536 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 522 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) |
537 | { | 523 | { |
538 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 524 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ |
539 | if (!mailDescription||current_recursion==10) { | 525 | if (!mailDescription||current_recursion==10) { |
@@ -554,13 +540,13 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai | |||
554 | RecPart currentPart; | 540 | RecPart currentPart; |
555 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 541 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); |
556 | QValueList<int>clist = recList; | 542 | QValueList<int>clist = recList; |
557 | clist.append(count); | 543 | clist.append(count); |
558 | /* important: Check for is NULL 'cause a body can be empty! */ | 544 | /* important: Check for is NULL 'cause a body can be empty! */ |
559 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 545 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { |
560 | QString body_text = fetchPart(mail,clist,true,currentPart.Encoding()); | 546 | QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding()); |
561 | target_body.setDescription(currentPart); | 547 | target_body.setDescription(currentPart); |
562 | target_body.setBodytext(body_text); | 548 | target_body.setBodytext(body_text); |
563 | } else { | 549 | } else { |
564 | QString id(""); | 550 | QString id(""); |
565 | for (unsigned int j = 0; j < clist.count();++j) { | 551 | for (unsigned int j = 0; j < clist.count();++j) { |
566 | id+=(j>0?" ":""); | 552 | id+=(j>0?" ":""); |
@@ -710,17 +696,12 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) | |||
710 | target_part.setDescription(QString(which->bd_description)); | 696 | target_part.setDescription(QString(which->bd_description)); |
711 | } | 697 | } |
712 | target_part.setEncoding(encoding); | 698 | target_part.setEncoding(encoding); |
713 | target_part.setSize(which->bd_size); | 699 | target_part.setSize(which->bd_size); |
714 | } | 700 | } |
715 | 701 | ||
716 | QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) | ||
717 | { | ||
718 | return fetchPart(mail,part.Positionlist(),false,part.Encoding()); | ||
719 | } | ||
720 | |||
721 | void IMAPwrapper::deleteMail(const RecMail&mail) | 702 | void IMAPwrapper::deleteMail(const RecMail&mail) |
722 | { | 703 | { |
723 | mailimap_flag_list*flist; | 704 | mailimap_flag_list*flist; |
724 | mailimap_set *set; | 705 | mailimap_set *set; |
725 | mailimap_store_att_flags * store_flags; | 706 | mailimap_store_att_flags * store_flags; |
726 | int err; | 707 | int err; |
@@ -781,6 +762,39 @@ void IMAPwrapper::answeredMail(const RecMail&mail) | |||
781 | 762 | ||
782 | if (err != MAILIMAP_NO_ERROR) { | 763 | if (err != MAILIMAP_NO_ERROR) { |
783 | qDebug("error marking mail: %s",m_imap->imap_response); | 764 | qDebug("error marking mail: %s",m_imap->imap_response); |
784 | return; | 765 | return; |
785 | } | 766 | } |
786 | } | 767 | } |
768 | |||
769 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc) | ||
770 | { | ||
771 | QString body(""); | ||
772 | encodedString*res = fetchRawPart(mail,path,internal_call); | ||
773 | encodedString*r = decode_String(res,enc); | ||
774 | delete res; | ||
775 | if (r) { | ||
776 | if (r->Length()>0) { | ||
777 | body = r->Content(); | ||
778 | } | ||
779 | delete r; | ||
780 | } | ||
781 | return body; | ||
782 | } | ||
783 | |||
784 | QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) | ||
785 | { | ||
786 | return fetchTextPart(mail,part.Positionlist(),false,part.Encoding()); | ||
787 | } | ||
788 | |||
789 | encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part) | ||
790 | { | ||
791 | encodedString*res = fetchRawPart(mail,part.Positionlist(),false); | ||
792 | encodedString*r = decode_String(res,part.Encoding()); | ||
793 | delete res; | ||
794 | return r; | ||
795 | } | ||
796 | |||
797 | encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) | ||
798 | { | ||
799 | return fetchRawPart(mail,part.Positionlist(),false); | ||
800 | } | ||