summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.h2
-rw-r--r--noncore/net/mail/imapwrapper.cpp32
-rw-r--r--noncore/net/mail/imapwrapper.h5
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h2
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp32
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h5
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp5
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h2
-rw-r--r--noncore/net/mail/pop3wrapper.cpp5
-rw-r--r--noncore/net/mail/pop3wrapper.h2
10 files changed, 80 insertions, 12 deletions
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index bc8938f..0a1719d 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -1,30 +1,30 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13 13
14class AbstractMail:public QObject 14class AbstractMail:public QObject
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17public: 17public:
18 AbstractMail(){}; 18 AbstractMail(){};
19 virtual ~AbstractMail(){} 19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0;
24 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
24 virtual void deleteMail(const RecMail&mail)=0;
25 25
26 static AbstractMail* getWrapper(IMAPaccount *a); 26 static AbstractMail* getWrapper(IMAPaccount *a);
27 static AbstractMail* getWrapper(POP3account *a); 27 static AbstractMail* getWrapper(POP3account *a);
28}; 28};
29 29
30#endif 30#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index 3222c7e..a01a2a9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -443,256 +443,288 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
443 if (++count > 99) { 443 if (++count > 99) {
444 break; 444 break;
445 } 445 }
446 } 446 }
447 return l; 447 return l;
448} 448}
449 449
450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
451{ 451{
452 QString body(""); 452 QString body("");
453 const char*mb; 453 const char*mb;
454 int err; 454 int err;
455 mailimap_fetch_type *fetchType; 455 mailimap_fetch_type *fetchType;
456 mailimap_set *set; 456 mailimap_set *set;
457 clistcell*current,*cur; 457 clistcell*current,*cur;
458 458
459 login(); 459 login();
460 if (!m_imap) { 460 if (!m_imap) {
461 return body; 461 return body;
462 } 462 }
463 if (!internal_call) { 463 if (!internal_call) {
464 mb = mail.getMbox().latin1(); 464 mb = mail.getMbox().latin1();
465 err = mailimap_select( m_imap, (char*)mb); 465 err = mailimap_select( m_imap, (char*)mb);
466 if ( err != MAILIMAP_NO_ERROR ) { 466 if ( err != MAILIMAP_NO_ERROR ) {
467 qDebug("error selecting mailbox: %s",m_imap->imap_response); 467 qDebug("error selecting mailbox: %s",m_imap->imap_response);
468 return body; 468 return body;
469 } 469 }
470 } 470 }
471 set = mailimap_set_new_single(mail.getNumber()); 471 set = mailimap_set_new_single(mail.getNumber());
472 clist*id_list=clist_new(); 472 clist*id_list=clist_new();
473 for (unsigned j=0; j < path.count();++j) { 473 for (unsigned j=0; j < path.count();++j) {
474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
475 *p_id = path[j]; 475 *p_id = path[j];
476 clist_append(id_list,p_id); 476 clist_append(id_list,p_id);
477 } 477 }
478 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 478 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
480 mailimap_section * section = mailimap_section_new(section_spec); 480 mailimap_section * section = mailimap_section_new(section_spec);
481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
482 482
483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
484 484
485 clist*result = clist_new(); 485 clist*result = clist_new();
486 486
487 err = mailimap_fetch( m_imap, set, fetchType, &result ); 487 err = mailimap_fetch( m_imap, set, fetchType, &result );
488 mailimap_set_free( set ); 488 mailimap_set_free( set );
489 mailimap_fetch_type_free( fetchType ); 489 mailimap_fetch_type_free( fetchType );
490 490
491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
492 mailimap_msg_att * msg_att; 492 mailimap_msg_att * msg_att;
493 msg_att = (mailimap_msg_att*)current->data; 493 msg_att = (mailimap_msg_att*)current->data;
494 mailimap_msg_att_item*msg_att_item; 494 mailimap_msg_att_item*msg_att_item;
495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
501 if (text) { 501 if (text) {
502 body = QString(text); 502 body = QString(text);
503 free(text); 503 free(text);
504 } else { 504 } else {
505 body = ""; 505 body = "";
506 } 506 }
507 } 507 }
508 } 508 }
509 } 509 }
510 510
511 } else { 511 } else {
512 qDebug("error fetching text: %s",m_imap->imap_response); 512 qDebug("error fetching text: %s",m_imap->imap_response);
513 } 513 }
514 mailimap_fetch_list_free(result); 514 mailimap_fetch_list_free(result);
515 return body; 515 return body;
516} 516}
517 517
518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
519{ 519{
520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
521 if (!mailDescription||current_recursion==10) { 521 if (!mailDescription||current_recursion==10) {
522 return; 522 return;
523 } 523 }
524 clistcell*current; 524 clistcell*current;
525 mailimap_body*current_body; 525 mailimap_body*current_body;
526 unsigned int count = 0; 526 unsigned int count = 0;
527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
528 /* the point in the message */ 528 /* the point in the message */
529 ++count; 529 ++count;
530 current_body = (mailimap_body*)current->data; 530 current_body = (mailimap_body*)current->data;
531 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 531 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
532 QValueList<int>clist = recList; 532 QValueList<int>clist = recList;
533 clist.append(count); 533 clist.append(count);
534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
536 RecPart currentPart; 536 RecPart currentPart;
537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
538 QValueList<int>clist = recList; 538 QValueList<int>clist = recList;
539 clist.append(count); 539 clist.append(count);
540 /* important: Check for is NULL 'cause a body can be empty! */ 540 /* important: Check for is NULL 'cause a body can be empty! */
541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
542 QString body_text = fetchPart(mail,clist,true); 542 QString body_text = fetchPart(mail,clist,true);
543 target_body.setDescription(currentPart); 543 target_body.setDescription(currentPart);
544 target_body.setBodytext(body_text); 544 target_body.setBodytext(body_text);
545 } else { 545 } else {
546 QString id(""); 546 QString id("");
547 for (unsigned int j = 0; j < clist.count();++j) { 547 for (unsigned int j = 0; j < clist.count();++j) {
548 id+=(j>0?" ":""); 548 id+=(j>0?" ":"");
549 id+=QString("%1").arg(clist[j]); 549 id+=QString("%1").arg(clist[j]);
550 } 550 }
551 qDebug("ID= %s",id.latin1()); 551 qDebug("ID= %s",id.latin1());
552 currentPart.setIdentifier(id); 552 currentPart.setIdentifier(id);
553 currentPart.setPositionlist(clist); 553 currentPart.setPositionlist(clist);
554 target_body.addPart(currentPart); 554 target_body.addPart(currentPart);
555 } 555 }
556 } 556 }
557 } 557 }
558} 558}
559 559
560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
561{ 561{
562 if (!Description) { 562 if (!Description) {
563 return; 563 return;
564 } 564 }
565 switch (Description->bd_type) { 565 switch (Description->bd_type) {
566 case MAILIMAP_BODY_TYPE_1PART_TEXT: 566 case MAILIMAP_BODY_TYPE_1PART_TEXT:
567 target_part.setType("text"); 567 target_part.setType("text");
568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
569 break; 569 break;
570 case MAILIMAP_BODY_TYPE_1PART_BASIC: 570 case MAILIMAP_BODY_TYPE_1PART_BASIC:
571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
572 break; 572 break;
573 case MAILIMAP_BODY_TYPE_1PART_MSG: 573 case MAILIMAP_BODY_TYPE_1PART_MSG:
574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
575 break; 575 break;
576 default: 576 default:
577 break; 577 break;
578 } 578 }
579} 579}
580 580
581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
582{ 582{
583 if (!which) { 583 if (!which) {
584 return; 584 return;
585 } 585 }
586 QString sub; 586 QString sub;
587 sub = which->bd_media_text; 587 sub = which->bd_media_text;
588 target_part.setSubtype(sub.lower()); 588 target_part.setSubtype(sub.lower());
589 target_part.setLines(which->bd_lines); 589 target_part.setLines(which->bd_lines);
590 fillBodyFields(target_part,which->bd_fields); 590 fillBodyFields(target_part,which->bd_fields);
591} 591}
592 592
593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
594{ 594{
595 if (!which) { 595 if (!which) {
596 return; 596 return;
597 } 597 }
598// QString sub; 598// QString sub;
599// sub = which->bd_media_text; 599// sub = which->bd_media_text;
600// target_part.setSubtype(sub.lower()); 600// target_part.setSubtype(sub.lower());
601 qDebug("Message part"); 601 qDebug("Message part");
602 /* we set this type to text/plain */ 602 /* we set this type to text/plain */
603 target_part.setType("text"); 603 target_part.setType("text");
604 target_part.setSubtype("plain"); 604 target_part.setSubtype("plain");
605 target_part.setLines(which->bd_lines); 605 target_part.setLines(which->bd_lines);
606 fillBodyFields(target_part,which->bd_fields); 606 fillBodyFields(target_part,which->bd_fields);
607} 607}
608 608
609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
610{ 610{
611 if (!which) { 611 if (!which) {
612 return; 612 return;
613 } 613 }
614 QString type,sub; 614 QString type,sub;
615 switch (which->bd_media_basic->med_type) { 615 switch (which->bd_media_basic->med_type) {
616 case MAILIMAP_MEDIA_BASIC_APPLICATION: 616 case MAILIMAP_MEDIA_BASIC_APPLICATION:
617 type = "application"; 617 type = "application";
618 break; 618 break;
619 case MAILIMAP_MEDIA_BASIC_AUDIO: 619 case MAILIMAP_MEDIA_BASIC_AUDIO:
620 type = "audio"; 620 type = "audio";
621 break; 621 break;
622 case MAILIMAP_MEDIA_BASIC_IMAGE: 622 case MAILIMAP_MEDIA_BASIC_IMAGE:
623 type = "image"; 623 type = "image";
624 break; 624 break;
625 case MAILIMAP_MEDIA_BASIC_MESSAGE: 625 case MAILIMAP_MEDIA_BASIC_MESSAGE:
626 type = "message"; 626 type = "message";
627 break; 627 break;
628 case MAILIMAP_MEDIA_BASIC_VIDEO: 628 case MAILIMAP_MEDIA_BASIC_VIDEO:
629 type = "video"; 629 type = "video";
630 break; 630 break;
631 case MAILIMAP_MEDIA_BASIC_OTHER: 631 case MAILIMAP_MEDIA_BASIC_OTHER:
632 default: 632 default:
633 if (which->bd_media_basic->med_basic_type) { 633 if (which->bd_media_basic->med_basic_type) {
634 type = which->bd_media_basic->med_basic_type; 634 type = which->bd_media_basic->med_basic_type;
635 } else { 635 } else {
636 type = ""; 636 type = "";
637 } 637 }
638 break; 638 break;
639 } 639 }
640 if (which->bd_media_basic->med_subtype) { 640 if (which->bd_media_basic->med_subtype) {
641 sub = which->bd_media_basic->med_subtype; 641 sub = which->bd_media_basic->med_subtype;
642 } else { 642 } else {
643 sub = ""; 643 sub = "";
644 } 644 }
645 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 645 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
646 target_part.setType(type.lower()); 646 target_part.setType(type.lower());
647 target_part.setSubtype(sub.lower()); 647 target_part.setSubtype(sub.lower());
648 fillBodyFields(target_part,which->bd_fields); 648 fillBodyFields(target_part,which->bd_fields);
649} 649}
650 650
651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
652{ 652{
653 if (!which) return; 653 if (!which) return;
654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
655 clistcell*cur; 655 clistcell*cur;
656 mailimap_single_body_fld_param*param=0; 656 mailimap_single_body_fld_param*param=0;
657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
658 param = (mailimap_single_body_fld_param*)cur->data; 658 param = (mailimap_single_body_fld_param*)cur->data;
659 if (param) { 659 if (param) {
660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
661 } 661 }
662 } 662 }
663 } 663 }
664 mailimap_body_fld_enc*enc = which->bd_encoding; 664 mailimap_body_fld_enc*enc = which->bd_encoding;
665 QString encoding(""); 665 QString encoding("");
666 switch (enc->enc_type) { 666 switch (enc->enc_type) {
667 case MAILIMAP_BODY_FLD_ENC_7BIT: 667 case MAILIMAP_BODY_FLD_ENC_7BIT:
668 encoding = "7bit"; 668 encoding = "7bit";
669 break; 669 break;
670 case MAILIMAP_BODY_FLD_ENC_8BIT: 670 case MAILIMAP_BODY_FLD_ENC_8BIT:
671 encoding = "8bit"; 671 encoding = "8bit";
672 break; 672 break;
673 case MAILIMAP_BODY_FLD_ENC_BINARY: 673 case MAILIMAP_BODY_FLD_ENC_BINARY:
674 encoding="binary"; 674 encoding="binary";
675 break; 675 break;
676 case MAILIMAP_BODY_FLD_ENC_BASE64: 676 case MAILIMAP_BODY_FLD_ENC_BASE64:
677 encoding="base64"; 677 encoding="base64";
678 break; 678 break;
679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
680 encoding="quoted-printable"; 680 encoding="quoted-printable";
681 break; 681 break;
682 case MAILIMAP_BODY_FLD_ENC_OTHER: 682 case MAILIMAP_BODY_FLD_ENC_OTHER:
683 default: 683 default:
684 if (enc->enc_value) { 684 if (enc->enc_value) {
685 char*t=enc->enc_value; 685 char*t=enc->enc_value;
686 encoding=QString(enc->enc_value); 686 encoding=QString(enc->enc_value);
687 enc->enc_value=0L; 687 enc->enc_value=0L;
688 free(t); 688 free(t);
689 } 689 }
690 } 690 }
691 target_part.setEncoding(encoding); 691 target_part.setEncoding(encoding);
692 target_part.setSize(which->bd_size); 692 target_part.setSize(which->bd_size);
693} 693}
694 694
695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
696{ 696{
697 return fetchPart(mail,part.Positionlist(),false); 697 return fetchPart(mail,part.Positionlist(),false);
698} 698}
699
700void IMAPwrapper::deleteMail(const RecMail&mail)
701{
702 mailimap_flag_list*flist;
703 mailimap_set *set;
704 mailimap_store_att_flags * store_flags;
705 int err;
706 login();
707 if (!m_imap) {
708 return;
709 }
710 const char *mb = mail.getMbox().latin1();
711 err = mailimap_select( m_imap, (char*)mb);
712 if ( err != MAILIMAP_NO_ERROR ) {
713 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
714 return;
715 }
716 flist = mailimap_flag_list_new_empty();
717 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
718 store_flags = mailimap_store_att_flags_new_set_flags(flist);
719 set = mailimap_set_new_single(mail.getNumber());
720 err = mailimap_store(m_imap,set,store_flags);
721 if (err != MAILIMAP_NO_ERROR) {
722 qDebug("error deleting mail: %s",m_imap->imap_response);
723 return;
724 }
725 err = mailimap_expunge(m_imap);
726 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response);
728 }
729 qDebug("Delete successfull");
730}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index f88457a..4f4d575 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,52 +1,55 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16 16
17class IMAPwrapper : public AbstractMail 17class IMAPwrapper : public AbstractMail
18{ 18{
19 Q_OBJECT 19 Q_OBJECT
20public: 20public:
21 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 23 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
26 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
27 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail);
28
28 static void imap_progress( size_t current, size_t maximum ); 29 static void imap_progress( size_t current, size_t maximum );
29 30
30protected: 31protected:
31 RecMail*parse_list_result(mailimap_msg_att*); 32 RecMail*parse_list_result(mailimap_msg_att*);
32 void login(); 33 void login();
33 void logout(); 34 void logout();
35
36 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
34 37
35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 38 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 39 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
37 40
38 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 41 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
39 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 42 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
40 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 43 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
41 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 44 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
42 45
43 /* just helpers */ 46 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 47 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
45 static QStringList address_list_to_stringlist(clist*list); 48 static QStringList address_list_to_stringlist(clist*list);
46 49
47private: 50private:
48 IMAPaccount *account; 51 IMAPaccount *account;
49 mailimap *m_imap; 52 mailimap *m_imap;
50}; 53};
51 54
52#endif 55#endif
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index bc8938f..0a1719d 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -1,30 +1,30 @@
1#ifndef __abstract_mail_ 1#ifndef __abstract_mail_
2#define __abstract_mail_ 2#define __abstract_mail_
3 3
4#include <qobject.h> 4#include <qobject.h>
5#include "settings.h" 5#include "settings.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9class RecPart; 9class RecPart;
10class IMAPwrapper; 10class IMAPwrapper;
11class POP3wrapper; 11class POP3wrapper;
12class Folder; 12class Folder;
13 13
14class AbstractMail:public QObject 14class AbstractMail:public QObject
15{ 15{
16 Q_OBJECT 16 Q_OBJECT
17public: 17public:
18 AbstractMail(){}; 18 AbstractMail(){};
19 virtual ~AbstractMail(){} 19 virtual ~AbstractMail(){}
20 virtual QList<Folder>* listFolders()=0; 20 virtual QList<Folder>* listFolders()=0;
21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; 21 virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
22 virtual RecBody fetchBody(const RecMail&mail)=0; 22 virtual RecBody fetchBody(const RecMail&mail)=0;
23 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false)=0;
24 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0; 23 virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
24 virtual void deleteMail(const RecMail&mail)=0;
25 25
26 static AbstractMail* getWrapper(IMAPaccount *a); 26 static AbstractMail* getWrapper(IMAPaccount *a);
27 static AbstractMail* getWrapper(POP3account *a); 27 static AbstractMail* getWrapper(POP3account *a);
28}; 28};
29 29
30#endif 30#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3222c7e..a01a2a9 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -443,256 +443,288 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
443 if (++count > 99) { 443 if (++count > 99) {
444 break; 444 break;
445 } 445 }
446 } 446 }
447 return l; 447 return l;
448} 448}
449 449
450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 450QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
451{ 451{
452 QString body(""); 452 QString body("");
453 const char*mb; 453 const char*mb;
454 int err; 454 int err;
455 mailimap_fetch_type *fetchType; 455 mailimap_fetch_type *fetchType;
456 mailimap_set *set; 456 mailimap_set *set;
457 clistcell*current,*cur; 457 clistcell*current,*cur;
458 458
459 login(); 459 login();
460 if (!m_imap) { 460 if (!m_imap) {
461 return body; 461 return body;
462 } 462 }
463 if (!internal_call) { 463 if (!internal_call) {
464 mb = mail.getMbox().latin1(); 464 mb = mail.getMbox().latin1();
465 err = mailimap_select( m_imap, (char*)mb); 465 err = mailimap_select( m_imap, (char*)mb);
466 if ( err != MAILIMAP_NO_ERROR ) { 466 if ( err != MAILIMAP_NO_ERROR ) {
467 qDebug("error selecting mailbox: %s",m_imap->imap_response); 467 qDebug("error selecting mailbox: %s",m_imap->imap_response);
468 return body; 468 return body;
469 } 469 }
470 } 470 }
471 set = mailimap_set_new_single(mail.getNumber()); 471 set = mailimap_set_new_single(mail.getNumber());
472 clist*id_list=clist_new(); 472 clist*id_list=clist_new();
473 for (unsigned j=0; j < path.count();++j) { 473 for (unsigned j=0; j < path.count();++j) {
474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 474 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
475 *p_id = path[j]; 475 *p_id = path[j];
476 clist_append(id_list,p_id); 476 clist_append(id_list,p_id);
477 } 477 }
478 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 478 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 479 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
480 mailimap_section * section = mailimap_section_new(section_spec); 480 mailimap_section * section = mailimap_section_new(section_spec);
481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 481 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
482 482
483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 483 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
484 484
485 clist*result = clist_new(); 485 clist*result = clist_new();
486 486
487 err = mailimap_fetch( m_imap, set, fetchType, &result ); 487 err = mailimap_fetch( m_imap, set, fetchType, &result );
488 mailimap_set_free( set ); 488 mailimap_set_free( set );
489 mailimap_fetch_type_free( fetchType ); 489 mailimap_fetch_type_free( fetchType );
490 490
491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 491 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
492 mailimap_msg_att * msg_att; 492 mailimap_msg_att * msg_att;
493 msg_att = (mailimap_msg_att*)current->data; 493 msg_att = (mailimap_msg_att*)current->data;
494 mailimap_msg_att_item*msg_att_item; 494 mailimap_msg_att_item*msg_att_item;
495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 495 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 496 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 497 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 498 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 499 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 500 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
501 if (text) { 501 if (text) {
502 body = QString(text); 502 body = QString(text);
503 free(text); 503 free(text);
504 } else { 504 } else {
505 body = ""; 505 body = "";
506 } 506 }
507 } 507 }
508 } 508 }
509 } 509 }
510 510
511 } else { 511 } else {
512 qDebug("error fetching text: %s",m_imap->imap_response); 512 qDebug("error fetching text: %s",m_imap->imap_response);
513 } 513 }
514 mailimap_fetch_list_free(result); 514 mailimap_fetch_list_free(result);
515 return body; 515 return body;
516} 516}
517 517
518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList) 518void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
519{ 519{
520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */ 520 /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
521 if (!mailDescription||current_recursion==10) { 521 if (!mailDescription||current_recursion==10) {
522 return; 522 return;
523 } 523 }
524 clistcell*current; 524 clistcell*current;
525 mailimap_body*current_body; 525 mailimap_body*current_body;
526 unsigned int count = 0; 526 unsigned int count = 0;
527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { 527 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
528 /* the point in the message */ 528 /* the point in the message */
529 ++count; 529 ++count;
530 current_body = (mailimap_body*)current->data; 530 current_body = (mailimap_body*)current->data;
531 if (current_body->bd_type==MAILIMAP_BODY_MPART) { 531 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
532 QValueList<int>clist = recList; 532 QValueList<int>clist = recList;
533 clist.append(count); 533 clist.append(count);
534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); 534 searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist);
535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 535 } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
536 RecPart currentPart; 536 RecPart currentPart;
537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part); 537 fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
538 QValueList<int>clist = recList; 538 QValueList<int>clist = recList;
539 clist.append(count); 539 clist.append(count);
540 /* important: Check for is NULL 'cause a body can be empty! */ 540 /* important: Check for is NULL 'cause a body can be empty! */
541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) { 541 if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
542 QString body_text = fetchPart(mail,clist,true); 542 QString body_text = fetchPart(mail,clist,true);
543 target_body.setDescription(currentPart); 543 target_body.setDescription(currentPart);
544 target_body.setBodytext(body_text); 544 target_body.setBodytext(body_text);
545 } else { 545 } else {
546 QString id(""); 546 QString id("");
547 for (unsigned int j = 0; j < clist.count();++j) { 547 for (unsigned int j = 0; j < clist.count();++j) {
548 id+=(j>0?" ":""); 548 id+=(j>0?" ":"");
549 id+=QString("%1").arg(clist[j]); 549 id+=QString("%1").arg(clist[j]);
550 } 550 }
551 qDebug("ID= %s",id.latin1()); 551 qDebug("ID= %s",id.latin1());
552 currentPart.setIdentifier(id); 552 currentPart.setIdentifier(id);
553 currentPart.setPositionlist(clist); 553 currentPart.setPositionlist(clist);
554 target_body.addPart(currentPart); 554 target_body.addPart(currentPart);
555 } 555 }
556 } 556 }
557 } 557 }
558} 558}
559 559
560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 560void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
561{ 561{
562 if (!Description) { 562 if (!Description) {
563 return; 563 return;
564 } 564 }
565 switch (Description->bd_type) { 565 switch (Description->bd_type) {
566 case MAILIMAP_BODY_TYPE_1PART_TEXT: 566 case MAILIMAP_BODY_TYPE_1PART_TEXT:
567 target_part.setType("text"); 567 target_part.setType("text");
568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 568 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
569 break; 569 break;
570 case MAILIMAP_BODY_TYPE_1PART_BASIC: 570 case MAILIMAP_BODY_TYPE_1PART_BASIC:
571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 571 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
572 break; 572 break;
573 case MAILIMAP_BODY_TYPE_1PART_MSG: 573 case MAILIMAP_BODY_TYPE_1PART_MSG:
574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 574 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
575 break; 575 break;
576 default: 576 default:
577 break; 577 break;
578 } 578 }
579} 579}
580 580
581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 581void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
582{ 582{
583 if (!which) { 583 if (!which) {
584 return; 584 return;
585 } 585 }
586 QString sub; 586 QString sub;
587 sub = which->bd_media_text; 587 sub = which->bd_media_text;
588 target_part.setSubtype(sub.lower()); 588 target_part.setSubtype(sub.lower());
589 target_part.setLines(which->bd_lines); 589 target_part.setLines(which->bd_lines);
590 fillBodyFields(target_part,which->bd_fields); 590 fillBodyFields(target_part,which->bd_fields);
591} 591}
592 592
593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 593void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
594{ 594{
595 if (!which) { 595 if (!which) {
596 return; 596 return;
597 } 597 }
598// QString sub; 598// QString sub;
599// sub = which->bd_media_text; 599// sub = which->bd_media_text;
600// target_part.setSubtype(sub.lower()); 600// target_part.setSubtype(sub.lower());
601 qDebug("Message part"); 601 qDebug("Message part");
602 /* we set this type to text/plain */ 602 /* we set this type to text/plain */
603 target_part.setType("text"); 603 target_part.setType("text");
604 target_part.setSubtype("plain"); 604 target_part.setSubtype("plain");
605 target_part.setLines(which->bd_lines); 605 target_part.setLines(which->bd_lines);
606 fillBodyFields(target_part,which->bd_fields); 606 fillBodyFields(target_part,which->bd_fields);
607} 607}
608 608
609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 609void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
610{ 610{
611 if (!which) { 611 if (!which) {
612 return; 612 return;
613 } 613 }
614 QString type,sub; 614 QString type,sub;
615 switch (which->bd_media_basic->med_type) { 615 switch (which->bd_media_basic->med_type) {
616 case MAILIMAP_MEDIA_BASIC_APPLICATION: 616 case MAILIMAP_MEDIA_BASIC_APPLICATION:
617 type = "application"; 617 type = "application";
618 break; 618 break;
619 case MAILIMAP_MEDIA_BASIC_AUDIO: 619 case MAILIMAP_MEDIA_BASIC_AUDIO:
620 type = "audio"; 620 type = "audio";
621 break; 621 break;
622 case MAILIMAP_MEDIA_BASIC_IMAGE: 622 case MAILIMAP_MEDIA_BASIC_IMAGE:
623 type = "image"; 623 type = "image";
624 break; 624 break;
625 case MAILIMAP_MEDIA_BASIC_MESSAGE: 625 case MAILIMAP_MEDIA_BASIC_MESSAGE:
626 type = "message"; 626 type = "message";
627 break; 627 break;
628 case MAILIMAP_MEDIA_BASIC_VIDEO: 628 case MAILIMAP_MEDIA_BASIC_VIDEO:
629 type = "video"; 629 type = "video";
630 break; 630 break;
631 case MAILIMAP_MEDIA_BASIC_OTHER: 631 case MAILIMAP_MEDIA_BASIC_OTHER:
632 default: 632 default:
633 if (which->bd_media_basic->med_basic_type) { 633 if (which->bd_media_basic->med_basic_type) {
634 type = which->bd_media_basic->med_basic_type; 634 type = which->bd_media_basic->med_basic_type;
635 } else { 635 } else {
636 type = ""; 636 type = "";
637 } 637 }
638 break; 638 break;
639 } 639 }
640 if (which->bd_media_basic->med_subtype) { 640 if (which->bd_media_basic->med_subtype) {
641 sub = which->bd_media_basic->med_subtype; 641 sub = which->bd_media_basic->med_subtype;
642 } else { 642 } else {
643 sub = ""; 643 sub = "";
644 } 644 }
645 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 645 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
646 target_part.setType(type.lower()); 646 target_part.setType(type.lower());
647 target_part.setSubtype(sub.lower()); 647 target_part.setSubtype(sub.lower());
648 fillBodyFields(target_part,which->bd_fields); 648 fillBodyFields(target_part,which->bd_fields);
649} 649}
650 650
651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 651void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
652{ 652{
653 if (!which) return; 653 if (!which) return;
654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 654 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
655 clistcell*cur; 655 clistcell*cur;
656 mailimap_single_body_fld_param*param=0; 656 mailimap_single_body_fld_param*param=0;
657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 657 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
658 param = (mailimap_single_body_fld_param*)cur->data; 658 param = (mailimap_single_body_fld_param*)cur->data;
659 if (param) { 659 if (param) {
660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 660 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
661 } 661 }
662 } 662 }
663 } 663 }
664 mailimap_body_fld_enc*enc = which->bd_encoding; 664 mailimap_body_fld_enc*enc = which->bd_encoding;
665 QString encoding(""); 665 QString encoding("");
666 switch (enc->enc_type) { 666 switch (enc->enc_type) {
667 case MAILIMAP_BODY_FLD_ENC_7BIT: 667 case MAILIMAP_BODY_FLD_ENC_7BIT:
668 encoding = "7bit"; 668 encoding = "7bit";
669 break; 669 break;
670 case MAILIMAP_BODY_FLD_ENC_8BIT: 670 case MAILIMAP_BODY_FLD_ENC_8BIT:
671 encoding = "8bit"; 671 encoding = "8bit";
672 break; 672 break;
673 case MAILIMAP_BODY_FLD_ENC_BINARY: 673 case MAILIMAP_BODY_FLD_ENC_BINARY:
674 encoding="binary"; 674 encoding="binary";
675 break; 675 break;
676 case MAILIMAP_BODY_FLD_ENC_BASE64: 676 case MAILIMAP_BODY_FLD_ENC_BASE64:
677 encoding="base64"; 677 encoding="base64";
678 break; 678 break;
679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 679 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
680 encoding="quoted-printable"; 680 encoding="quoted-printable";
681 break; 681 break;
682 case MAILIMAP_BODY_FLD_ENC_OTHER: 682 case MAILIMAP_BODY_FLD_ENC_OTHER:
683 default: 683 default:
684 if (enc->enc_value) { 684 if (enc->enc_value) {
685 char*t=enc->enc_value; 685 char*t=enc->enc_value;
686 encoding=QString(enc->enc_value); 686 encoding=QString(enc->enc_value);
687 enc->enc_value=0L; 687 enc->enc_value=0L;
688 free(t); 688 free(t);
689 } 689 }
690 } 690 }
691 target_part.setEncoding(encoding); 691 target_part.setEncoding(encoding);
692 target_part.setSize(which->bd_size); 692 target_part.setSize(which->bd_size);
693} 693}
694 694
695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part) 695QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
696{ 696{
697 return fetchPart(mail,part.Positionlist(),false); 697 return fetchPart(mail,part.Positionlist(),false);
698} 698}
699
700void IMAPwrapper::deleteMail(const RecMail&mail)
701{
702 mailimap_flag_list*flist;
703 mailimap_set *set;
704 mailimap_store_att_flags * store_flags;
705 int err;
706 login();
707 if (!m_imap) {
708 return;
709 }
710 const char *mb = mail.getMbox().latin1();
711 err = mailimap_select( m_imap, (char*)mb);
712 if ( err != MAILIMAP_NO_ERROR ) {
713 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
714 return;
715 }
716 flist = mailimap_flag_list_new_empty();
717 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
718 store_flags = mailimap_store_att_flags_new_set_flags(flist);
719 set = mailimap_set_new_single(mail.getNumber());
720 err = mailimap_store(m_imap,set,store_flags);
721 if (err != MAILIMAP_NO_ERROR) {
722 qDebug("error deleting mail: %s",m_imap->imap_response);
723 return;
724 }
725 err = mailimap_expunge(m_imap);
726 if (err != MAILIMAP_NO_ERROR) {
727 qDebug("error deleting mail: %s",m_imap->imap_response);
728 }
729 qDebug("Delete successfull");
730}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index f88457a..4f4d575 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,52 +1,55 @@
1#ifndef __IMAPWRAPPER 1#ifndef __IMAPWRAPPER
2#define __IMAPWRAPPER 2#define __IMAPWRAPPER
3 3
4#include <qlist.h> 4#include <qlist.h>
5#include "mailwrapper.h" 5#include "mailwrapper.h"
6#include "abstractmail.h" 6#include "abstractmail.h"
7 7
8struct mailimap; 8struct mailimap;
9struct mailimap_body_type_1part; 9struct mailimap_body_type_1part;
10struct mailimap_body_type_text; 10struct mailimap_body_type_text;
11struct mailimap_body_type_basic; 11struct mailimap_body_type_basic;
12struct mailimap_body_type_msg; 12struct mailimap_body_type_msg;
13struct mailimap_body_type_mpart; 13struct mailimap_body_type_mpart;
14struct mailimap_body_fields; 14struct mailimap_body_fields;
15struct mailimap_msg_att; 15struct mailimap_msg_att;
16 16
17class IMAPwrapper : public AbstractMail 17class IMAPwrapper : public AbstractMail
18{ 18{
19 Q_OBJECT 19 Q_OBJECT
20public: 20public:
21 IMAPwrapper( IMAPaccount *a ); 21 IMAPwrapper( IMAPaccount *a );
22 virtual ~IMAPwrapper(); 22 virtual ~IMAPwrapper();
23 virtual QList<Folder>* listFolders(); 23 virtual QList<Folder>* listFolders();
24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 24 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
25 virtual RecBody fetchBody(const RecMail&mail); 25 virtual RecBody fetchBody(const RecMail&mail);
26 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
27 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 26 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
27 virtual void deleteMail(const RecMail&mail);
28
28 static void imap_progress( size_t current, size_t maximum ); 29 static void imap_progress( size_t current, size_t maximum );
29 30
30protected: 31protected:
31 RecMail*parse_list_result(mailimap_msg_att*); 32 RecMail*parse_list_result(mailimap_msg_att*);
32 void login(); 33 void login();
33 void logout(); 34 void logout();
35
36 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
34 37
35 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body); 38 void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
36 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>()); 39 void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
37 40
38 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 41 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
39 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 42 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
40 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 43 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
41 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); 44 void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which);
42 45
43 /* just helpers */ 46 /* just helpers */
44 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 47 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
45 static QStringList address_list_to_stringlist(clist*list); 48 static QStringList address_list_to_stringlist(clist*list);
46 49
47private: 50private:
48 IMAPaccount *account; 51 IMAPaccount *account;
49 mailimap *m_imap; 52 mailimap *m_imap;
50}; 53};
51 54
52#endif 55#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 903ef4d..62523bf 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -26,265 +26,264 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
26 size_t length; 26 size_t length;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this); 84 mail->setWrapper(this);
85 target.append( mail ); 85 target.append( mail );
86 } 86 }
87 87
88 logout(); 88 logout();
89} 89}
90 90
91RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
92{ 92{
93 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
94 size_t curTok; 94 size_t curTok;
95 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
96 mailimf_fields *fields; 96 mailimf_fields *fields;
97 97
98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
100 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
101 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
102 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
104 break; 104 break;
105 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
107 break; 107 break;
108 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
110 break; 110 break;
111 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
113 break; 113 break;
114 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
116 break; 116 break;
117 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
119 break; 119 break;
120 default: 120 default:
121 break; 121 break;
122 } 122 }
123 } 123 }
124 124
125 return mail; 125 return mail;
126} 126}
127 127
128QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
129{ 129{
130 char tmp[23]; 130 char tmp[23];
131 131
132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
134 134
135 return QString( tmp ); 135 return QString( tmp );
136} 136}
137 137
138QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
139{ 139{
140 QString result( "" ); 140 QString result( "" );
141 141
142 bool first = true; 142 bool first = true;
143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
144 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
145 145
146 if ( !first ) { 146 if ( !first ) {
147 result.append( "," ); 147 result.append( "," );
148 } else { 148 } else {
149 first = false; 149 first = false;
150 } 150 }
151 151
152 switch ( addr->ad_type ) { 152 switch ( addr->ad_type ) {
153 case MAILIMF_ADDRESS_MAILBOX: 153 case MAILIMF_ADDRESS_MAILBOX:
154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
155 break; 155 break;
156 case MAILIMF_ADDRESS_GROUP: 156 case MAILIMF_ADDRESS_GROUP:
157 result.append( parseGroup( addr->ad_data.ad_group ) ); 157 result.append( parseGroup( addr->ad_data.ad_group ) );
158 break; 158 break;
159 default: 159 default:
160 qDebug( "POP3: unkown mailimf address type" ); 160 qDebug( "POP3: unkown mailimf address type" );
161 break; 161 break;
162 } 162 }
163 } 163 }
164 164
165 return result; 165 return result;
166} 166}
167 167
168QString POP3wrapper::parseGroup( mailimf_group *group ) 168QString POP3wrapper::parseGroup( mailimf_group *group )
169{ 169{
170 QString result( "" ); 170 QString result( "" );
171 171
172 result.append( group->grp_display_name ); 172 result.append( group->grp_display_name );
173 result.append( ": " ); 173 result.append( ": " );
174 174
175 if ( group->grp_mb_list != NULL ) { 175 if ( group->grp_mb_list != NULL ) {
176 result.append( parseMailboxList( group->grp_mb_list ) ); 176 result.append( parseMailboxList( group->grp_mb_list ) );
177 } 177 }
178 178
179 result.append( ";" ); 179 result.append( ";" );
180 180
181 return result; 181 return result;
182} 182}
183 183
184QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 184QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
185{ 185{
186 QString result( "" ); 186 QString result( "" );
187 187
188 if ( box->mb_display_name == NULL ) { 188 if ( box->mb_display_name == NULL ) {
189 result.append( box->mb_addr_spec ); 189 result.append( box->mb_addr_spec );
190 } else { 190 } else {
191 result.append( box->mb_display_name ); 191 result.append( box->mb_display_name );
192 result.append( " <" ); 192 result.append( " <" );
193 result.append( box->mb_addr_spec ); 193 result.append( box->mb_addr_spec );
194 result.append( ">" ); 194 result.append( ">" );
195 } 195 }
196 196
197 return result; 197 return result;
198} 198}
199 199
200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
201{ 201{
202 QString result( "" ); 202 QString result( "" );
203 203
204 bool first = true; 204 bool first = true;
205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
206 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 206 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
207 207
208 if ( !first ) { 208 if ( !first ) {
209 result.append( "," ); 209 result.append( "," );
210 } else { 210 } else {
211 first = false; 211 first = false;
212 } 212 }
213 213
214 result.append( parseMailbox( box ) ); 214 result.append( parseMailbox( box ) );
215 } 215 }
216 216
217 return result; 217 return result;
218} 218}
219 219
220void POP3wrapper::login() 220void POP3wrapper::login()
221{ 221{
222 if ( m_pop3 != NULL ) logout(); 222 if ( m_pop3 != NULL ) logout();
223 223
224 const char *server, *user, *pass; 224 const char *server, *user, *pass;
225 uint16_t port; 225 uint16_t port;
226 int err = MAILPOP3_NO_ERROR; 226 int err = MAILPOP3_NO_ERROR;
227 227
228 server = account->getServer().latin1(); 228 server = account->getServer().latin1();
229 port = account->getPort().toUInt(); 229 port = account->getPort().toUInt();
230 user = account->getUser().latin1(); 230 user = account->getUser().latin1();
231 pass = account->getPassword().latin1(); 231 pass = account->getPassword().latin1();
232 232
233 m_pop3 = mailpop3_new( 200, &pop3_progress ); 233 m_pop3 = mailpop3_new( 200, &pop3_progress );
234 234
235 // connect 235 // connect
236 if (account->getSSL()) { 236 if (account->getSSL()) {
237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
238 } else { 238 } else {
239 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 239 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
240 } 240 }
241 241
242 if ( err != MAILPOP3_NO_ERROR ) { 242 if ( err != MAILPOP3_NO_ERROR ) {
243 qDebug( "pop3: error connecting to %s\n reason: %s", server, 243 qDebug( "pop3: error connecting to %s\n reason: %s", server,
244 m_pop3->pop3_response ); 244 m_pop3->pop3_response );
245 mailpop3_free( m_pop3 ); 245 mailpop3_free( m_pop3 );
246 m_pop3 = NULL; 246 m_pop3 = NULL;
247 return; 247 return;
248 } 248 }
249 qDebug( "POP3: connected!" ); 249 qDebug( "POP3: connected!" );
250 250
251 // login 251 // login
252 // TODO: decide if apop or plain login should be used 252 // TODO: decide if apop or plain login should be used
253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
254 if ( err != MAILPOP3_NO_ERROR ) { 254 if ( err != MAILPOP3_NO_ERROR ) {
255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
256 logout(); 256 logout();
257 return; 257 return;
258 } 258 }
259 259
260 qDebug( "POP3: logged in!" ); 260 qDebug( "POP3: logged in!" );
261} 261}
262 262
263void POP3wrapper::logout() 263void POP3wrapper::logout()
264{ 264{
265 int err = MAILPOP3_NO_ERROR; 265 int err = MAILPOP3_NO_ERROR;
266 if ( m_pop3 == NULL ) return; 266 if ( m_pop3 == NULL ) return;
267 err = mailpop3_quit( m_pop3 ); 267 err = mailpop3_quit( m_pop3 );
268 mailpop3_free( m_pop3 ); 268 mailpop3_free( m_pop3 );
269 m_pop3 = NULL; 269 m_pop3 = NULL;
270} 270}
271 271
272 272
273QList<Folder>* POP3wrapper::listFolders() 273QList<Folder>* POP3wrapper::listFolders()
274{ 274{
275 QList<Folder> * folders = new QList<Folder>(); 275 QList<Folder> * folders = new QList<Folder>();
276 folders->setAutoDelete( true ); 276 folders->setAutoDelete( true );
277 Folder*inb=new Folder("INBOX"); 277 Folder*inb=new Folder("INBOX");
278 folders->append(inb); 278 folders->append(inb);
279 return folders; 279 return folders;
280} 280}
281 281
282QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) 282QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
283{ 283{
284 return ""; 284 return "";
285} 285}
286 286
287QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 287void POP3wrapper::deleteMail(const RecMail&)
288{ 288{
289 return "";
290} 289}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 3b24564..ef972c8 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,43 +1,43 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h" 5#include "abstractmail.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9struct mailpop3; 9struct mailpop3;
10 10
11class POP3wrapper : public AbstractMail 11class POP3wrapper : public AbstractMail
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
22 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 21 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
22 virtual void deleteMail(const RecMail&mail);
23 23
24 RecBody fetchBody( const RecMail &mail ); 24 RecBody fetchBody( const RecMail &mail );
25 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );
26 26
27protected: 27protected:
28 void login(); 28 void login();
29 void logout(); 29 void logout();
30 30
31private: 31private:
32 RecMail *parseHeader( const char *header ); 32 RecMail *parseHeader( const char *header );
33 RecBody parseBody( const char *message ); 33 RecBody parseBody( const char *message );
34 QString parseMailboxList( mailimf_mailbox_list *list ); 34 QString parseMailboxList( mailimf_mailbox_list *list );
35 QString parseMailbox( mailimf_mailbox *box ); 35 QString parseMailbox( mailimf_mailbox *box );
36 QString parseGroup( mailimf_group *group ); 36 QString parseGroup( mailimf_group *group );
37 QString parseAddressList( mailimf_address_list *list ); 37 QString parseAddressList( mailimf_address_list *list );
38 QString parseDateTime( mailimf_date_time *date ); 38 QString parseDateTime( mailimf_date_time *date );
39 POP3account *account; 39 POP3account *account;
40 mailpop3 *m_pop3; 40 mailpop3 *m_pop3;
41}; 41};
42 42
43#endif 43#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 903ef4d..62523bf 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -26,265 +26,264 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail )
26 size_t length; 26 size_t length;
27 27
28 login(); 28 login();
29 if ( !m_pop3 ) return RecBody(); 29 if ( !m_pop3 ) return RecBody();
30 30
31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); 31 err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
32 if ( err != MAILPOP3_NO_ERROR ) { 32 if ( err != MAILPOP3_NO_ERROR ) {
33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); 33 qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
34 logout(); 34 logout();
35 return RecBody(); 35 return RecBody();
36 } 36 }
37 37
38 logout(); 38 logout();
39 39
40 return parseBody( message ); 40 return parseBody( message );
41} 41}
42 42
43RecBody POP3wrapper::parseBody( const char *message ) 43RecBody POP3wrapper::parseBody( const char *message )
44{ 44{
45 int err = MAILIMF_NO_ERROR; 45 int err = MAILIMF_NO_ERROR;
46 size_t curTok; 46 size_t curTok;
47 mailimf_message *result; 47 mailimf_message *result;
48 RecBody body; 48 RecBody body;
49 49
50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); 50 err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result );
51 if ( err != MAILIMF_NO_ERROR ) return body; 51 if ( err != MAILIMF_NO_ERROR ) return body;
52 52
53 if ( result && result->msg_body && result->msg_body->bd_text ) { 53 if ( result && result->msg_body && result->msg_body->bd_text ) {
54 qDebug( "POP3: bodytext found" ); 54 qDebug( "POP3: bodytext found" );
55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan. 55 // TODO: why does this line segfault???? gdb says segfault in strlen(), maybe a bug in libetpan.
56 body.setBodytext( QString( result->msg_body->bd_text ) ); 56 body.setBodytext( QString( result->msg_body->bd_text ) );
57 } 57 }
58 58
59 return body; 59 return body;
60} 60}
61 61
62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 62void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
63{ 63{
64 int err = MAILPOP3_NO_ERROR; 64 int err = MAILPOP3_NO_ERROR;
65 char *header; 65 char *header;
66 size_t length; 66 size_t length;
67 carray *messages; 67 carray *messages;
68 68
69 login(); 69 login();
70 if (!m_pop3) return; 70 if (!m_pop3) return;
71 mailpop3_list( m_pop3, &messages ); 71 mailpop3_list( m_pop3, &messages );
72 72
73 for ( int i = carray_count( messages ); i > 0; i-- ) { 73 for ( int i = carray_count( messages ); i > 0; i-- ) {
74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 ); 74 mailpop3_msg_info *info = (mailpop3_msg_info *) carray_get( messages, i - 1 );
75 75
76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); 76 err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
77 if ( err != MAILPOP3_NO_ERROR ) { 77 if ( err != MAILPOP3_NO_ERROR ) {
78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); 78 qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
79 logout(); 79 logout();
80 return; 80 return;
81 } 81 }
82 RecMail *mail = parseHeader( header ); 82 RecMail *mail = parseHeader( header );
83 mail->setNumber( info->msg_index ); 83 mail->setNumber( info->msg_index );
84 mail->setWrapper(this); 84 mail->setWrapper(this);
85 target.append( mail ); 85 target.append( mail );
86 } 86 }
87 87
88 logout(); 88 logout();
89} 89}
90 90
91RecMail *POP3wrapper::parseHeader( const char *header ) 91RecMail *POP3wrapper::parseHeader( const char *header )
92{ 92{
93 int err = MAILIMF_NO_ERROR; 93 int err = MAILIMF_NO_ERROR;
94 size_t curTok; 94 size_t curTok;
95 RecMail *mail = new RecMail(); 95 RecMail *mail = new RecMail();
96 mailimf_fields *fields; 96 mailimf_fields *fields;
97 97
98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); 98 err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields );
99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { 99 for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) {
100 mailimf_field *field = (mailimf_field *) current->data; 100 mailimf_field *field = (mailimf_field *) current->data;
101 switch ( field->fld_type ) { 101 switch ( field->fld_type ) {
102 case MAILIMF_FIELD_FROM: 102 case MAILIMF_FIELD_FROM:
103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); 103 mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) );
104 break; 104 break;
105 case MAILIMF_FIELD_TO: 105 case MAILIMF_FIELD_TO:
106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); 106 mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) );
107 break; 107 break;
108 case MAILIMF_FIELD_CC: 108 case MAILIMF_FIELD_CC:
109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); 109 mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) );
110 break; 110 break;
111 case MAILIMF_FIELD_BCC: 111 case MAILIMF_FIELD_BCC:
112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); 112 mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) );
113 break; 113 break;
114 case MAILIMF_FIELD_SUBJECT: 114 case MAILIMF_FIELD_SUBJECT:
115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) ); 115 mail->setSubject( QString( field->fld_data.fld_subject->sbj_value ) );
116 break; 116 break;
117 case MAILIMF_FIELD_ORIG_DATE: 117 case MAILIMF_FIELD_ORIG_DATE:
118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); 118 mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) );
119 break; 119 break;
120 default: 120 default:
121 break; 121 break;
122 } 122 }
123 } 123 }
124 124
125 return mail; 125 return mail;
126} 126}
127 127
128QString POP3wrapper::parseDateTime( mailimf_date_time *date ) 128QString POP3wrapper::parseDateTime( mailimf_date_time *date )
129{ 129{
130 char tmp[23]; 130 char tmp[23];
131 131
132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", 132 snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); 133 date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
134 134
135 return QString( tmp ); 135 return QString( tmp );
136} 136}
137 137
138QString POP3wrapper::parseAddressList( mailimf_address_list *list ) 138QString POP3wrapper::parseAddressList( mailimf_address_list *list )
139{ 139{
140 QString result( "" ); 140 QString result( "" );
141 141
142 bool first = true; 142 bool first = true;
143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { 143 for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) {
144 mailimf_address *addr = (mailimf_address *) current->data; 144 mailimf_address *addr = (mailimf_address *) current->data;
145 145
146 if ( !first ) { 146 if ( !first ) {
147 result.append( "," ); 147 result.append( "," );
148 } else { 148 } else {
149 first = false; 149 first = false;
150 } 150 }
151 151
152 switch ( addr->ad_type ) { 152 switch ( addr->ad_type ) {
153 case MAILIMF_ADDRESS_MAILBOX: 153 case MAILIMF_ADDRESS_MAILBOX:
154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); 154 result.append( parseMailbox( addr->ad_data.ad_mailbox ) );
155 break; 155 break;
156 case MAILIMF_ADDRESS_GROUP: 156 case MAILIMF_ADDRESS_GROUP:
157 result.append( parseGroup( addr->ad_data.ad_group ) ); 157 result.append( parseGroup( addr->ad_data.ad_group ) );
158 break; 158 break;
159 default: 159 default:
160 qDebug( "POP3: unkown mailimf address type" ); 160 qDebug( "POP3: unkown mailimf address type" );
161 break; 161 break;
162 } 162 }
163 } 163 }
164 164
165 return result; 165 return result;
166} 166}
167 167
168QString POP3wrapper::parseGroup( mailimf_group *group ) 168QString POP3wrapper::parseGroup( mailimf_group *group )
169{ 169{
170 QString result( "" ); 170 QString result( "" );
171 171
172 result.append( group->grp_display_name ); 172 result.append( group->grp_display_name );
173 result.append( ": " ); 173 result.append( ": " );
174 174
175 if ( group->grp_mb_list != NULL ) { 175 if ( group->grp_mb_list != NULL ) {
176 result.append( parseMailboxList( group->grp_mb_list ) ); 176 result.append( parseMailboxList( group->grp_mb_list ) );
177 } 177 }
178 178
179 result.append( ";" ); 179 result.append( ";" );
180 180
181 return result; 181 return result;
182} 182}
183 183
184QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) 184QString POP3wrapper::parseMailbox( mailimf_mailbox *box )
185{ 185{
186 QString result( "" ); 186 QString result( "" );
187 187
188 if ( box->mb_display_name == NULL ) { 188 if ( box->mb_display_name == NULL ) {
189 result.append( box->mb_addr_spec ); 189 result.append( box->mb_addr_spec );
190 } else { 190 } else {
191 result.append( box->mb_display_name ); 191 result.append( box->mb_display_name );
192 result.append( " <" ); 192 result.append( " <" );
193 result.append( box->mb_addr_spec ); 193 result.append( box->mb_addr_spec );
194 result.append( ">" ); 194 result.append( ">" );
195 } 195 }
196 196
197 return result; 197 return result;
198} 198}
199 199
200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) 200QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list )
201{ 201{
202 QString result( "" ); 202 QString result( "" );
203 203
204 bool first = true; 204 bool first = true;
205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { 205 for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) {
206 mailimf_mailbox *box = (mailimf_mailbox *) current->data; 206 mailimf_mailbox *box = (mailimf_mailbox *) current->data;
207 207
208 if ( !first ) { 208 if ( !first ) {
209 result.append( "," ); 209 result.append( "," );
210 } else { 210 } else {
211 first = false; 211 first = false;
212 } 212 }
213 213
214 result.append( parseMailbox( box ) ); 214 result.append( parseMailbox( box ) );
215 } 215 }
216 216
217 return result; 217 return result;
218} 218}
219 219
220void POP3wrapper::login() 220void POP3wrapper::login()
221{ 221{
222 if ( m_pop3 != NULL ) logout(); 222 if ( m_pop3 != NULL ) logout();
223 223
224 const char *server, *user, *pass; 224 const char *server, *user, *pass;
225 uint16_t port; 225 uint16_t port;
226 int err = MAILPOP3_NO_ERROR; 226 int err = MAILPOP3_NO_ERROR;
227 227
228 server = account->getServer().latin1(); 228 server = account->getServer().latin1();
229 port = account->getPort().toUInt(); 229 port = account->getPort().toUInt();
230 user = account->getUser().latin1(); 230 user = account->getUser().latin1();
231 pass = account->getPassword().latin1(); 231 pass = account->getPassword().latin1();
232 232
233 m_pop3 = mailpop3_new( 200, &pop3_progress ); 233 m_pop3 = mailpop3_new( 200, &pop3_progress );
234 234
235 // connect 235 // connect
236 if (account->getSSL()) { 236 if (account->getSSL()) {
237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); 237 err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
238 } else { 238 } else {
239 err = mailpop3_socket_connect( m_pop3, (char*)server, port ); 239 err = mailpop3_socket_connect( m_pop3, (char*)server, port );
240 } 240 }
241 241
242 if ( err != MAILPOP3_NO_ERROR ) { 242 if ( err != MAILPOP3_NO_ERROR ) {
243 qDebug( "pop3: error connecting to %s\n reason: %s", server, 243 qDebug( "pop3: error connecting to %s\n reason: %s", server,
244 m_pop3->pop3_response ); 244 m_pop3->pop3_response );
245 mailpop3_free( m_pop3 ); 245 mailpop3_free( m_pop3 );
246 m_pop3 = NULL; 246 m_pop3 = NULL;
247 return; 247 return;
248 } 248 }
249 qDebug( "POP3: connected!" ); 249 qDebug( "POP3: connected!" );
250 250
251 // login 251 // login
252 // TODO: decide if apop or plain login should be used 252 // TODO: decide if apop or plain login should be used
253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); 253 err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
254 if ( err != MAILPOP3_NO_ERROR ) { 254 if ( err != MAILPOP3_NO_ERROR ) {
255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); 255 qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
256 logout(); 256 logout();
257 return; 257 return;
258 } 258 }
259 259
260 qDebug( "POP3: logged in!" ); 260 qDebug( "POP3: logged in!" );
261} 261}
262 262
263void POP3wrapper::logout() 263void POP3wrapper::logout()
264{ 264{
265 int err = MAILPOP3_NO_ERROR; 265 int err = MAILPOP3_NO_ERROR;
266 if ( m_pop3 == NULL ) return; 266 if ( m_pop3 == NULL ) return;
267 err = mailpop3_quit( m_pop3 ); 267 err = mailpop3_quit( m_pop3 );
268 mailpop3_free( m_pop3 ); 268 mailpop3_free( m_pop3 );
269 m_pop3 = NULL; 269 m_pop3 = NULL;
270} 270}
271 271
272 272
273QList<Folder>* POP3wrapper::listFolders() 273QList<Folder>* POP3wrapper::listFolders()
274{ 274{
275 QList<Folder> * folders = new QList<Folder>(); 275 QList<Folder> * folders = new QList<Folder>();
276 folders->setAutoDelete( true ); 276 folders->setAutoDelete( true );
277 Folder*inb=new Folder("INBOX"); 277 Folder*inb=new Folder("INBOX");
278 folders->append(inb); 278 folders->append(inb);
279 return folders; 279 return folders;
280} 280}
281 281
282QString POP3wrapper::fetchPart(const RecMail&,const QValueList<int>&,bool) 282QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
283{ 283{
284 return ""; 284 return "";
285} 285}
286 286
287QString POP3wrapper::fetchPart(const RecMail&,const RecPart&) 287void POP3wrapper::deleteMail(const RecMail&)
288{ 288{
289 return "";
290} 289}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 3b24564..ef972c8 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,43 +1,43 @@
1#ifndef __POP3WRAPPER 1#ifndef __POP3WRAPPER
2#define __POP3WRAPPER 2#define __POP3WRAPPER
3 3
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include "abstractmail.h" 5#include "abstractmail.h"
6 6
7class RecMail; 7class RecMail;
8class RecBody; 8class RecBody;
9struct mailpop3; 9struct mailpop3;
10 10
11class POP3wrapper : public AbstractMail 11class POP3wrapper : public AbstractMail
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 POP3wrapper( POP3account *a ); 16 POP3wrapper( POP3account *a );
17 virtual ~POP3wrapper(); 17 virtual ~POP3wrapper();
18 /* mailbox will be ignored */ 18 /* mailbox will be ignored */
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
21 virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false);
22 virtual QString fetchPart(const RecMail&mail,const RecPart&part); 21 virtual QString fetchPart(const RecMail&mail,const RecPart&part);
22 virtual void deleteMail(const RecMail&mail);
23 23
24 RecBody fetchBody( const RecMail &mail ); 24 RecBody fetchBody( const RecMail &mail );
25 static void pop3_progress( size_t current, size_t maximum ); 25 static void pop3_progress( size_t current, size_t maximum );
26 26
27protected: 27protected:
28 void login(); 28 void login();
29 void logout(); 29 void logout();
30 30
31private: 31private:
32 RecMail *parseHeader( const char *header ); 32 RecMail *parseHeader( const char *header );
33 RecBody parseBody( const char *message ); 33 RecBody parseBody( const char *message );
34 QString parseMailboxList( mailimf_mailbox_list *list ); 34 QString parseMailboxList( mailimf_mailbox_list *list );
35 QString parseMailbox( mailimf_mailbox *box ); 35 QString parseMailbox( mailimf_mailbox *box );
36 QString parseGroup( mailimf_group *group ); 36 QString parseGroup( mailimf_group *group );
37 QString parseAddressList( mailimf_address_list *list ); 37 QString parseAddressList( mailimf_address_list *list );
38 QString parseDateTime( mailimf_date_time *date ); 38 QString parseDateTime( mailimf_date_time *date );
39 POP3account *account; 39 POP3account *account;
40 mailpop3 *m_pop3; 40 mailpop3 *m_pop3;
41}; 41};
42 42
43#endif 43#endif