summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-03 02:17:50 (UTC)
committer alwin <alwin>2004-01-03 02:17:50 (UTC)
commit1214e08e45cda6f0de39a8f3bcff2e69244bb87f (patch) (unidiff)
treed51a018b6014904c09272c684e211d8d05cf360e
parent79bca648a80c42d5dc7e7674b251715292db33b3 (diff)
downloadopie-1214e08e45cda6f0de39a8f3bcff2e69244bb87f.zip
opie-1214e08e45cda6f0de39a8f3bcff2e69244bb87f.tar.gz
opie-1214e08e45cda6f0de39a8f3bcff2e69244bb87f.tar.bz2
improved parsing of mailbodies 'cause it failed on multi-part fields which
contains multipart-fields, too.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp43
-rw-r--r--noncore/net/mail/imapwrapper.h3
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp43
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h3
4 files changed, 84 insertions, 8 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index f7e93aa..ae196bb 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -404,351 +404,388 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
404 mailimap_fetch_type_free( fetchType ); 404 mailimap_fetch_type_free( fetchType );
405 405
406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
407 mailimap_msg_att * msg_att; 407 mailimap_msg_att * msg_att;
408 msg_att = (mailimap_msg_att*)current->data; 408 msg_att = (mailimap_msg_att*)current->data;
409 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; 410 QValueList<int> path;
411 body_desc = item->att_data.att_static->att_data.att_body; 411 body_desc = item->att_data.att_static->att_data.att_body;
412 traverseBody(mail,body_desc,body,0,path); 412 traverseBody(mail,body_desc,body,0,path);
413 } else { 413 } else {
414 qDebug("error fetching body: %s",m_imap->imap_response); 414 qDebug("error fetching body: %s",m_imap->imap_response);
415 } 415 }
416 if (result) mailimap_fetch_list_free(result); 416 if (result) mailimap_fetch_list_free(result);
417 return body; 417 return body;
418} 418}
419 419
420QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 420QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{ 421{
422 QStringList l; 422 QStringList l;
423 QString from; 423 QString from;
424 bool named_from; 424 bool named_from;
425 clistcell *current = NULL; 425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL; 426 mailimap_address * current_address=NULL;
427 if (!list) { 427 if (!list) {
428 return l; 428 return l;
429 } 429 }
430 unsigned int count = 0; 430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = ""; 432 from = "";
433 named_from = false; 433 named_from = false;
434 current_address=(mailimap_address*)current->data; 434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){ 435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name); 436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" "; 437 from+=" ";
438 named_from = true; 438 named_from = true;
439 } 439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<"; 441 from+="<";
442 } 442 }
443 if (current_address->ad_mailbox_name) { 443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name); 444 from+=QString(current_address->ad_mailbox_name);
445 from+="@"; 445 from+="@";
446 } 446 }
447 if (current_address->ad_host_name) { 447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name); 448 from+=QString(current_address->ad_host_name);
449 } 449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">"; 451 from+=">";
452 } 452 }
453 l.append(QString(from)); 453 l.append(QString(from));
454 if (++count > 99) { 454 if (++count > 99) {
455 break; 455 break;
456 } 456 }
457 } 457 }
458 return l; 458 return l;
459} 459}
460 460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{ 462{
463 encodedString*res=new encodedString; 463 encodedString*res=new encodedString;
464 const char*mb; 464 const char*mb;
465 int err; 465 int err;
466 mailimap_fetch_type *fetchType; 466 mailimap_fetch_type *fetchType;
467 mailimap_set *set; 467 mailimap_set *set;
468 clistcell*current,*cur; 468 clistcell*current,*cur;
469 469
470 login(); 470 login();
471 if (!m_imap) { 471 if (!m_imap) {
472 return res; 472 return res;
473 } 473 }
474 if (!internal_call) { 474 if (!internal_call) {
475 mb = mail.getMbox().latin1(); 475 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb); 476 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) { 477 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response); 478 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res; 479 return res;
480 } 480 }
481 } 481 }
482 set = mailimap_set_new_single(mail.getNumber()); 482 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new(); 483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) { 484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j]; 486 *p_id = path[j];
487 clist_append(id_list,p_id); 487 clist_append(id_list,p_id);
488 } 488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec); 491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493 493
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495 495
496 clist*result = 0; 496 clist*result = 0;
497 497
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 498 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 499 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 500 mailimap_fetch_type_free( fetchType );
501 501
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 503 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 504 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item; 505 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */ 511 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 } 514 }
515 } 515 }
516 } 516 }
517 } else { 517 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 518 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 519 }
520 if (result) mailimap_fetch_list_free(result); 520 if (result) mailimap_fetch_list_free(result);
521 return res; 521 return res;
522} 522}
523 523
524/* current_recursion is for recursive calls. 524/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */ 525 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count) 527 int current_recursion,QValueList<int>recList,int current_count)
528{ 528{
529 if (!body || current_recursion>=10) { 529 if (!body || current_recursion>=10) {
530 return; 530 return;
531 } 531 }
532 ++current_count;
533 switch (body->bd_type) { 532 switch (body->bd_type) {
534 case MAILIMAP_BODY_1PART: 533 case MAILIMAP_BODY_1PART:
535 { 534 {
536 QValueList<int>countlist = recList; 535 QValueList<int>countlist = recList;
537 countlist.append(current_count); 536 countlist.append(current_count);
538 RecPart currentPart; 537 RecPart currentPart;
539 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
540 QString id(""); 539 QString id("");
541 currentPart.setPositionlist(countlist); 540 currentPart.setPositionlist(countlist);
542 for (unsigned int j = 0; j < countlist.count();++j) { 541 for (unsigned int j = 0; j < countlist.count();++j) {
543 id+=(j>0?" ":""); 542 id+=(j>0?" ":"");
544 id+=QString("%1").arg(countlist[j]); 543 id+=QString("%1").arg(countlist[j]);
545 } 544 }
546 qDebug("ID = %s",id.latin1()); 545 qDebug("ID = %s",id.latin1());
547 currentPart.setIdentifier(id); 546 currentPart.setIdentifier(id);
548 fillSinglePart(currentPart,part1); 547 fillSinglePart(currentPart,part1);
549 /* important: Check for is NULL 'cause a body can be empty! 548 /* important: Check for is NULL 'cause a body can be empty!
550 And we put it only into the mail if it is the FIRST part */ 549 And we put it only into the mail if it is the FIRST part */
551 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
552 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
553 target_body.setDescription(currentPart); 552 target_body.setDescription(currentPart);
554 target_body.setBodytext(body_text); 553 target_body.setBodytext(body_text);
554 if (countlist.count()>1) {
555 target_body.addPart(currentPart);
556 }
555 } else { 557 } else {
556 target_body.addPart(currentPart); 558 target_body.addPart(currentPart);
557 } 559 }
558 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
559 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
560 } 562 }
561 } 563 }
562 break; 564 break;
563 case MAILIMAP_BODY_MPART: 565 case MAILIMAP_BODY_MPART:
564 { 566 {
567 QValueList<int>countlist = recList;
565 clistcell*current=0; 568 clistcell*current=0;
566 mailimap_body*current_body=0; 569 mailimap_body*current_body=0;
567 unsigned int ccount = current_count-1; 570 unsigned int ccount = 1;
568 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 571 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)) { 572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
570 current_body = (mailimap_body*)current->data; 573 current_body = (mailimap_body*)current->data;
571 traverseBody(mail,current_body,target_body,current_recursion+1,recList,ccount); 574 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
575 RecPart targetPart;
576 targetPart.setType("multipart");
577 fillMultiPart(targetPart,mailDescription);
578 countlist.append(current_count);
579 targetPart.setPositionlist(countlist);
580 target_body.addPart(targetPart);
581 QString id("");
582 for (unsigned int j = 0; j < countlist.count();++j) {
583 id+=(j>0?" ":"");
584 id+=QString("%1").arg(countlist[j]);
585 }
586 qDebug("ID(mpart) = %s",id.latin1());
587 }
588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
589 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
590 countlist = recList;
591 }
572 ++ccount; 592 ++ccount;
573 } 593 }
574 } 594 }
575 break; 595 break;
576 default: 596 default:
577 break; 597 break;
578 } 598 }
579} 599}
580 600
581void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
582{ 602{
583 if (!Description) { 603 if (!Description) {
584 return; 604 return;
585 } 605 }
586 switch (Description->bd_type) { 606 switch (Description->bd_type) {
587 case MAILIMAP_BODY_TYPE_1PART_TEXT: 607 case MAILIMAP_BODY_TYPE_1PART_TEXT:
588 target_part.setType("text"); 608 target_part.setType("text");
589 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
590 break; 610 break;
591 case MAILIMAP_BODY_TYPE_1PART_BASIC: 611 case MAILIMAP_BODY_TYPE_1PART_BASIC:
592 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
593 break; 613 break;
594 case MAILIMAP_BODY_TYPE_1PART_MSG: 614 case MAILIMAP_BODY_TYPE_1PART_MSG:
595 target_part.setType("message"); 615 target_part.setType("message");
596 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
597 break; 617 break;
598 default: 618 default:
599 break; 619 break;
600 } 620 }
601} 621}
602 622
603void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
604{ 624{
605 if (!which) { 625 if (!which) {
606 return; 626 return;
607 } 627 }
608 QString sub; 628 QString sub;
609 sub = which->bd_media_text; 629 sub = which->bd_media_text;
630 qDebug("Type= text/%s",which->bd_media_text);
610 target_part.setSubtype(sub.lower()); 631 target_part.setSubtype(sub.lower());
611 target_part.setLines(which->bd_lines); 632 target_part.setLines(which->bd_lines);
612 fillBodyFields(target_part,which->bd_fields); 633 fillBodyFields(target_part,which->bd_fields);
613} 634}
614 635
615void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
616{ 637{
617 if (!which) { 638 if (!which) {
618 return; 639 return;
619 } 640 }
620 target_part.setSubtype("rfc822"); 641 target_part.setSubtype("rfc822");
621 qDebug("Message part"); 642 qDebug("Message part");
622 /* we set this type to text/plain */ 643 /* we set this type to text/plain */
623 target_part.setLines(which->bd_lines); 644 target_part.setLines(which->bd_lines);
624 fillBodyFields(target_part,which->bd_fields); 645 fillBodyFields(target_part,which->bd_fields);
625} 646}
626 647
648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
649{
650 if (!which) return;
651 target_part.setSubtype(which->bd_media_subtype);
652 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
653 clistcell*cur = 0;
654 mailimap_single_body_fld_param*param=0;
655 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
656 param = (mailimap_single_body_fld_param*)cur->data;
657 if (param) {
658 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
659 }
660 }
661 }
662}
663
627void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 664void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
628{ 665{
629 if (!which) { 666 if (!which) {
630 return; 667 return;
631 } 668 }
632 QString type,sub; 669 QString type,sub;
633 switch (which->bd_media_basic->med_type) { 670 switch (which->bd_media_basic->med_type) {
634 case MAILIMAP_MEDIA_BASIC_APPLICATION: 671 case MAILIMAP_MEDIA_BASIC_APPLICATION:
635 type = "application"; 672 type = "application";
636 break; 673 break;
637 case MAILIMAP_MEDIA_BASIC_AUDIO: 674 case MAILIMAP_MEDIA_BASIC_AUDIO:
638 type = "audio"; 675 type = "audio";
639 break; 676 break;
640 case MAILIMAP_MEDIA_BASIC_IMAGE: 677 case MAILIMAP_MEDIA_BASIC_IMAGE:
641 type = "image"; 678 type = "image";
642 break; 679 break;
643 case MAILIMAP_MEDIA_BASIC_MESSAGE: 680 case MAILIMAP_MEDIA_BASIC_MESSAGE:
644 type = "message"; 681 type = "message";
645 break; 682 break;
646 case MAILIMAP_MEDIA_BASIC_VIDEO: 683 case MAILIMAP_MEDIA_BASIC_VIDEO:
647 type = "video"; 684 type = "video";
648 break; 685 break;
649 case MAILIMAP_MEDIA_BASIC_OTHER: 686 case MAILIMAP_MEDIA_BASIC_OTHER:
650 default: 687 default:
651 if (which->bd_media_basic->med_basic_type) { 688 if (which->bd_media_basic->med_basic_type) {
652 type = which->bd_media_basic->med_basic_type; 689 type = which->bd_media_basic->med_basic_type;
653 } else { 690 } else {
654 type = ""; 691 type = "";
655 } 692 }
656 break; 693 break;
657 } 694 }
658 if (which->bd_media_basic->med_subtype) { 695 if (which->bd_media_basic->med_subtype) {
659 sub = which->bd_media_basic->med_subtype; 696 sub = which->bd_media_basic->med_subtype;
660 } else { 697 } else {
661 sub = ""; 698 sub = "";
662 } 699 }
663 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 700 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
664 target_part.setType(type.lower()); 701 target_part.setType(type.lower());
665 target_part.setSubtype(sub.lower()); 702 target_part.setSubtype(sub.lower());
666 fillBodyFields(target_part,which->bd_fields); 703 fillBodyFields(target_part,which->bd_fields);
667} 704}
668 705
669void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 706void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
670{ 707{
671 if (!which) return; 708 if (!which) return;
672 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 709 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
673 clistcell*cur; 710 clistcell*cur;
674 mailimap_single_body_fld_param*param=0; 711 mailimap_single_body_fld_param*param=0;
675 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 712 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
676 param = (mailimap_single_body_fld_param*)cur->data; 713 param = (mailimap_single_body_fld_param*)cur->data;
677 if (param) { 714 if (param) {
678 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 715 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
679 } 716 }
680 } 717 }
681 } 718 }
682 mailimap_body_fld_enc*enc = which->bd_encoding; 719 mailimap_body_fld_enc*enc = which->bd_encoding;
683 QString encoding(""); 720 QString encoding("");
684 switch (enc->enc_type) { 721 switch (enc->enc_type) {
685 case MAILIMAP_BODY_FLD_ENC_7BIT: 722 case MAILIMAP_BODY_FLD_ENC_7BIT:
686 encoding = "7bit"; 723 encoding = "7bit";
687 break; 724 break;
688 case MAILIMAP_BODY_FLD_ENC_8BIT: 725 case MAILIMAP_BODY_FLD_ENC_8BIT:
689 encoding = "8bit"; 726 encoding = "8bit";
690 break; 727 break;
691 case MAILIMAP_BODY_FLD_ENC_BINARY: 728 case MAILIMAP_BODY_FLD_ENC_BINARY:
692 encoding="binary"; 729 encoding="binary";
693 break; 730 break;
694 case MAILIMAP_BODY_FLD_ENC_BASE64: 731 case MAILIMAP_BODY_FLD_ENC_BASE64:
695 encoding="base64"; 732 encoding="base64";
696 break; 733 break;
697 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 734 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
698 encoding="quoted-printable"; 735 encoding="quoted-printable";
699 break; 736 break;
700 case MAILIMAP_BODY_FLD_ENC_OTHER: 737 case MAILIMAP_BODY_FLD_ENC_OTHER:
701 default: 738 default:
702 if (enc->enc_value) { 739 if (enc->enc_value) {
703 char*t=enc->enc_value; 740 char*t=enc->enc_value;
704 encoding=QString(enc->enc_value); 741 encoding=QString(enc->enc_value);
705 enc->enc_value=0L; 742 enc->enc_value=0L;
706 free(t); 743 free(t);
707 } 744 }
708 } 745 }
709 if (which->bd_description) { 746 if (which->bd_description) {
710 target_part.setDescription(QString(which->bd_description)); 747 target_part.setDescription(QString(which->bd_description));
711 } 748 }
712 target_part.setEncoding(encoding); 749 target_part.setEncoding(encoding);
713 target_part.setSize(which->bd_size); 750 target_part.setSize(which->bd_size);
714} 751}
715 752
716void IMAPwrapper::deleteMail(const RecMail&mail) 753void IMAPwrapper::deleteMail(const RecMail&mail)
717{ 754{
718 mailimap_flag_list*flist; 755 mailimap_flag_list*flist;
719 mailimap_set *set; 756 mailimap_set *set;
720 mailimap_store_att_flags * store_flags; 757 mailimap_store_att_flags * store_flags;
721 int err; 758 int err;
722 login(); 759 login();
723 if (!m_imap) { 760 if (!m_imap) {
724 return; 761 return;
725 } 762 }
726 const char *mb = mail.getMbox().latin1(); 763 const char *mb = mail.getMbox().latin1();
727 err = mailimap_select( m_imap, (char*)mb); 764 err = mailimap_select( m_imap, (char*)mb);
728 if ( err != MAILIMAP_NO_ERROR ) { 765 if ( err != MAILIMAP_NO_ERROR ) {
729 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 766 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
730 return; 767 return;
731 } 768 }
732 flist = mailimap_flag_list_new_empty(); 769 flist = mailimap_flag_list_new_empty();
733 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 770 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
734 store_flags = mailimap_store_att_flags_new_set_flags(flist); 771 store_flags = mailimap_store_att_flags_new_set_flags(flist);
735 set = mailimap_set_new_single(mail.getNumber()); 772 set = mailimap_set_new_single(mail.getNumber());
736 err = mailimap_store(m_imap,set,store_flags); 773 err = mailimap_store(m_imap,set,store_flags);
737 mailimap_set_free( set ); 774 mailimap_set_free( set );
738 mailimap_store_att_flags_free(store_flags); 775 mailimap_store_att_flags_free(store_flags);
739 776
740 if (err != MAILIMAP_NO_ERROR) { 777 if (err != MAILIMAP_NO_ERROR) {
741 qDebug("error deleting mail: %s",m_imap->imap_response); 778 qDebug("error deleting mail: %s",m_imap->imap_response);
742 return; 779 return;
743 } 780 }
744 qDebug("deleting mail: %s",m_imap->imap_response); 781 qDebug("deleting mail: %s",m_imap->imap_response);
745 /* should we realy do that at this moment? */ 782 /* should we realy do that at this moment? */
746 err = mailimap_expunge(m_imap); 783 err = mailimap_expunge(m_imap);
747 if (err != MAILIMAP_NO_ERROR) { 784 if (err != MAILIMAP_NO_ERROR) {
748 qDebug("error deleting mail: %s",m_imap->imap_response); 785 qDebug("error deleting mail: %s",m_imap->imap_response);
749 } 786 }
750 qDebug("Delete successfull %s",m_imap->imap_response); 787 qDebug("Delete successfull %s",m_imap->imap_response);
751} 788}
752 789
753void IMAPwrapper::answeredMail(const RecMail&mail) 790void IMAPwrapper::answeredMail(const RecMail&mail)
754{ 791{
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index e5846f8..7941046 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -1,66 +1,67 @@
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#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 28
29 virtual void deleteMail(const RecMail&mail); 29 virtual void deleteMail(const RecMail&mail);
30 virtual void answeredMail(const RecMail&mail); 30 virtual void answeredMail(const RecMail&mail);
31 virtual int deleteAllMail(const Folder*folder); 31 virtual int deleteAllMail(const Folder*folder);
32 32
33 virtual RecBody fetchBody(const RecMail&mail); 33 virtual RecBody fetchBody(const RecMail&mail);
34 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 34 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
36 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 36 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
37 37
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
39 virtual int deleteMbox(const Folder*folder); 39 virtual int deleteMbox(const Folder*folder);
40 40
41 static void imap_progress( size_t current, size_t maximum ); 41 static void imap_progress( size_t current, size_t maximum );
42 42
43protected: 43protected:
44 RecMail*parse_list_result(mailimap_msg_att*); 44 RecMail*parse_list_result(mailimap_msg_att*);
45 void login(); 45 void login();
46 void logout(); 46 void logout();
47 47
48 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="");
49 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);
50 50
51 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 51 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
52 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 52 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
53 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 53 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
54 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); 55 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
56 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
56 57
57 /* just helpers */ 58 /* just helpers */
58 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 59 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
59 static QStringList address_list_to_stringlist(clist*list); 60 static QStringList address_list_to_stringlist(clist*list);
60 61
61 62
62 IMAPaccount *account; 63 IMAPaccount *account;
63 mailimap *m_imap; 64 mailimap *m_imap;
64}; 65};
65 66
66#endif 67#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index f7e93aa..ae196bb 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -404,351 +404,388 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
404 mailimap_fetch_type_free( fetchType ); 404 mailimap_fetch_type_free( fetchType );
405 405
406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 406 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
407 mailimap_msg_att * msg_att; 407 mailimap_msg_att * msg_att;
408 msg_att = (mailimap_msg_att*)current->data; 408 msg_att = (mailimap_msg_att*)current->data;
409 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; 410 QValueList<int> path;
411 body_desc = item->att_data.att_static->att_data.att_body; 411 body_desc = item->att_data.att_static->att_data.att_body;
412 traverseBody(mail,body_desc,body,0,path); 412 traverseBody(mail,body_desc,body,0,path);
413 } else { 413 } else {
414 qDebug("error fetching body: %s",m_imap->imap_response); 414 qDebug("error fetching body: %s",m_imap->imap_response);
415 } 415 }
416 if (result) mailimap_fetch_list_free(result); 416 if (result) mailimap_fetch_list_free(result);
417 return body; 417 return body;
418} 418}
419 419
420QStringList IMAPwrapper::address_list_to_stringlist(clist*list) 420QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
421{ 421{
422 QStringList l; 422 QStringList l;
423 QString from; 423 QString from;
424 bool named_from; 424 bool named_from;
425 clistcell *current = NULL; 425 clistcell *current = NULL;
426 mailimap_address * current_address=NULL; 426 mailimap_address * current_address=NULL;
427 if (!list) { 427 if (!list) {
428 return l; 428 return l;
429 } 429 }
430 unsigned int count = 0; 430 unsigned int count = 0;
431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) { 431 for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
432 from = ""; 432 from = "";
433 named_from = false; 433 named_from = false;
434 current_address=(mailimap_address*)current->data; 434 current_address=(mailimap_address*)current->data;
435 if (current_address->ad_personal_name){ 435 if (current_address->ad_personal_name){
436 from+=convert_String((const char*)current_address->ad_personal_name); 436 from+=convert_String((const char*)current_address->ad_personal_name);
437 from+=" "; 437 from+=" ";
438 named_from = true; 438 named_from = true;
439 } 439 }
440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 440 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
441 from+="<"; 441 from+="<";
442 } 442 }
443 if (current_address->ad_mailbox_name) { 443 if (current_address->ad_mailbox_name) {
444 from+=QString(current_address->ad_mailbox_name); 444 from+=QString(current_address->ad_mailbox_name);
445 from+="@"; 445 from+="@";
446 } 446 }
447 if (current_address->ad_host_name) { 447 if (current_address->ad_host_name) {
448 from+=QString(current_address->ad_host_name); 448 from+=QString(current_address->ad_host_name);
449 } 449 }
450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { 450 if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) {
451 from+=">"; 451 from+=">";
452 } 452 }
453 l.append(QString(from)); 453 l.append(QString(from));
454 if (++count > 99) { 454 if (++count > 99) {
455 break; 455 break;
456 } 456 }
457 } 457 }
458 return l; 458 return l;
459} 459}
460 460
461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call) 461encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
462{ 462{
463 encodedString*res=new encodedString; 463 encodedString*res=new encodedString;
464 const char*mb; 464 const char*mb;
465 int err; 465 int err;
466 mailimap_fetch_type *fetchType; 466 mailimap_fetch_type *fetchType;
467 mailimap_set *set; 467 mailimap_set *set;
468 clistcell*current,*cur; 468 clistcell*current,*cur;
469 469
470 login(); 470 login();
471 if (!m_imap) { 471 if (!m_imap) {
472 return res; 472 return res;
473 } 473 }
474 if (!internal_call) { 474 if (!internal_call) {
475 mb = mail.getMbox().latin1(); 475 mb = mail.getMbox().latin1();
476 err = mailimap_select( m_imap, (char*)mb); 476 err = mailimap_select( m_imap, (char*)mb);
477 if ( err != MAILIMAP_NO_ERROR ) { 477 if ( err != MAILIMAP_NO_ERROR ) {
478 qDebug("error selecting mailbox: %s",m_imap->imap_response); 478 qDebug("error selecting mailbox: %s",m_imap->imap_response);
479 return res; 479 return res;
480 } 480 }
481 } 481 }
482 set = mailimap_set_new_single(mail.getNumber()); 482 set = mailimap_set_new_single(mail.getNumber());
483 clist*id_list=clist_new(); 483 clist*id_list=clist_new();
484 for (unsigned j=0; j < path.count();++j) { 484 for (unsigned j=0; j < path.count();++j) {
485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id)); 485 uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
486 *p_id = path[j]; 486 *p_id = path[j];
487 clist_append(id_list,p_id); 487 clist_append(id_list,p_id);
488 } 488 }
489 mailimap_section_part * section_part = mailimap_section_part_new(id_list); 489 mailimap_section_part * section_part = mailimap_section_part_new(id_list);
490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); 490 mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
491 mailimap_section * section = mailimap_section_new(section_spec); 491 mailimap_section * section = mailimap_section_new(section_spec);
492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section); 492 mailimap_fetch_att * fetch_att = mailimap_fetch_att_new_body_section(section);
493 493
494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att); 494 fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
495 495
496 clist*result = 0; 496 clist*result = 0;
497 497
498 err = mailimap_fetch( m_imap, set, fetchType, &result ); 498 err = mailimap_fetch( m_imap, set, fetchType, &result );
499 mailimap_set_free( set ); 499 mailimap_set_free( set );
500 mailimap_fetch_type_free( fetchType ); 500 mailimap_fetch_type_free( fetchType );
501 501
502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) { 502 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
503 mailimap_msg_att * msg_att; 503 mailimap_msg_att * msg_att;
504 msg_att = (mailimap_msg_att*)current->data; 504 msg_att = (mailimap_msg_att*)current->data;
505 mailimap_msg_att_item*msg_att_item; 505 mailimap_msg_att_item*msg_att_item;
506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) { 506 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur); 507 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) { 508 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) { 509 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part; 510 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
511 /* detach - we take over the content */ 511 /* detach - we take over the content */
512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L; 512 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length); 513 res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
514 } 514 }
515 } 515 }
516 } 516 }
517 } else { 517 } else {
518 qDebug("error fetching text: %s",m_imap->imap_response); 518 qDebug("error fetching text: %s",m_imap->imap_response);
519 } 519 }
520 if (result) mailimap_fetch_list_free(result); 520 if (result) mailimap_fetch_list_free(result);
521 return res; 521 return res;
522} 522}
523 523
524/* current_recursion is for recursive calls. 524/* current_recursion is for recursive calls.
525 current_count means the position inside the internal loop! */ 525 current_count means the position inside the internal loop! */
526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body, 526void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,
527 int current_recursion,QValueList<int>recList,int current_count) 527 int current_recursion,QValueList<int>recList,int current_count)
528{ 528{
529 if (!body || current_recursion>=10) { 529 if (!body || current_recursion>=10) {
530 return; 530 return;
531 } 531 }
532 ++current_count;
533 switch (body->bd_type) { 532 switch (body->bd_type) {
534 case MAILIMAP_BODY_1PART: 533 case MAILIMAP_BODY_1PART:
535 { 534 {
536 QValueList<int>countlist = recList; 535 QValueList<int>countlist = recList;
537 countlist.append(current_count); 536 countlist.append(current_count);
538 RecPart currentPart; 537 RecPart currentPart;
539 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part; 538 mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
540 QString id(""); 539 QString id("");
541 currentPart.setPositionlist(countlist); 540 currentPart.setPositionlist(countlist);
542 for (unsigned int j = 0; j < countlist.count();++j) { 541 for (unsigned int j = 0; j < countlist.count();++j) {
543 id+=(j>0?" ":""); 542 id+=(j>0?" ":"");
544 id+=QString("%1").arg(countlist[j]); 543 id+=QString("%1").arg(countlist[j]);
545 } 544 }
546 qDebug("ID = %s",id.latin1()); 545 qDebug("ID = %s",id.latin1());
547 currentPart.setIdentifier(id); 546 currentPart.setIdentifier(id);
548 fillSinglePart(currentPart,part1); 547 fillSinglePart(currentPart,part1);
549 /* important: Check for is NULL 'cause a body can be empty! 548 /* important: Check for is NULL 'cause a body can be empty!
550 And we put it only into the mail if it is the FIRST part */ 549 And we put it only into the mail if it is the FIRST part */
551 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) { 550 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body.Bodytext().isNull() && countlist[0]==1) {
552 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding()); 551 QString body_text = fetchTextPart(mail,countlist,true,currentPart.Encoding());
553 target_body.setDescription(currentPart); 552 target_body.setDescription(currentPart);
554 target_body.setBodytext(body_text); 553 target_body.setBodytext(body_text);
554 if (countlist.count()>1) {
555 target_body.addPart(currentPart);
556 }
555 } else { 557 } else {
556 target_body.addPart(currentPart); 558 target_body.addPart(currentPart);
557 } 559 }
558 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) { 560 if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
559 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist); 561 traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
560 } 562 }
561 } 563 }
562 break; 564 break;
563 case MAILIMAP_BODY_MPART: 565 case MAILIMAP_BODY_MPART:
564 { 566 {
567 QValueList<int>countlist = recList;
565 clistcell*current=0; 568 clistcell*current=0;
566 mailimap_body*current_body=0; 569 mailimap_body*current_body=0;
567 unsigned int ccount = current_count-1; 570 unsigned int ccount = 1;
568 mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart; 571 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)) { 572 for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
570 current_body = (mailimap_body*)current->data; 573 current_body = (mailimap_body*)current->data;
571 traverseBody(mail,current_body,target_body,current_recursion+1,recList,ccount); 574 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
575 RecPart targetPart;
576 targetPart.setType("multipart");
577 fillMultiPart(targetPart,mailDescription);
578 countlist.append(current_count);
579 targetPart.setPositionlist(countlist);
580 target_body.addPart(targetPart);
581 QString id("");
582 for (unsigned int j = 0; j < countlist.count();++j) {
583 id+=(j>0?" ":"");
584 id+=QString("%1").arg(countlist[j]);
585 }
586 qDebug("ID(mpart) = %s",id.latin1());
587 }
588 traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
589 if (current_body->bd_type==MAILIMAP_BODY_MPART) {
590 countlist = recList;
591 }
572 ++ccount; 592 ++ccount;
573 } 593 }
574 } 594 }
575 break; 595 break;
576 default: 596 default:
577 break; 597 break;
578 } 598 }
579} 599}
580 600
581void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description) 601void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
582{ 602{
583 if (!Description) { 603 if (!Description) {
584 return; 604 return;
585 } 605 }
586 switch (Description->bd_type) { 606 switch (Description->bd_type) {
587 case MAILIMAP_BODY_TYPE_1PART_TEXT: 607 case MAILIMAP_BODY_TYPE_1PART_TEXT:
588 target_part.setType("text"); 608 target_part.setType("text");
589 fillSingleTextPart(target_part,Description->bd_data.bd_type_text); 609 fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
590 break; 610 break;
591 case MAILIMAP_BODY_TYPE_1PART_BASIC: 611 case MAILIMAP_BODY_TYPE_1PART_BASIC:
592 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic); 612 fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
593 break; 613 break;
594 case MAILIMAP_BODY_TYPE_1PART_MSG: 614 case MAILIMAP_BODY_TYPE_1PART_MSG:
595 target_part.setType("message"); 615 target_part.setType("message");
596 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg); 616 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
597 break; 617 break;
598 default: 618 default:
599 break; 619 break;
600 } 620 }
601} 621}
602 622
603void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which) 623void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
604{ 624{
605 if (!which) { 625 if (!which) {
606 return; 626 return;
607 } 627 }
608 QString sub; 628 QString sub;
609 sub = which->bd_media_text; 629 sub = which->bd_media_text;
630 qDebug("Type= text/%s",which->bd_media_text);
610 target_part.setSubtype(sub.lower()); 631 target_part.setSubtype(sub.lower());
611 target_part.setLines(which->bd_lines); 632 target_part.setLines(which->bd_lines);
612 fillBodyFields(target_part,which->bd_fields); 633 fillBodyFields(target_part,which->bd_fields);
613} 634}
614 635
615void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which) 636void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
616{ 637{
617 if (!which) { 638 if (!which) {
618 return; 639 return;
619 } 640 }
620 target_part.setSubtype("rfc822"); 641 target_part.setSubtype("rfc822");
621 qDebug("Message part"); 642 qDebug("Message part");
622 /* we set this type to text/plain */ 643 /* we set this type to text/plain */
623 target_part.setLines(which->bd_lines); 644 target_part.setLines(which->bd_lines);
624 fillBodyFields(target_part,which->bd_fields); 645 fillBodyFields(target_part,which->bd_fields);
625} 646}
626 647
648void IMAPwrapper::fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which)
649{
650 if (!which) return;
651 target_part.setSubtype(which->bd_media_subtype);
652 if (which->bd_ext_mpart && which->bd_ext_mpart->bd_parameter && which->bd_ext_mpart->bd_parameter->pa_list) {
653 clistcell*cur = 0;
654 mailimap_single_body_fld_param*param=0;
655 for (cur = clist_begin(which->bd_ext_mpart->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
656 param = (mailimap_single_body_fld_param*)cur->data;
657 if (param) {
658 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
659 }
660 }
661 }
662}
663
627void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 664void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
628{ 665{
629 if (!which) { 666 if (!which) {
630 return; 667 return;
631 } 668 }
632 QString type,sub; 669 QString type,sub;
633 switch (which->bd_media_basic->med_type) { 670 switch (which->bd_media_basic->med_type) {
634 case MAILIMAP_MEDIA_BASIC_APPLICATION: 671 case MAILIMAP_MEDIA_BASIC_APPLICATION:
635 type = "application"; 672 type = "application";
636 break; 673 break;
637 case MAILIMAP_MEDIA_BASIC_AUDIO: 674 case MAILIMAP_MEDIA_BASIC_AUDIO:
638 type = "audio"; 675 type = "audio";
639 break; 676 break;
640 case MAILIMAP_MEDIA_BASIC_IMAGE: 677 case MAILIMAP_MEDIA_BASIC_IMAGE:
641 type = "image"; 678 type = "image";
642 break; 679 break;
643 case MAILIMAP_MEDIA_BASIC_MESSAGE: 680 case MAILIMAP_MEDIA_BASIC_MESSAGE:
644 type = "message"; 681 type = "message";
645 break; 682 break;
646 case MAILIMAP_MEDIA_BASIC_VIDEO: 683 case MAILIMAP_MEDIA_BASIC_VIDEO:
647 type = "video"; 684 type = "video";
648 break; 685 break;
649 case MAILIMAP_MEDIA_BASIC_OTHER: 686 case MAILIMAP_MEDIA_BASIC_OTHER:
650 default: 687 default:
651 if (which->bd_media_basic->med_basic_type) { 688 if (which->bd_media_basic->med_basic_type) {
652 type = which->bd_media_basic->med_basic_type; 689 type = which->bd_media_basic->med_basic_type;
653 } else { 690 } else {
654 type = ""; 691 type = "";
655 } 692 }
656 break; 693 break;
657 } 694 }
658 if (which->bd_media_basic->med_subtype) { 695 if (which->bd_media_basic->med_subtype) {
659 sub = which->bd_media_basic->med_subtype; 696 sub = which->bd_media_basic->med_subtype;
660 } else { 697 } else {
661 sub = ""; 698 sub = "";
662 } 699 }
663 qDebug("Type = %s/%s",type.latin1(),sub.latin1()); 700 qDebug("Type = %s/%s",type.latin1(),sub.latin1());
664 target_part.setType(type.lower()); 701 target_part.setType(type.lower());
665 target_part.setSubtype(sub.lower()); 702 target_part.setSubtype(sub.lower());
666 fillBodyFields(target_part,which->bd_fields); 703 fillBodyFields(target_part,which->bd_fields);
667} 704}
668 705
669void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) 706void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
670{ 707{
671 if (!which) return; 708 if (!which) return;
672 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) { 709 if (which->bd_parameter && which->bd_parameter->pa_list && which->bd_parameter->pa_list->count>0) {
673 clistcell*cur; 710 clistcell*cur;
674 mailimap_single_body_fld_param*param=0; 711 mailimap_single_body_fld_param*param=0;
675 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) { 712 for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
676 param = (mailimap_single_body_fld_param*)cur->data; 713 param = (mailimap_single_body_fld_param*)cur->data;
677 if (param) { 714 if (param) {
678 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); 715 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
679 } 716 }
680 } 717 }
681 } 718 }
682 mailimap_body_fld_enc*enc = which->bd_encoding; 719 mailimap_body_fld_enc*enc = which->bd_encoding;
683 QString encoding(""); 720 QString encoding("");
684 switch (enc->enc_type) { 721 switch (enc->enc_type) {
685 case MAILIMAP_BODY_FLD_ENC_7BIT: 722 case MAILIMAP_BODY_FLD_ENC_7BIT:
686 encoding = "7bit"; 723 encoding = "7bit";
687 break; 724 break;
688 case MAILIMAP_BODY_FLD_ENC_8BIT: 725 case MAILIMAP_BODY_FLD_ENC_8BIT:
689 encoding = "8bit"; 726 encoding = "8bit";
690 break; 727 break;
691 case MAILIMAP_BODY_FLD_ENC_BINARY: 728 case MAILIMAP_BODY_FLD_ENC_BINARY:
692 encoding="binary"; 729 encoding="binary";
693 break; 730 break;
694 case MAILIMAP_BODY_FLD_ENC_BASE64: 731 case MAILIMAP_BODY_FLD_ENC_BASE64:
695 encoding="base64"; 732 encoding="base64";
696 break; 733 break;
697 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE: 734 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
698 encoding="quoted-printable"; 735 encoding="quoted-printable";
699 break; 736 break;
700 case MAILIMAP_BODY_FLD_ENC_OTHER: 737 case MAILIMAP_BODY_FLD_ENC_OTHER:
701 default: 738 default:
702 if (enc->enc_value) { 739 if (enc->enc_value) {
703 char*t=enc->enc_value; 740 char*t=enc->enc_value;
704 encoding=QString(enc->enc_value); 741 encoding=QString(enc->enc_value);
705 enc->enc_value=0L; 742 enc->enc_value=0L;
706 free(t); 743 free(t);
707 } 744 }
708 } 745 }
709 if (which->bd_description) { 746 if (which->bd_description) {
710 target_part.setDescription(QString(which->bd_description)); 747 target_part.setDescription(QString(which->bd_description));
711 } 748 }
712 target_part.setEncoding(encoding); 749 target_part.setEncoding(encoding);
713 target_part.setSize(which->bd_size); 750 target_part.setSize(which->bd_size);
714} 751}
715 752
716void IMAPwrapper::deleteMail(const RecMail&mail) 753void IMAPwrapper::deleteMail(const RecMail&mail)
717{ 754{
718 mailimap_flag_list*flist; 755 mailimap_flag_list*flist;
719 mailimap_set *set; 756 mailimap_set *set;
720 mailimap_store_att_flags * store_flags; 757 mailimap_store_att_flags * store_flags;
721 int err; 758 int err;
722 login(); 759 login();
723 if (!m_imap) { 760 if (!m_imap) {
724 return; 761 return;
725 } 762 }
726 const char *mb = mail.getMbox().latin1(); 763 const char *mb = mail.getMbox().latin1();
727 err = mailimap_select( m_imap, (char*)mb); 764 err = mailimap_select( m_imap, (char*)mb);
728 if ( err != MAILIMAP_NO_ERROR ) { 765 if ( err != MAILIMAP_NO_ERROR ) {
729 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response); 766 qDebug("error selecting mailbox for delete: %s",m_imap->imap_response);
730 return; 767 return;
731 } 768 }
732 flist = mailimap_flag_list_new_empty(); 769 flist = mailimap_flag_list_new_empty();
733 mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); 770 mailimap_flag_list_add(flist,mailimap_flag_new_deleted());
734 store_flags = mailimap_store_att_flags_new_set_flags(flist); 771 store_flags = mailimap_store_att_flags_new_set_flags(flist);
735 set = mailimap_set_new_single(mail.getNumber()); 772 set = mailimap_set_new_single(mail.getNumber());
736 err = mailimap_store(m_imap,set,store_flags); 773 err = mailimap_store(m_imap,set,store_flags);
737 mailimap_set_free( set ); 774 mailimap_set_free( set );
738 mailimap_store_att_flags_free(store_flags); 775 mailimap_store_att_flags_free(store_flags);
739 776
740 if (err != MAILIMAP_NO_ERROR) { 777 if (err != MAILIMAP_NO_ERROR) {
741 qDebug("error deleting mail: %s",m_imap->imap_response); 778 qDebug("error deleting mail: %s",m_imap->imap_response);
742 return; 779 return;
743 } 780 }
744 qDebug("deleting mail: %s",m_imap->imap_response); 781 qDebug("deleting mail: %s",m_imap->imap_response);
745 /* should we realy do that at this moment? */ 782 /* should we realy do that at this moment? */
746 err = mailimap_expunge(m_imap); 783 err = mailimap_expunge(m_imap);
747 if (err != MAILIMAP_NO_ERROR) { 784 if (err != MAILIMAP_NO_ERROR) {
748 qDebug("error deleting mail: %s",m_imap->imap_response); 785 qDebug("error deleting mail: %s",m_imap->imap_response);
749 } 786 }
750 qDebug("Delete successfull %s",m_imap->imap_response); 787 qDebug("Delete successfull %s",m_imap->imap_response);
751} 788}
752 789
753void IMAPwrapper::answeredMail(const RecMail&mail) 790void IMAPwrapper::answeredMail(const RecMail&mail)
754{ 791{
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index e5846f8..7941046 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -1,66 +1,67 @@
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#include <libetpan/clist.h> 7#include <libetpan/clist.h>
8 8
9struct mailimap; 9struct mailimap;
10struct mailimap_body; 10struct mailimap_body;
11struct mailimap_body_type_1part; 11struct mailimap_body_type_1part;
12struct mailimap_body_type_text; 12struct mailimap_body_type_text;
13struct mailimap_body_type_basic; 13struct mailimap_body_type_basic;
14struct mailimap_body_type_msg; 14struct mailimap_body_type_msg;
15struct mailimap_body_type_mpart; 15struct mailimap_body_type_mpart;
16struct mailimap_body_fields; 16struct mailimap_body_fields;
17struct mailimap_msg_att; 17struct mailimap_msg_att;
18class encodedString; 18class encodedString;
19 19
20class IMAPwrapper : public AbstractMail 20class IMAPwrapper : public AbstractMail
21{ 21{
22 Q_OBJECT 22 Q_OBJECT
23public: 23public:
24 IMAPwrapper( IMAPaccount *a ); 24 IMAPwrapper( IMAPaccount *a );
25 virtual ~IMAPwrapper(); 25 virtual ~IMAPwrapper();
26 virtual QList<Folder>* listFolders(); 26 virtual QList<Folder>* listFolders();
27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 27 virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
28 28
29 virtual void deleteMail(const RecMail&mail); 29 virtual void deleteMail(const RecMail&mail);
30 virtual void answeredMail(const RecMail&mail); 30 virtual void answeredMail(const RecMail&mail);
31 virtual int deleteAllMail(const Folder*folder); 31 virtual int deleteAllMail(const Folder*folder);
32 32
33 virtual RecBody fetchBody(const RecMail&mail); 33 virtual RecBody fetchBody(const RecMail&mail);
34 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); 34 virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
35 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); 35 virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
36 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); 36 virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
37 37
38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); 38 virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false);
39 virtual int deleteMbox(const Folder*folder); 39 virtual int deleteMbox(const Folder*folder);
40 40
41 static void imap_progress( size_t current, size_t maximum ); 41 static void imap_progress( size_t current, size_t maximum );
42 42
43protected: 43protected:
44 RecMail*parse_list_result(mailimap_msg_att*); 44 RecMail*parse_list_result(mailimap_msg_att*);
45 void login(); 45 void login();
46 void logout(); 46 void logout();
47 47
48 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="");
49 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);
50 50
51 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); 51 void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
52 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); 52 void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
53 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); 53 void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
54 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); 55 void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which);
56 void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1);
56 57
57 /* just helpers */ 58 /* just helpers */
58 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); 59 static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
59 static QStringList address_list_to_stringlist(clist*list); 60 static QStringList address_list_to_stringlist(clist*list);
60 61
61 62
62 IMAPaccount *account; 63 IMAPaccount *account;
63 mailimap *m_imap; 64 mailimap *m_imap;
64}; 65};
65 66
66#endif 67#endif