-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 148 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 5 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 148 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 5 |
4 files changed, 128 insertions, 178 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index 406c57c..f7e93aa 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp | |||
@@ -55,27 +55,34 @@ void IMAPwrapper::login() | |||
55 | return; | 55 | return; |
56 | } | 56 | } |
57 | } else { | 57 | } else { |
58 | user = account->getUser().latin1(); | 58 | user = account->getUser().latin1(); |
59 | pass = account->getPassword().latin1(); | 59 | pass = account->getPassword().latin1(); |
60 | } | 60 | } |
61 | 61 | ||
62 | m_imap = mailimap_new( 20, &imap_progress ); | 62 | m_imap = mailimap_new( 20, &imap_progress ); |
63 | |||
63 | /* connect */ | 64 | /* connect */ |
64 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
65 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
66 | } else { | 67 | } else { |
67 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
68 | } | 69 | } |
69 | 70 | ||
70 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
71 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
72 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
73 | Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response)); | 74 | QString failure = ""; |
75 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | ||
76 | failure="Connection refused"; | ||
77 | } else { | ||
78 | failure="Unknown failure"; | ||
79 | } | ||
80 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | ||
74 | mailimap_free( m_imap ); | 81 | mailimap_free( m_imap ); |
75 | m_imap = 0; | 82 | m_imap = 0; |
76 | return; | 83 | return; |
77 | } | 84 | } |
78 | 85 | ||
79 | /* login */ | 86 | /* login */ |
80 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 87 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
81 | if ( err != MAILIMAP_NO_ERROR ) { | 88 | if ( err != MAILIMAP_NO_ERROR ) { |
@@ -395,68 +402,26 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) | |||
395 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
396 | mailimap_set_free( set ); | 403 | mailimap_set_free( set ); |
397 | mailimap_fetch_type_free( fetchType ); | 404 | mailimap_fetch_type_free( fetchType ); |
398 | 405 | ||
399 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
400 | mailimap_msg_att * msg_att; | 407 | mailimap_msg_att * msg_att; |
401 | msg_att = (mailimap_msg_att*)current->data; | 408 | msg_att = (mailimap_msg_att*)current->data; |
402 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
410 | QValueList<int> path; | ||
403 | body_desc = item->att_data.att_static->att_data.att_body; | 411 | body_desc = item->att_data.att_static->att_data.att_body; |
404 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 412 | traverseBody(mail,body_desc,body,0,path); |
405 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | ||
406 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | ||
407 | qDebug("Mulitpart mail"); | ||
408 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | ||
409 | } | ||
410 | } else { | 413 | } else { |
411 | qDebug("error fetching body: %s",m_imap->imap_response); | 414 | qDebug("error fetching body: %s",m_imap->imap_response); |
412 | } | 415 | } |
413 | if (result) mailimap_fetch_list_free(result); | 416 | if (result) mailimap_fetch_list_free(result); |
414 | return body; | 417 | return body; |
415 | } | 418 | } |
416 | 419 | ||
417 | /* this routine is just called when the mail has only ONE part. | ||
418 | for filling the parts of a multi-part-message there are other | ||
419 | routines 'cause we can not simply fetch the whole body. */ | ||
420 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | ||
421 | { | ||
422 | if (!mailDescription) { | ||
423 | return; | ||
424 | } | ||
425 | QString sub,body_text; | ||
426 | RecPart singlePart; | ||
427 | QValueList<int> path; | ||
428 | fillSinglePart(singlePart,mailDescription); | ||
429 | switch (mailDescription->bd_type) { | ||
430 | case MAILIMAP_BODY_TYPE_1PART_MSG: | ||
431 | path.append(1); | ||
432 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | ||
433 | target_body.setBodytext(body_text); | ||
434 | target_body.setDescription(singlePart); | ||
435 | break; | ||
436 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | ||
437 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | ||
438 | path.append(1); | ||
439 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | ||
440 | target_body.setBodytext(body_text); | ||
441 | target_body.setDescription(singlePart); | ||
442 | break; | ||
443 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | ||
444 | qDebug("Single attachment"); | ||
445 | target_body.setBodytext(""); | ||
446 | target_body.addPart(singlePart); | ||
447 | break; | ||
448 | default: | ||
449 | break; | ||
450 | } | ||
451 | |||
452 | return; | ||
453 | } | ||
454 | |||
455 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
456 | { | 421 | { |
457 | QStringList l; | 422 | QStringList l; |
458 | QString from; | 423 | QString from; |
459 | bool named_from; | 424 | bool named_from; |
460 | clistcell *current = NULL; | 425 | clistcell *current = NULL; |
461 | mailimap_address * current_address=NULL; | 426 | mailimap_address * current_address=NULL; |
462 | if (!list) { | 427 | if (!list) { |
@@ -464,17 +429,16 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
464 | } | 429 | } |
465 | unsigned int count = 0; | 430 | unsigned int count = 0; |
466 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
467 | from = ""; | 432 | from = ""; |
468 | named_from = false; | 433 | named_from = false; |
469 | current_address=(mailimap_address*)current->data; | 434 | current_address=(mailimap_address*)current->data; |
470 | if (current_address->ad_personal_name){ | 435 | if (current_address->ad_personal_name){ |
471 | from+=convert_String((const char*)current_address->ad_personal_name); | 436 | from+=convert_String((const char*)current_address->ad_personal_name); |
472 | //from+=QString(current_address->ad_personal_name); | ||
473 | from+=" "; | 437 | from+=" "; |
474 | named_from = true; | 438 | named_from = true; |
475 | } | 439 | } |
476 | 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)) { |
477 | from+="<"; | 441 | from+="<"; |
478 | } | 442 | } |
479 | if (current_address->ad_mailbox_name) { | 443 | if (current_address->ad_mailbox_name) { |
480 | from+=QString(current_address->ad_mailbox_name); | 444 | from+=QString(current_address->ad_mailbox_name); |
@@ -552,72 +516,88 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
552 | } | 516 | } |
553 | } else { | 517 | } else { |
554 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
555 | } | 519 | } |
556 | if (result) mailimap_fetch_list_free(result); | 520 | if (result) mailimap_fetch_list_free(result); |
557 | return res; | 521 | return res; |
558 | } | 522 | } |
559 | 523 | ||
560 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 524 | /* current_recursion is for recursive calls. |
525 | current_count means the position inside the internal loop! */ | ||
526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | ||
527 | int current_recursion,QValueList<int>recList,int current_count) | ||
561 | { | 528 | { |
562 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 529 | if (!body || current_recursion>=10) { |
563 | if (!mailDescription||current_recursion==10) { | ||
564 | return; | 530 | return; |
565 | } | 531 | } |
566 | clistcell*current; | 532 | ++current_count; |
567 | mailimap_body*current_body; | 533 | switch (body->bd_type) { |
568 | unsigned int count = 0; | 534 | case MAILIMAP_BODY_1PART: |
569 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 535 | { |
570 | /* the point in the message */ | 536 | QValueList<int>countlist = recList; |
571 | ++count; | 537 | countlist.append(current_count); |
572 | current_body = (mailimap_body*)current->data; | 538 | RecPart currentPart; |
573 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 539 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
574 | QValueList<int>countlist = recList; | 540 | QString id(""); |
575 | countlist.append(count); | 541 | currentPart.setPositionlist(countlist); |
576 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 542 | for (unsigned int j = 0; j < countlist.count();++j) { |
577 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 543 | id+=(j>0?" ":""); |
578 | RecPart currentPart; | 544 | id+=QString("%1").arg(countlist[j]); |
579 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 545 | } |
580 | QValueList<int>countlist = recList; | 546 | qDebug("ID = %s",id.latin1()); |
581 | countlist.append(count); | 547 | currentPart.setIdentifier(id); |
582 | /* important: Check for is NULL 'cause a body can be empty! */ | 548 | fillSinglePart(currentPart,part1); |
583 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 549 | /* important: Check for is NULL 'cause a body can be empty! |
584 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 550 | And we put it only into the mail if it is the FIRST part */ |
585 | target_body.setDescription(currentPart); | 551 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
586 | target_body.setBodytext(body_text); | 552 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
587 | } else { | 553 | target_body.setDescription(currentPart); |
588 | QString id(""); | 554 | target_body.setBodytext(body_text); |
589 | for (unsigned int j = 0; j < countlist.count();++j) { | 555 | } else { |
590 | id+=(j>0?" ":""); | 556 | target_body.addPart(currentPart); |
591 | id+=QString("%1").arg(countlist[j]); | 557 | } |
592 | } | 558 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
593 | qDebug("ID= %s",id.latin1()); | 559 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
594 | currentPart.setIdentifier(id); | 560 | } |
595 | currentPart.setPositionlist(countlist); | 561 | } |
596 | target_body.addPart(currentPart); | 562 | break; |
597 | } | 563 | case MAILIMAP_BODY_MPART: |
564 | { | ||
565 | clistcell*current=0; | ||
566 | mailimap_body*current_body=0; | ||
567 | unsigned int ccount = current_count-1; | ||
568 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | ||
569 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | ||
570 | current_body = (mailimap_body*)current->data; | ||
571 | traverseBody(mail,current_body,target_body,current_recursion+1,recList,ccount); | ||
572 | ++ccount; | ||
598 | } | 573 | } |
599 | } | 574 | } |
575 | break; | ||
576 | default: | ||
577 | break; | ||
578 | } | ||
600 | } | 579 | } |
601 | 580 | ||
602 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 581 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
603 | { | 582 | { |
604 | if (!Description) { | 583 | if (!Description) { |
605 | return; | 584 | return; |
606 | } | 585 | } |
607 | switch (Description->bd_type) { | 586 | switch (Description->bd_type) { |
608 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 587 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
609 | target_part.setType("text"); | 588 | target_part.setType("text"); |
610 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 589 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
611 | break; | 590 | break; |
612 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 591 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
613 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 592 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
614 | break; | 593 | break; |
615 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 594 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
595 | target_part.setType("message"); | ||
616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 596 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
617 | break; | 597 | break; |
618 | default: | 598 | default: |
619 | break; | 599 | break; |
620 | } | 600 | } |
621 | } | 601 | } |
622 | 602 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 603 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
@@ -632,23 +612,19 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text | |||
632 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
633 | } | 613 | } |
634 | 614 | ||
635 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 615 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
636 | { | 616 | { |
637 | if (!which) { | 617 | if (!which) { |
638 | return; | 618 | return; |
639 | } | 619 | } |
640 | // QString sub; | 620 | target_part.setSubtype("rfc822"); |
641 | // sub = which->bd_media_text; | ||
642 | // target_part.setSubtype(sub.lower()); | ||
643 | qDebug("Message part"); | 621 | qDebug("Message part"); |
644 | /* we set this type to text/plain */ | 622 | /* we set this type to text/plain */ |
645 | target_part.setType("text"); | ||
646 | target_part.setSubtype("plain"); | ||
647 | target_part.setLines(which->bd_lines); | 623 | target_part.setLines(which->bd_lines); |
648 | fillBodyFields(target_part,which->bd_fields); | 624 | fillBodyFields(target_part,which->bd_fields); |
649 | } | 625 | } |
650 | 626 | ||
651 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 627 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
652 | { | 628 | { |
653 | if (!which) { | 629 | if (!which) { |
654 | return; | 630 | return; |
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 9b20288..e5846f8 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h | |||
@@ -2,16 +2,17 @@ | |||
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 | ||
9 | struct mailimap; | 9 | struct mailimap; |
10 | struct mailimap_body; | ||
10 | struct mailimap_body_type_1part; | 11 | struct mailimap_body_type_1part; |
11 | struct mailimap_body_type_text; | 12 | struct mailimap_body_type_text; |
12 | struct mailimap_body_type_basic; | 13 | struct mailimap_body_type_basic; |
13 | struct mailimap_body_type_msg; | 14 | struct mailimap_body_type_msg; |
14 | struct mailimap_body_type_mpart; | 15 | struct mailimap_body_type_mpart; |
15 | struct mailimap_body_fields; | 16 | struct mailimap_body_fields; |
16 | struct mailimap_msg_att; | 17 | struct mailimap_msg_att; |
17 | class encodedString; | 18 | class encodedString; |
@@ -42,23 +43,21 @@ public: | |||
42 | protected: | 43 | protected: |
43 | RecMail*parse_list_result(mailimap_msg_att*); | 44 | RecMail*parse_list_result(mailimap_msg_att*); |
44 | void login(); | 45 | void login(); |
45 | void logout(); | 46 | void logout(); |
46 | 47 | ||
47 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 48 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
48 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 49 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
49 | 50 | ||
50 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | ||
51 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | ||
52 | |||
53 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 51 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
54 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 52 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
55 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 53 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
56 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 54 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
55 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=0); | ||
57 | 56 | ||
58 | /* just helpers */ | 57 | /* just helpers */ |
59 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 58 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
60 | static QStringList address_list_to_stringlist(clist*list); | 59 | static QStringList address_list_to_stringlist(clist*list); |
61 | 60 | ||
62 | 61 | ||
63 | IMAPaccount *account; | 62 | IMAPaccount *account; |
64 | mailimap *m_imap; | 63 | mailimap *m_imap; |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index 406c57c..f7e93aa 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp | |||
@@ -55,27 +55,34 @@ void IMAPwrapper::login() | |||
55 | return; | 55 | return; |
56 | } | 56 | } |
57 | } else { | 57 | } else { |
58 | user = account->getUser().latin1(); | 58 | user = account->getUser().latin1(); |
59 | pass = account->getPassword().latin1(); | 59 | pass = account->getPassword().latin1(); |
60 | } | 60 | } |
61 | 61 | ||
62 | m_imap = mailimap_new( 20, &imap_progress ); | 62 | m_imap = mailimap_new( 20, &imap_progress ); |
63 | |||
63 | /* connect */ | 64 | /* connect */ |
64 | if (account->getSSL()) { | 65 | if (account->getSSL()) { |
65 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); | 66 | err = mailimap_ssl_connect( m_imap, (char*)server, port ); |
66 | } else { | 67 | } else { |
67 | err = mailimap_socket_connect( m_imap, (char*)server, port ); | 68 | err = mailimap_socket_connect( m_imap, (char*)server, port ); |
68 | } | 69 | } |
69 | 70 | ||
70 | if ( err != MAILIMAP_NO_ERROR && | 71 | if ( err != MAILIMAP_NO_ERROR && |
71 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && | 72 | err != MAILIMAP_NO_ERROR_AUTHENTICATED && |
72 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { | 73 | err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { |
73 | Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response)); | 74 | QString failure = ""; |
75 | if (err == MAILIMAP_ERROR_CONNECTION_REFUSED) { | ||
76 | failure="Connection refused"; | ||
77 | } else { | ||
78 | failure="Unknown failure"; | ||
79 | } | ||
80 | Global::statusMessage(tr("error connecting imap server: %1").arg(failure)); | ||
74 | mailimap_free( m_imap ); | 81 | mailimap_free( m_imap ); |
75 | m_imap = 0; | 82 | m_imap = 0; |
76 | return; | 83 | return; |
77 | } | 84 | } |
78 | 85 | ||
79 | /* login */ | 86 | /* login */ |
80 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); | 87 | err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); |
81 | if ( err != MAILIMAP_NO_ERROR ) { | 88 | if ( err != MAILIMAP_NO_ERROR ) { |
@@ -395,68 +402,26 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) | |||
395 | err = mailimap_fetch( m_imap, set, fetchType, &result ); | 402 | err = mailimap_fetch( m_imap, set, fetchType, &result ); |
396 | mailimap_set_free( set ); | 403 | mailimap_set_free( set ); |
397 | mailimap_fetch_type_free( fetchType ); | 404 | mailimap_fetch_type_free( fetchType ); |
398 | 405 | ||
399 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { | 406 | if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { |
400 | mailimap_msg_att * msg_att; | 407 | mailimap_msg_att * msg_att; |
401 | msg_att = (mailimap_msg_att*)current->data; | 408 | msg_att = (mailimap_msg_att*)current->data; |
402 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; | 409 | mailimap_msg_att_item*item = (mailimap_msg_att_item*)msg_att->att_list->first->data; |
410 | QValueList<int> path; | ||
403 | body_desc = item->att_data.att_static->att_data.att_body; | 411 | body_desc = item->att_data.att_static->att_data.att_body; |
404 | if (body_desc->bd_type==MAILIMAP_BODY_1PART) { | 412 | traverseBody(mail,body_desc,body,0,path); |
405 | searchBodyText(mail,body_desc->bd_data.bd_body_1part,body); | ||
406 | } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) { | ||
407 | qDebug("Mulitpart mail"); | ||
408 | searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body); | ||
409 | } | ||
410 | } else { | 413 | } else { |
411 | qDebug("error fetching body: %s",m_imap->imap_response); | 414 | qDebug("error fetching body: %s",m_imap->imap_response); |
412 | } | 415 | } |
413 | if (result) mailimap_fetch_list_free(result); | 416 | if (result) mailimap_fetch_list_free(result); |
414 | return body; | 417 | return body; |
415 | } | 418 | } |
416 | 419 | ||
417 | /* this routine is just called when the mail has only ONE part. | ||
418 | for filling the parts of a multi-part-message there are other | ||
419 | routines 'cause we can not simply fetch the whole body. */ | ||
420 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) | ||
421 | { | ||
422 | if (!mailDescription) { | ||
423 | return; | ||
424 | } | ||
425 | QString sub,body_text; | ||
426 | RecPart singlePart; | ||
427 | QValueList<int> path; | ||
428 | fillSinglePart(singlePart,mailDescription); | ||
429 | switch (mailDescription->bd_type) { | ||
430 | case MAILIMAP_BODY_TYPE_1PART_MSG: | ||
431 | path.append(1); | ||
432 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | ||
433 | target_body.setBodytext(body_text); | ||
434 | target_body.setDescription(singlePart); | ||
435 | break; | ||
436 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | ||
437 | qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); | ||
438 | path.append(1); | ||
439 | body_text = fetchTextPart(mail,path,true,singlePart.Encoding()); | ||
440 | target_body.setBodytext(body_text); | ||
441 | target_body.setDescription(singlePart); | ||
442 | break; | ||
443 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | ||
444 | qDebug("Single attachment"); | ||
445 | target_body.setBodytext(""); | ||
446 | target_body.addPart(singlePart); | ||
447 | break; | ||
448 | default: | ||
449 | break; | ||
450 | } | ||
451 | |||
452 | return; | ||
453 | } | ||
454 | |||
455 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | 420 | QStringList IMAPwrapper::address_list_to_stringlist(clist*list) |
456 | { | 421 | { |
457 | QStringList l; | 422 | QStringList l; |
458 | QString from; | 423 | QString from; |
459 | bool named_from; | 424 | bool named_from; |
460 | clistcell *current = NULL; | 425 | clistcell *current = NULL; |
461 | mailimap_address * current_address=NULL; | 426 | mailimap_address * current_address=NULL; |
462 | if (!list) { | 427 | if (!list) { |
@@ -464,17 +429,16 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) | |||
464 | } | 429 | } |
465 | unsigned int count = 0; | 430 | unsigned int count = 0; |
466 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { | 431 | for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { |
467 | from = ""; | 432 | from = ""; |
468 | named_from = false; | 433 | named_from = false; |
469 | current_address=(mailimap_address*)current->data; | 434 | current_address=(mailimap_address*)current->data; |
470 | if (current_address->ad_personal_name){ | 435 | if (current_address->ad_personal_name){ |
471 | from+=convert_String((const char*)current_address->ad_personal_name); | 436 | from+=convert_String((const char*)current_address->ad_personal_name); |
472 | //from+=QString(current_address->ad_personal_name); | ||
473 | from+=" "; | 437 | from+=" "; |
474 | named_from = true; | 438 | named_from = true; |
475 | } | 439 | } |
476 | 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)) { |
477 | from+="<"; | 441 | from+="<"; |
478 | } | 442 | } |
479 | if (current_address->ad_mailbox_name) { | 443 | if (current_address->ad_mailbox_name) { |
480 | from+=QString(current_address->ad_mailbox_name); | 444 | from+=QString(current_address->ad_mailbox_name); |
@@ -552,72 +516,88 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int> | |||
552 | } | 516 | } |
553 | } else { | 517 | } else { |
554 | qDebug("error fetching text: %s",m_imap->imap_response); | 518 | qDebug("error fetching text: %s",m_imap->imap_response); |
555 | } | 519 | } |
556 | if (result) mailimap_fetch_list_free(result); | 520 | if (result) mailimap_fetch_list_free(result); |
557 | return res; | 521 | return res; |
558 | } | 522 | } |
559 | 523 | ||
560 | void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) | 524 | /* current_recursion is for recursive calls. |
525 | current_count means the position inside the internal loop! */ | ||
526 | void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, | ||
527 | int current_recursion,QValueList<int>recList,int current_count) | ||
561 | { | 528 | { |
562 | /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ | 529 | if (!body || current_recursion>=10) { |
563 | if (!mailDescription||current_recursion==10) { | ||
564 | return; | 530 | return; |
565 | } | 531 | } |
566 | clistcell*current; | 532 | ++current_count; |
567 | mailimap_body*current_body; | 533 | switch (body->bd_type) { |
568 | unsigned int count = 0; | 534 | case MAILIMAP_BODY_1PART: |
569 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | 535 | { |
570 | /* the point in the message */ | 536 | QValueList<int>countlist = recList; |
571 | ++count; | 537 | countlist.append(current_count); |
572 | current_body = (mailimap_body*)current->data; | 538 | RecPart currentPart; |
573 | if (current_body->bd_type==MAILIMAP_BODY_MPART) { | 539 | mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; |
574 | QValueList<int>countlist = recList; | 540 | QString id(""); |
575 | countlist.append(count); | 541 | currentPart.setPositionlist(countlist); |
576 | searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,countlist); | 542 | for (unsigned int j = 0; j < countlist.count();++j) { |
577 | } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ | 543 | id+=(j>0?" ":""); |
578 | RecPart currentPart; | 544 | id+=QString("%1").arg(countlist[j]); |
579 | fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); | 545 | } |
580 | QValueList<int>countlist = recList; | 546 | qDebug("ID = %s",id.latin1()); |
581 | countlist.append(count); | 547 | currentPart.setIdentifier(id); |
582 | /* important: Check for is NULL 'cause a body can be empty! */ | 548 | fillSinglePart(currentPart,part1); |
583 | if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { | 549 | /* important: Check for is NULL 'cause a body can be empty! |
584 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); | 550 | And we put it only into the mail if it is the FIRST part */ |
585 | target_body.setDescription(currentPart); | 551 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { |
586 | target_body.setBodytext(body_text); | 552 | QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); |
587 | } else { | 553 | target_body.setDescription(currentPart); |
588 | QString id(""); | 554 | target_body.setBodytext(body_text); |
589 | for (unsigned int j = 0; j < countlist.count();++j) { | 555 | } else { |
590 | id+=(j>0?" ":""); | 556 | target_body.addPart(currentPart); |
591 | id+=QString("%1").arg(countlist[j]); | 557 | } |
592 | } | 558 | if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { |
593 | qDebug("ID= %s",id.latin1()); | 559 | traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); |
594 | currentPart.setIdentifier(id); | 560 | } |
595 | currentPart.setPositionlist(countlist); | 561 | } |
596 | target_body.addPart(currentPart); | 562 | break; |
597 | } | 563 | case MAILIMAP_BODY_MPART: |
564 | { | ||
565 | clistcell*current=0; | ||
566 | mailimap_body*current_body=0; | ||
567 | unsigned int ccount = current_count-1; | ||
568 | mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; | ||
569 | for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { | ||
570 | current_body = (mailimap_body*)current->data; | ||
571 | traverseBody(mail,current_body,target_body,current_recursion+1,recList,ccount); | ||
572 | ++ccount; | ||
598 | } | 573 | } |
599 | } | 574 | } |
575 | break; | ||
576 | default: | ||
577 | break; | ||
578 | } | ||
600 | } | 579 | } |
601 | 580 | ||
602 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) | 581 | void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) |
603 | { | 582 | { |
604 | if (!Description) { | 583 | if (!Description) { |
605 | return; | 584 | return; |
606 | } | 585 | } |
607 | switch (Description->bd_type) { | 586 | switch (Description->bd_type) { |
608 | case MAILIMAP_BODY_TYPE_1PART_TEXT: | 587 | case MAILIMAP_BODY_TYPE_1PART_TEXT: |
609 | target_part.setType("text"); | 588 | target_part.setType("text"); |
610 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); | 589 | fillSingleTextPart(target_part,Description->bd_data.bd_type_text); |
611 | break; | 590 | break; |
612 | case MAILIMAP_BODY_TYPE_1PART_BASIC: | 591 | case MAILIMAP_BODY_TYPE_1PART_BASIC: |
613 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); | 592 | fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); |
614 | break; | 593 | break; |
615 | case MAILIMAP_BODY_TYPE_1PART_MSG: | 594 | case MAILIMAP_BODY_TYPE_1PART_MSG: |
595 | target_part.setType("message"); | ||
616 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); | 596 | fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); |
617 | break; | 597 | break; |
618 | default: | 598 | default: |
619 | break; | 599 | break; |
620 | } | 600 | } |
621 | } | 601 | } |
622 | 602 | ||
623 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) | 603 | void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) |
@@ -632,23 +612,19 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text | |||
632 | fillBodyFields(target_part,which->bd_fields); | 612 | fillBodyFields(target_part,which->bd_fields); |
633 | } | 613 | } |
634 | 614 | ||
635 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) | 615 | void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) |
636 | { | 616 | { |
637 | if (!which) { | 617 | if (!which) { |
638 | return; | 618 | return; |
639 | } | 619 | } |
640 | // QString sub; | 620 | target_part.setSubtype("rfc822"); |
641 | // sub = which->bd_media_text; | ||
642 | // target_part.setSubtype(sub.lower()); | ||
643 | qDebug("Message part"); | 621 | qDebug("Message part"); |
644 | /* we set this type to text/plain */ | 622 | /* we set this type to text/plain */ |
645 | target_part.setType("text"); | ||
646 | target_part.setSubtype("plain"); | ||
647 | target_part.setLines(which->bd_lines); | 623 | target_part.setLines(which->bd_lines); |
648 | fillBodyFields(target_part,which->bd_fields); | 624 | fillBodyFields(target_part,which->bd_fields); |
649 | } | 625 | } |
650 | 626 | ||
651 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) | 627 | void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) |
652 | { | 628 | { |
653 | if (!which) { | 629 | if (!which) { |
654 | return; | 630 | return; |
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 9b20288..e5846f8 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h | |||
@@ -2,16 +2,17 @@ | |||
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 | ||
9 | struct mailimap; | 9 | struct mailimap; |
10 | struct mailimap_body; | ||
10 | struct mailimap_body_type_1part; | 11 | struct mailimap_body_type_1part; |
11 | struct mailimap_body_type_text; | 12 | struct mailimap_body_type_text; |
12 | struct mailimap_body_type_basic; | 13 | struct mailimap_body_type_basic; |
13 | struct mailimap_body_type_msg; | 14 | struct mailimap_body_type_msg; |
14 | struct mailimap_body_type_mpart; | 15 | struct mailimap_body_type_mpart; |
15 | struct mailimap_body_fields; | 16 | struct mailimap_body_fields; |
16 | struct mailimap_msg_att; | 17 | struct mailimap_msg_att; |
17 | class encodedString; | 18 | class encodedString; |
@@ -42,23 +43,21 @@ public: | |||
42 | protected: | 43 | protected: |
43 | RecMail*parse_list_result(mailimap_msg_att*); | 44 | RecMail*parse_list_result(mailimap_msg_att*); |
44 | void login(); | 45 | void login(); |
45 | void logout(); | 46 | void logout(); |
46 | 47 | ||
47 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); | 48 | virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); |
48 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); | 49 | virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); |
49 | 50 | ||
50 | void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); | ||
51 | void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); | ||
52 | |||
53 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); | 51 | void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); |
54 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); | 52 | void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); |
55 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); | 53 | void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); |
56 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); | 54 | void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); |
55 | void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=0); | ||
57 | 56 | ||
58 | /* just helpers */ | 57 | /* just helpers */ |
59 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); | 58 | static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); |
60 | static QStringList address_list_to_stringlist(clist*list); | 59 | static QStringList address_list_to_stringlist(clist*list); |
61 | 60 | ||
62 | 61 | ||
63 | IMAPaccount *account; | 62 | IMAPaccount *account; |
64 | mailimap *m_imap; | 63 | mailimap *m_imap; |