-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 183 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 8 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 183 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 8 |
4 files changed, 318 insertions, 64 deletions
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index b0b985c..2c2a42a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp | |||
@@ -91,7 +91,9 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
91 | mailimf_message *result = 0; | 91 | mailimf_message *result = 0; |
92 | mailmessage * msg=0; | 92 | mailmessage * msg=0; |
93 | mailmime_single_fields fields; | ||
94 | |||
95 | /* is bound to msg and will be freed there */ | ||
93 | struct mailmime * mime=0; | 96 | struct mailmime * mime=0; |
94 | struct mailmime_single_fields fields; | 97 | |
95 | |||
96 | RecBody body; | 98 | RecBody body; |
97 | 99 | ||
@@ -103,11 +105,5 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
103 | } | 105 | } |
104 | 106 | ||
105 | #if 0 | ||
106 | char*body_msg = message; | 107 | char*body_msg = message; |
107 | if ( result && result->msg_body && result->msg_body->bd_text ) { | ||
108 | body_msg = (char*)result->msg_body->bd_text; | ||
109 | result->msg_body->bd_text = 0; | ||
110 | } | ||
111 | |||
112 | msg = mailmessage_new(); | 108 | msg = mailmessage_new(); |
113 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); | 109 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); |
@@ -117,31 +113,12 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
117 | msg_data->msg_message = body_msg; | 113 | msg_data->msg_message = body_msg; |
118 | msg_data->msg_length = strlen(body_msg); | 114 | msg_data->msg_length = strlen(body_msg); |
115 | |||
116 | |||
119 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 117 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
120 | err = mailmessage_get_bodystructure(msg,&mime); | 118 | err = mailmessage_get_bodystructure(msg,&mime); |
119 | traverseBody(body,msg,mime); | ||
120 | |||
121 | mailmessage_free(msg); | ||
121 | 122 | ||
122 | if (mime->mm_mime_fields != NULL) { | ||
123 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
124 | mime->mm_content_type); | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | #if 1 | ||
129 | if ( result && result->msg_body && result->msg_body->bd_text ) { | ||
130 | qDebug( "POP3: bodytext found" ); | ||
131 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | ||
132 | body.setBodytext( QString( result->msg_body->bd_text ) ); | ||
133 | #if 0 | ||
134 | curTok = 0; | ||
135 | mailmime_content*mresult = 0; | ||
136 | size_t index = 0; | ||
137 | mailmime_content_parse(result->msg_body->bd_text, | ||
138 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
139 | if (mresult) { | ||
140 | mailmime_content_free(mresult); | ||
141 | } | ||
142 | #endif | ||
143 | mailimf_message_free(result); | ||
144 | } | ||
145 | #endif | ||
146 | return body; | 123 | return body; |
147 | } | 124 | } |
@@ -457,2 +434,144 @@ encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | |||
457 | return new encodedString(); | 434 | return new encodedString(); |
458 | } | 435 | } |
436 | |||
437 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | ||
438 | { | ||
439 | if (current_rec >= 10) { | ||
440 | qDebug("too deep recursion!"); | ||
441 | } | ||
442 | if (!message || !mime) { | ||
443 | return; | ||
444 | } | ||
445 | int r; | ||
446 | char*data = 0; | ||
447 | size_t len; | ||
448 | clistiter * cur = 0; | ||
449 | mailmime_single_fields fields; | ||
450 | int res; | ||
451 | QString b; | ||
452 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
453 | RecPart part; | ||
454 | |||
455 | if (mime->mm_mime_fields != NULL) { | ||
456 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
457 | mime->mm_content_type); | ||
458 | } | ||
459 | switch (mime->mm_type) { | ||
460 | case MAILMIME_SINGLE: | ||
461 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
462 | fillSingleBody(part,message,mime); | ||
463 | if (part.Type()=="text" && target.Bodytext().isNull()) { | ||
464 | encodedString*r = new encodedString(); | ||
465 | r->setContent(data,len); | ||
466 | encodedString*res = decode_String(r,part.Encoding()); | ||
467 | b = QString(res->Content()); | ||
468 | delete r; | ||
469 | delete res; | ||
470 | target.setBodytext(b); | ||
471 | target.setDescription(part); | ||
472 | } else { | ||
473 | /* TODO: Add the content to a list and store it for later use */ | ||
474 | if (data) free(data); | ||
475 | target.addPart(part); | ||
476 | } | ||
477 | break; | ||
478 | case MAILMIME_MULTIPLE: | ||
479 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | ||
480 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | ||
481 | } | ||
482 | break; | ||
483 | case MAILMIME_MESSAGE: | ||
484 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | ||
485 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | ||
486 | } | ||
487 | break; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) | ||
492 | { | ||
493 | QString enc="7bit"; | ||
494 | if (!aEnc) return enc; | ||
495 | switch(aEnc->enc_type) { | ||
496 | case MAILMIME_MECHANISM_7BIT: | ||
497 | enc = "7bit"; | ||
498 | break; | ||
499 | case MAILMIME_MECHANISM_8BIT: | ||
500 | enc = "8bit"; | ||
501 | break; | ||
502 | case MAILMIME_MECHANISM_BINARY: | ||
503 | enc = "binary"; | ||
504 | break; | ||
505 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | ||
506 | enc = "quoted-printable"; | ||
507 | break; | ||
508 | case MAILMIME_MECHANISM_BASE64: | ||
509 | enc = "base64"; | ||
510 | break; | ||
511 | case MAILMIME_MECHANISM_TOKEN: | ||
512 | default: | ||
513 | if (aEnc->enc_token) { | ||
514 | enc = QString(aEnc->enc_token); | ||
515 | } | ||
516 | break; | ||
517 | } | ||
518 | return enc; | ||
519 | } | ||
520 | |||
521 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | ||
522 | { | ||
523 | if (!mime) { | ||
524 | return; | ||
525 | } | ||
526 | mailmime_content*type = mime->mm_content_type; | ||
527 | mailmime_field*field = 0; | ||
528 | clistcell*current; | ||
529 | if (!type) { | ||
530 | target.setType("text"); | ||
531 | target.setSubtype("plain"); | ||
532 | } else { | ||
533 | target.setSubtype(type->ct_subtype); | ||
534 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | ||
535 | case MAILMIME_DISCRETE_TYPE_TEXT: | ||
536 | target.setType("text"); | ||
537 | break; | ||
538 | case MAILMIME_DISCRETE_TYPE_IMAGE: | ||
539 | target.setType("image"); | ||
540 | break; | ||
541 | case MAILMIME_DISCRETE_TYPE_AUDIO: | ||
542 | target.setType("audio"); | ||
543 | break; | ||
544 | case MAILMIME_DISCRETE_TYPE_VIDEO: | ||
545 | target.setType("video"); | ||
546 | break; | ||
547 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | ||
548 | target.setType("application"); | ||
549 | break; | ||
550 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | ||
551 | default: | ||
552 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | ||
553 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | ||
554 | } | ||
555 | break; | ||
556 | } | ||
557 | } | ||
558 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | ||
559 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | ||
560 | field = (mailmime_field*)current->data; | ||
561 | switch(field->fld_type) { | ||
562 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
563 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | ||
564 | break; | ||
565 | case MAILMIME_FIELD_ID: | ||
566 | target.setIdentifier(field->fld_data.fld_id); | ||
567 | break; | ||
568 | case MAILMIME_FIELD_DESCRIPTION: | ||
569 | target.setDescription(field->fld_data.fld_description); | ||
570 | break; | ||
571 | default: | ||
572 | break; | ||
573 | } | ||
574 | } | ||
575 | } | ||
576 | // TODO search the parameter list for unique id and so on | ||
577 | } | ||
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index a05021c..4171a76 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h | |||
@@ -9,4 +9,7 @@ class RecBody; | |||
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailpop3; | 10 | struct mailpop3; |
11 | struct mailmessage; | ||
12 | struct mailmime; | ||
13 | struct mailmime_mechanism; | ||
11 | 14 | ||
12 | class POP3wrapper : public AbstractMail | 15 | class POP3wrapper : public AbstractMail |
@@ -41,4 +44,9 @@ protected: | |||
41 | QString parseAddressList( mailimf_address_list *list ); | 44 | QString parseAddressList( mailimf_address_list *list ); |
42 | QString parseDateTime( mailimf_date_time *date ); | 45 | QString parseDateTime( mailimf_date_time *date ); |
46 | |||
47 | static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | ||
48 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | ||
49 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); | ||
50 | |||
43 | POP3account *account; | 51 | POP3account *account; |
44 | mailpop3 *m_pop3; | 52 | mailpop3 *m_pop3; |
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index b0b985c..2c2a42a 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp | |||
@@ -91,7 +91,9 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
91 | mailimf_message *result = 0; | 91 | mailimf_message *result = 0; |
92 | mailmessage * msg=0; | 92 | mailmessage * msg=0; |
93 | mailmime_single_fields fields; | ||
94 | |||
95 | /* is bound to msg and will be freed there */ | ||
93 | struct mailmime * mime=0; | 96 | struct mailmime * mime=0; |
94 | struct mailmime_single_fields fields; | 97 | |
95 | |||
96 | RecBody body; | 98 | RecBody body; |
97 | 99 | ||
@@ -103,11 +105,5 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
103 | } | 105 | } |
104 | 106 | ||
105 | #if 0 | ||
106 | char*body_msg = message; | 107 | char*body_msg = message; |
107 | if ( result && result->msg_body && result->msg_body->bd_text ) { | ||
108 | body_msg = (char*)result->msg_body->bd_text; | ||
109 | result->msg_body->bd_text = 0; | ||
110 | } | ||
111 | |||
112 | msg = mailmessage_new(); | 108 | msg = mailmessage_new(); |
113 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); | 109 | mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); |
@@ -117,31 +113,12 @@ RecBody POP3wrapper::parseMail( char *message ) | |||
117 | msg_data->msg_message = body_msg; | 113 | msg_data->msg_message = body_msg; |
118 | msg_data->msg_length = strlen(body_msg); | 114 | msg_data->msg_length = strlen(body_msg); |
115 | |||
116 | |||
119 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | 117 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); |
120 | err = mailmessage_get_bodystructure(msg,&mime); | 118 | err = mailmessage_get_bodystructure(msg,&mime); |
119 | traverseBody(body,msg,mime); | ||
120 | |||
121 | mailmessage_free(msg); | ||
121 | 122 | ||
122 | if (mime->mm_mime_fields != NULL) { | ||
123 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
124 | mime->mm_content_type); | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | #if 1 | ||
129 | if ( result && result->msg_body && result->msg_body->bd_text ) { | ||
130 | qDebug( "POP3: bodytext found" ); | ||
131 | // when curTok isn't set to 0 this line will fault! 'cause upper line faults! | ||
132 | body.setBodytext( QString( result->msg_body->bd_text ) ); | ||
133 | #if 0 | ||
134 | curTok = 0; | ||
135 | mailmime_content*mresult = 0; | ||
136 | size_t index = 0; | ||
137 | mailmime_content_parse(result->msg_body->bd_text, | ||
138 | strlen(result->msg_body->bd_text),&index,&mresult); | ||
139 | if (mresult) { | ||
140 | mailmime_content_free(mresult); | ||
141 | } | ||
142 | #endif | ||
143 | mailimf_message_free(result); | ||
144 | } | ||
145 | #endif | ||
146 | return body; | 123 | return body; |
147 | } | 124 | } |
@@ -457,2 +434,144 @@ encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&) | |||
457 | return new encodedString(); | 434 | return new encodedString(); |
458 | } | 435 | } |
436 | |||
437 | void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) | ||
438 | { | ||
439 | if (current_rec >= 10) { | ||
440 | qDebug("too deep recursion!"); | ||
441 | } | ||
442 | if (!message || !mime) { | ||
443 | return; | ||
444 | } | ||
445 | int r; | ||
446 | char*data = 0; | ||
447 | size_t len; | ||
448 | clistiter * cur = 0; | ||
449 | mailmime_single_fields fields; | ||
450 | int res; | ||
451 | QString b; | ||
452 | memset(&fields, 0, sizeof(struct mailmime_single_fields)); | ||
453 | RecPart part; | ||
454 | |||
455 | if (mime->mm_mime_fields != NULL) { | ||
456 | mailmime_single_fields_init(&fields, mime->mm_mime_fields, | ||
457 | mime->mm_content_type); | ||
458 | } | ||
459 | switch (mime->mm_type) { | ||
460 | case MAILMIME_SINGLE: | ||
461 | r = mailmessage_fetch_section(message,mime,&data,&len); | ||
462 | fillSingleBody(part,message,mime); | ||
463 | if (part.Type()=="text" && target.Bodytext().isNull()) { | ||
464 | encodedString*r = new encodedString(); | ||
465 | r->setContent(data,len); | ||
466 | encodedString*res = decode_String(r,part.Encoding()); | ||
467 | b = QString(res->Content()); | ||
468 | delete r; | ||
469 | delete res; | ||
470 | target.setBodytext(b); | ||
471 | target.setDescription(part); | ||
472 | } else { | ||
473 | /* TODO: Add the content to a list and store it for later use */ | ||
474 | if (data) free(data); | ||
475 | target.addPart(part); | ||
476 | } | ||
477 | break; | ||
478 | case MAILMIME_MULTIPLE: | ||
479 | for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { | ||
480 | traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); | ||
481 | } | ||
482 | break; | ||
483 | case MAILMIME_MESSAGE: | ||
484 | if (mime->mm_data.mm_message.mm_msg_mime != NULL) { | ||
485 | traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); | ||
486 | } | ||
487 | break; | ||
488 | } | ||
489 | } | ||
490 | |||
491 | QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) | ||
492 | { | ||
493 | QString enc="7bit"; | ||
494 | if (!aEnc) return enc; | ||
495 | switch(aEnc->enc_type) { | ||
496 | case MAILMIME_MECHANISM_7BIT: | ||
497 | enc = "7bit"; | ||
498 | break; | ||
499 | case MAILMIME_MECHANISM_8BIT: | ||
500 | enc = "8bit"; | ||
501 | break; | ||
502 | case MAILMIME_MECHANISM_BINARY: | ||
503 | enc = "binary"; | ||
504 | break; | ||
505 | case MAILMIME_MECHANISM_QUOTED_PRINTABLE: | ||
506 | enc = "quoted-printable"; | ||
507 | break; | ||
508 | case MAILMIME_MECHANISM_BASE64: | ||
509 | enc = "base64"; | ||
510 | break; | ||
511 | case MAILMIME_MECHANISM_TOKEN: | ||
512 | default: | ||
513 | if (aEnc->enc_token) { | ||
514 | enc = QString(aEnc->enc_token); | ||
515 | } | ||
516 | break; | ||
517 | } | ||
518 | return enc; | ||
519 | } | ||
520 | |||
521 | void POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) | ||
522 | { | ||
523 | if (!mime) { | ||
524 | return; | ||
525 | } | ||
526 | mailmime_content*type = mime->mm_content_type; | ||
527 | mailmime_field*field = 0; | ||
528 | clistcell*current; | ||
529 | if (!type) { | ||
530 | target.setType("text"); | ||
531 | target.setSubtype("plain"); | ||
532 | } else { | ||
533 | target.setSubtype(type->ct_subtype); | ||
534 | switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { | ||
535 | case MAILMIME_DISCRETE_TYPE_TEXT: | ||
536 | target.setType("text"); | ||
537 | break; | ||
538 | case MAILMIME_DISCRETE_TYPE_IMAGE: | ||
539 | target.setType("image"); | ||
540 | break; | ||
541 | case MAILMIME_DISCRETE_TYPE_AUDIO: | ||
542 | target.setType("audio"); | ||
543 | break; | ||
544 | case MAILMIME_DISCRETE_TYPE_VIDEO: | ||
545 | target.setType("video"); | ||
546 | break; | ||
547 | case MAILMIME_DISCRETE_TYPE_APPLICATION: | ||
548 | target.setType("application"); | ||
549 | break; | ||
550 | case MAILMIME_DISCRETE_TYPE_EXTENSION: | ||
551 | default: | ||
552 | if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { | ||
553 | target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); | ||
554 | } | ||
555 | break; | ||
556 | } | ||
557 | } | ||
558 | if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { | ||
559 | for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { | ||
560 | field = (mailmime_field*)current->data; | ||
561 | switch(field->fld_type) { | ||
562 | case MAILMIME_FIELD_TRANSFER_ENCODING: | ||
563 | target.setEncoding(getencoding(field->fld_data.fld_encoding)); | ||
564 | break; | ||
565 | case MAILMIME_FIELD_ID: | ||
566 | target.setIdentifier(field->fld_data.fld_id); | ||
567 | break; | ||
568 | case MAILMIME_FIELD_DESCRIPTION: | ||
569 | target.setDescription(field->fld_data.fld_description); | ||
570 | break; | ||
571 | default: | ||
572 | break; | ||
573 | } | ||
574 | } | ||
575 | } | ||
576 | // TODO search the parameter list for unique id and so on | ||
577 | } | ||
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index a05021c..4171a76 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h | |||
@@ -9,4 +9,7 @@ class RecBody; | |||
9 | class encodedString; | 9 | class encodedString; |
10 | struct mailpop3; | 10 | struct mailpop3; |
11 | struct mailmessage; | ||
12 | struct mailmime; | ||
13 | struct mailmime_mechanism; | ||
11 | 14 | ||
12 | class POP3wrapper : public AbstractMail | 15 | class POP3wrapper : public AbstractMail |
@@ -41,4 +44,9 @@ protected: | |||
41 | QString parseAddressList( mailimf_address_list *list ); | 44 | QString parseAddressList( mailimf_address_list *list ); |
42 | QString parseDateTime( mailimf_date_time *date ); | 45 | QString parseDateTime( mailimf_date_time *date ); |
46 | |||
47 | static void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); | ||
48 | static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); | ||
49 | static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); | ||
50 | |||
43 | POP3account *account; | 51 | POP3account *account; |
44 | mailpop3 *m_pop3; | 52 | mailpop3 *m_pop3; |