summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/imapwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp74
1 files changed, 48 insertions, 26 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 95b317a..d252159 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -421,121 +421,132 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{ 421{
422 QStringList l; 422 QStringList l;
423 QString from; 423 QString from;
424 bool named_from; 424 bool named_from;
425 clistcell *current = NULL; 425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL; 426 mailimap_address * current_address=NULL;
427 if (!list) { 427 if (!list) {
428 return l; 428 return l;
429 } 429 }
430 unsigned int count = 0; 430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = ""; 432 from = "";
433 named_from = false; 433 named_from = false;
434 current_address=(mailimap_address*)current->data; 434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){ 435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name); 436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" "; 437 from+=" ";
438 named_from = true; 438 named_from = true;
439 } 439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<"; 441 from+="<";
442 } 442 }
443 if (current_address->ad_mailbox_name) { 443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name); 444 from+=QString(current_address->ad_mailbox_name);
445 from+="@"; 445 from+="@";
446 } 446 }
447 if (current_address->ad_host_name) { 447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name); 448 from+=QString(current_address->ad_host_name);
449 } 449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">"; 451 from+=">";
452 } 452 }
453 l.append(QString(from)); 453 l.append(QString(from));
454 if (++count > 99) { 454 if (++count > 99) {
455 break; 455 break;
456 } 456 }
457 } 457 }
458 return l; 458 return l;
459} 459}
460 460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{ 462{
463 encodedString*res=new encodedString; 463 encodedString*res=new encodedString;
464 const char*mb; 464 const char*mb;
465 int err; 465 int err;
466 mailimap_fetch_type *fetchType; 466 mailimap_fetch_type *fetchType;
467 mailimap_set *set; 467 mailimap_set *set;
468 clistcell*current,*cur; 468 clistcell*current,*cur;
469 mailimap_section_part * section_part = 0;
470 mailimap_section_spec * section_spec = 0;
471 mailimap_section * section = 0;
472 mailimap_fetch_att * fetch_att = 0;
469 473
470 login(); 474 login();
471 if (!m_imap) { 475 if (!m_imap) {
472 return res; 476 return res;
473 } 477 }
474 if (!internal_call) { 478 if (!internal_call) {
475 mb = mail.getMbox().latin1(); 479 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb); 480 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) { 481 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response); 482 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res; 483 return res;
480 } 484 }
481 } 485 }
482 set = mailimap_set_new_single(mail.getNumber()); 486 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j];
487 clist_append(id_list,p_id);
488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493 487
488 clist*id_list = 0;
489
490 /* if path == empty then its a request for the whole rfc822 mail and generates
491 a "fetch <id> (body[])" statement on imap server */
492 if (path.count()>0 ) {
493 id_list = clist_new();
494 for (unsigned j=0; j < path.count();++j) {
495 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
496 *p_id = path[j];
497 clist_append(id_list,p_id);
498 }
499 section_part = mailimap_section_part_new(id_list);
500 section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
501 }
502
503 section = mailimap_section_new(section_spec);
504 fetch_att = mailimap_fetch_att_new_body_section(section);
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 505 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495 506
496 clist*result = 0; 507 clist*result = 0;
497 508
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 509 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 510 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 511 mailimap_fetch_type_free( fetchType );
501 512
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 513 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 514 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 515 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item; 516 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 517 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 518 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 519 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 520 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 521 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */ 522 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 523 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 524 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 } 525 }
515 } 526 }
516 } 527 }
517 } else { 528 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 529 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 530 }
520 if (result) mailimap_fetch_list_free(result); 531 if (result) mailimap_fetch_list_free(result);
521 return res; 532 return res;
522} 533}
523 534
524/* current_recursion is for recursive calls. 535/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */ 536 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 537void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count) 538 int current_recursion,QValueList<int>recList,int current_count)
528{ 539{
529 if (!body || current_recursion>=10) { 540 if (!body || current_recursion>=10) {
530 return; 541 return;
531 } 542 }
532 switch (body->bd_type) { 543 switch (body->bd_type) {
533 case MAILIMAP_BODY_1PART: 544 case MAILIMAP_BODY_1PART:
534 { 545 {
535 QValueList<int>countlist = recList; 546 QValueList<int>countlist = recList;
536 countlist.append(current_count); 547 countlist.append(current_count);
537 RecPart currentPart; 548 RecPart currentPart;
538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 549 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
539 QString id(""); 550 QString id("");
540 currentPart.setPositionlist(countlist); 551 currentPart.setPositionlist(countlist);
541 for (unsigned int j = 0; j < countlist.count();++j) { 552 for (unsigned int j = 0; j < countlist.count();++j) {
@@ -910,83 +921,94 @@ int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const
910 pre+=delemiter; 921 pre+=delemiter;
911 } else { 922 } else {
912 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); 923 Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre));
913 return 0; 924 return 0;
914 } 925 }
915 } 926 }
916 qDebug("Creating %s",pre.latin1()); 927 qDebug("Creating %s",pre.latin1());
917 int res = mailimap_create(m_imap,pre.latin1()); 928 int res = mailimap_create(m_imap,pre.latin1());
918 if (res != MAILIMAP_NO_ERROR) { 929 if (res != MAILIMAP_NO_ERROR) {
919 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 930 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
920 return 0; 931 return 0;
921 } 932 }
922 return 1; 933 return 1;
923} 934}
924 935
925int IMAPwrapper::deleteMbox(const Folder*folder) 936int IMAPwrapper::deleteMbox(const Folder*folder)
926{ 937{
927 if (!folder) return 0; 938 if (!folder) return 0;
928 login(); 939 login();
929 if (!m_imap) {return 0;} 940 if (!m_imap) {return 0;}
930 int res = mailimap_delete(m_imap,folder->getName()); 941 int res = mailimap_delete(m_imap,folder->getName());
931 if (res != MAILIMAP_NO_ERROR) { 942 if (res != MAILIMAP_NO_ERROR) {
932 Global::statusMessage(tr("%1").arg(m_imap->imap_response)); 943 Global::statusMessage(tr("%1").arg(m_imap->imap_response));
933 return 0; 944 return 0;
934 } 945 }
935 return 1; 946 return 1;
936} 947}
937 948
938void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 949void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
939{ 950{
940 mailimap_status_att_list * att_list =0; 951 mailimap_status_att_list * att_list =0;
941 mailimap_mailbox_data_status * status=0; 952 mailimap_mailbox_data_status * status=0;
942 clistiter * cur = 0; 953 clistiter * cur = 0;
943 int r = 0; 954 int r = 0;
944 int res = 0; 955 int res = 0;
945 target_stat.message_count = 0; 956 target_stat.message_count = 0;
946 target_stat.message_unseen = 0; 957 target_stat.message_unseen = 0;
947 target_stat.message_recent = 0; 958 target_stat.message_recent = 0;
948 login(); 959 login();
949 if (!m_imap) { 960 if (!m_imap) {
950 return; 961 return;
951 } 962 }
952 att_list = mailimap_status_att_list_new_empty(); 963 att_list = mailimap_status_att_list_new_empty();
953 if (!att_list) return; 964 if (!att_list) return;
954 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); 965 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES);
955 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); 966 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT);
956 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); 967 r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN);
957 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); 968 r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status);
958 for (cur = clist_begin(status->st_info_list); 969 if (r==MAILIMAP_NO_ERROR&&status->st_info_list!=0) {
959 cur != NULL ; cur = clist_next(cur)) { 970 for (cur = clist_begin(status->st_info_list);
960 mailimap_status_info * status_info; 971 cur != NULL ; cur = clist_next(cur)) {
961 status_info = (mailimap_status_info *)clist_content(cur); 972 mailimap_status_info * status_info;
962 switch (status_info->st_att) { 973 status_info = (mailimap_status_info *)clist_content(cur);
963 case MAILIMAP_STATUS_ATT_MESSAGES: 974 switch (status_info->st_att) {
964 target_stat.message_count = status_info->st_value; 975 case MAILIMAP_STATUS_ATT_MESSAGES:
965 break; 976 target_stat.message_count = status_info->st_value;
966 case MAILIMAP_STATUS_ATT_RECENT: 977 break;
967 target_stat.message_recent = status_info->st_value; 978 case MAILIMAP_STATUS_ATT_RECENT:
968 break; 979 target_stat.message_recent = status_info->st_value;
969 case MAILIMAP_STATUS_ATT_UNSEEN: 980 break;
970 target_stat.message_unseen = status_info->st_value; 981 case MAILIMAP_STATUS_ATT_UNSEEN:
971 break; 982 target_stat.message_unseen = status_info->st_value;
983 break;
984 }
972 } 985 }
986 } else {
987 qDebug("Error retrieving status");
973 } 988 }
974 mailimap_mailbox_data_status_free(status); 989 if (status) mailimap_mailbox_data_status_free(status);
975 mailimap_status_att_list_free(att_list); 990 if (att_list) mailimap_status_att_list_free(att_list);
976} 991}
977 992
978void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder) 993void IMAPwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
979{ 994{
980 login(); 995 login();
981 if (!m_imap) return; 996 if (!m_imap) return;
982 if (!msg) return; 997 if (!msg) return;
983 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length); 998 int r = mailimap_append(m_imap,(char*)folder.latin1(),0,0,msg,length);
984 if (r != MAILIMAP_NO_ERROR) { 999 if (r != MAILIMAP_NO_ERROR) {
985 Global::statusMessage("Error storing mail!"); 1000 Global::statusMessage("Error storing mail!");
986 } 1001 }
987} 1002}
988 1003
989const QString&IMAPwrapper::getType()const 1004const QString&IMAPwrapper::getType()const
990{ 1005{
991 return account->getType(); 1006 return account->getType();
992} 1007}
1008
1009encodedString* IMAPwrapper::fetchRawBody(const RecMail&mail)
1010{
1011 // dummy
1012 QValueList<int> path;
1013 return fetchRawPart(mail,path,false);
1014}