summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/imapwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp143
1 files changed, 76 insertions, 67 deletions
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index fa967da..da5974c 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -375,9 +375,12 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
375 } 375 }
376 QString sub; 376 QString sub,body_text;
377 RecPart singlePart;
378 QValueList<int> path;
379 fillSinglePart(singlePart,mailDescription);
377 switch (mailDescription->bd_type) { 380 switch (mailDescription->bd_type) {
378 case MAILIMAP_BODY_TYPE_1PART_MSG: 381 case MAILIMAP_BODY_TYPE_1PART_MSG:
379 target_body.setType("text"); 382 path.append(1);
380 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 383 body_text = fetchPart(mail,path,true);
381 target_body.setSubtype(sub.lower()); 384 target_body.setBodytext(body_text);
382 fillPlainBody(mail,target_body); 385 target_body.setDescription(singlePart);
383 break; 386 break;
@@ -385,6 +388,11 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
385 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text); 388 qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
386 target_body.setType("text"); 389 path.append(1);
387 sub = mailDescription->bd_data.bd_type_text->bd_media_text; 390 body_text = fetchPart(mail,path,true);
388 target_body.setSubtype(sub.lower()); 391 target_body.setBodytext(body_text);
389 fillPlainBody(mail,target_body); 392 target_body.setDescription(singlePart);
393 break;
394 case MAILIMAP_BODY_TYPE_1PART_BASIC:
395 qDebug("Single attachment");
396 target_body.setBodytext("");
397 target_body.addPart(singlePart);
390 break; 398 break;
@@ -393,57 +401,3 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
393 } 401 }
394 return;
395}
396
397void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
398{
399 const char *mb;
400 QString body="";
401 int err = MAILIMAP_NO_ERROR;
402 clist *result;
403 clistcell *current,*cur;
404 mailimap_fetch_att *fetchAtt;
405 mailimap_fetch_type *fetchType;
406 mailimap_set *set;
407
408 mb = mail.getMbox().latin1();
409
410 if (!m_imap) {
411 return;
412 }
413
414 result = clist_new();
415 set = set = mailimap_set_new_single(mail.getNumber());
416 mailimap_section * section = mailimap_section_new_text();
417 fetchAtt = mailimap_fetch_att_new_body_peek_section(section);
418 fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
419 err = mailimap_fetch( m_imap, set, fetchType, &result );
420 mailimap_set_free( set );
421 mailimap_fetch_type_free( fetchType );
422
423 402
424 if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
425 mailimap_msg_att * msg_att;
426 msg_att = (mailimap_msg_att*)current->data;
427 mailimap_msg_att_item*msg_att_item;
428 for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
429 msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
430 if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
431 if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
432 char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
433 msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
434 if (text) {
435 body = QString(text);
436 free(text);
437 } else {
438 body = "";
439 }
440 }
441 }
442 }
443
444 } else {
445 qDebug("error fetching text: %s",m_imap->imap_response);
446 }
447 mailimap_fetch_list_free(result);
448 target_body.setBodytext(body);
449 return; 403 return;
@@ -492,3 +446,3 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
492 446
493QString IMAPwrapper::fetchPart(const RecMail&mail,QValueList<int>&path,bool internal_call) 447QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
494{ 448{
@@ -586,5 +540,4 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
586 QString body_text = fetchPart(mail,clist,true); 540 QString body_text = fetchPart(mail,clist,true);
541 target_body.setDescription(currentPart);
587 target_body.setBodytext(body_text); 542 target_body.setBodytext(body_text);
588 target_body.setType(currentPart.Type());
589 target_body.setSubtype(currentPart.Subtype());
590 } else { 543 } else {
@@ -592,3 +545,3 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
592 for (unsigned int j = 0; j < clist.count();++j) { 545 for (unsigned int j = 0; j < clist.count();++j) {
593 id+=(j>0?".":""); 546 id+=(j>0?" ":"");
594 id+=QString("%1").arg(clist[j]); 547 id+=QString("%1").arg(clist[j]);
@@ -597,2 +550,3 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
597 currentPart.setIdentifier(id); 550 currentPart.setIdentifier(id);
551 currentPart.setPositionlist(clist);
598 target_body.addPart(currentPart); 552 target_body.addPart(currentPart);
@@ -616,2 +570,5 @@ void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*De
616 break; 570 break;
571 case MAILIMAP_BODY_TYPE_1PART_MSG:
572 fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
573 break;
617 default: 574 default:
@@ -633,2 +590,18 @@ void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text
633 590
591void IMAPwrapper::fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which)
592{
593 if (!which) {
594 return;
595 }
596// QString sub;
597// sub = which->bd_media_text;
598// target_part.setSubtype(sub.lower());
599 qDebug("Message part");
600 /* we set this type to text/plain */
601 target_part.setType("text");
602 target_part.setSubtype("plain");
603 target_part.setLines(which->bd_lines);
604 fillBodyFields(target_part,which->bd_fields);
605}
606
634void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which) 607void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
@@ -682,3 +655,39 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
682 param = (mailimap_single_body_fld_param*)cur->data; 655 param = (mailimap_single_body_fld_param*)cur->data;
656 if (param) {
657 target_part.addParameter(QString(param->pa_name).lower(),QString(param->pa_value));
658 }
683 } 659 }
660 mailimap_body_fld_enc*enc = which->bd_encoding;
661 QString encoding("");
662 switch (enc->enc_type) {
663 case MAILIMAP_BODY_FLD_ENC_7BIT:
664 encoding = "7bit";
665 break;
666 case MAILIMAP_BODY_FLD_ENC_8BIT:
667 encoding = "8bit";
668 break;
669 case MAILIMAP_BODY_FLD_ENC_BINARY:
670 encoding="binary";
671 break;
672 case MAILIMAP_BODY_FLD_ENC_BASE64:
673 encoding="base64";
674 break;
675 case MAILIMAP_BODY_FLD_ENC_QUOTED_PRINTABLE:
676 encoding="quoted-printable";
677 break;
678 case MAILIMAP_BODY_FLD_ENC_OTHER:
679 default:
680 if (enc->enc_value) {
681 char*t=enc->enc_value;
682 encoding=QString(enc->enc_value);
683 enc->enc_value=0L;
684 free(t);
685 }
686 }
687 target_part.setEncoding(encoding);
688}
689
690QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
691{
692 return fetchPart(mail,part.Positionlist(),false);
684} 693}