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
@@ -529,7 +529,6 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 {
@@ -552,6 +551,9 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 }
@@ -562,13 +564,31 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 }
@@ -607,6 +627,7 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text
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);
@@ -624,6 +645,22 @@ void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*w
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) {
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
@@ -52,7 +52,8 @@ protected:
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);
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
@@ -529,7 +529,6 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 {
@@ -552,6 +551,9 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 }
@@ -562,13 +564,31 @@ void IMAPwrapper::traverseBody(const RecMail&mail,mailimap_body*body,RecBody&tar
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 }
@@ -607,6 +627,7 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text
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);
@@ -624,6 +645,22 @@ void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*w
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) {
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
@@ -52,7 +52,8 @@ protected:
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);