-rw-r--r-- | noncore/net/mail/genericwrapper.cpp | 47 | ||||
-rw-r--r-- | noncore/net/mail/genericwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 47 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 2 |
4 files changed, 78 insertions, 20 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp index bef6ae5..5de9299 100644 --- a/noncore/net/mail/genericwrapper.cpp +++ b/noncore/net/mail/genericwrapper.cpp @@ -102,107 +102,136 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) enc = "7bit"; break; case MAILMIME_MECHANISM_8BIT: enc = "8bit"; break; case MAILMIME_MECHANISM_BINARY: enc = "binary"; break; case MAILMIME_MECHANISM_QUOTED_PRINTABLE: enc = "quoted-printable"; break; case MAILMIME_MECHANISM_BASE64: enc = "base64"; break; case MAILMIME_MECHANISM_TOKEN: default: if (aEnc->enc_token) { enc = QString(aEnc->enc_token); } break; } return enc; } -void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) +void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) { if (current_rec >= 10) { qDebug("too deep recursion!"); } if (!message || !mime) { return; } int r; char*data = 0; size_t len; clistiter * cur = 0; QString b; RecPart part; + //current_count; + switch (mime->mm_type) { case MAILMIME_SINGLE: + { + QValueList<int>countlist = recList; + countlist.append(current_count); r = mailmessage_fetch_section(message,mime,&data,&len); part.setSize(len); + part.setPositionlist(countlist); + b = gen_attachment_id(); + part.setIdentifier(b); fillSingleBody(part,message,mime); if (part.Type()=="text" && target.Bodytext().isNull()) { encodedString*r = new encodedString(); r->setContent(data,len); encodedString*res = decode_String(r,part.Encoding()); b = QString(res->Content()); delete r; delete res; target.setBodytext(b); target.setDescription(part); } else { - b = gen_attachment_id(); - part.setIdentifier(b); bodyCache[b]=new encodedString(data,len); target.addPart(part); } - break; + } + break; case MAILMIME_MULTIPLE: + { + unsigned int ccount = current_count; for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { - traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); + traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount); + ++ccount; } - break; + } + break; case MAILMIME_MESSAGE: + { + QValueList<int>countlist = recList; + countlist.append(current_count); + /* the own header is always at recursion 0 - we don't need that */ + if (current_rec > 0) { + part.setPositionlist(countlist); + r = mailmessage_fetch_section(message,mime,&data,&len); + part.setSize(len); + part.setPositionlist(countlist); + b = gen_attachment_id(); + part.setIdentifier(b); + part.setType("message"); + part.setSubtype("rfc822"); + bodyCache[b]=new encodedString(data,len); + target.addPart(part); + } if (mime->mm_data.mm_message.mm_msg_mime != NULL) { - traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); + traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); } - break; + } + break; } } RecBody Genericwrapper::parseMail( mailmessage * msg ) { int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBody body; memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); - traverseBody(body,msg,mime); + QValueList<int>recList; + traverseBody(body,msg,mime,recList); return body; } RecMail *Genericwrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok = 0; RecMail *mail = new RecMail(); mailimf_fields *fields = 0; mailimf_references * refs = 0; mailimf_keywords*keys = 0; QString status; QString value; QBitArray mFlags(7); err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h index 54d6ea9..c00d864 100644 --- a/noncore/net/mail/genericwrapper.h +++ b/noncore/net/mail/genericwrapper.h @@ -24,36 +24,36 @@ struct mailsession; * mbox and pop3 (later mh, too) mail access. * it is not desigend to make a instance of it! */ class Genericwrapper : public AbstractMail { Q_OBJECT public: Genericwrapper(); virtual ~Genericwrapper(); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual void cleanMimeCache(); protected: RecMail *parseHeader( const char *header ); RecBody parseMail( mailmessage * msg ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); QString parseDateTime( mailimf_date_time *date ); - void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); + void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=0); static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); static void fillParameters(RecPart&target,clist*parameters); static QString getencoding(mailmime_mechanism*aEnc); virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); QString msgTempName; unsigned int last_msg_id; QMap<QString,encodedString*> bodyCache; }; #endif diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp index bef6ae5..5de9299 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp @@ -102,107 +102,136 @@ QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) enc = "7bit"; break; case MAILMIME_MECHANISM_8BIT: enc = "8bit"; break; case MAILMIME_MECHANISM_BINARY: enc = "binary"; break; case MAILMIME_MECHANISM_QUOTED_PRINTABLE: enc = "quoted-printable"; break; case MAILMIME_MECHANISM_BASE64: enc = "base64"; break; case MAILMIME_MECHANISM_TOKEN: default: if (aEnc->enc_token) { enc = QString(aEnc->enc_token); } break; } return enc; } -void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) +void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rec,int current_count) { if (current_rec >= 10) { qDebug("too deep recursion!"); } if (!message || !mime) { return; } int r; char*data = 0; size_t len; clistiter * cur = 0; QString b; RecPart part; + //current_count; + switch (mime->mm_type) { case MAILMIME_SINGLE: + { + QValueList<int>countlist = recList; + countlist.append(current_count); r = mailmessage_fetch_section(message,mime,&data,&len); part.setSize(len); + part.setPositionlist(countlist); + b = gen_attachment_id(); + part.setIdentifier(b); fillSingleBody(part,message,mime); if (part.Type()=="text" && target.Bodytext().isNull()) { encodedString*r = new encodedString(); r->setContent(data,len); encodedString*res = decode_String(r,part.Encoding()); b = QString(res->Content()); delete r; delete res; target.setBodytext(b); target.setDescription(part); } else { - b = gen_attachment_id(); - part.setIdentifier(b); bodyCache[b]=new encodedString(data,len); target.addPart(part); } - break; + } + break; case MAILMIME_MULTIPLE: + { + unsigned int ccount = current_count; for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) { - traverseBody(target,message, (mailmime*)clist_content(cur),current_rec+1); + traverseBody(target,message, (mailmime*)clist_content(cur),recList,current_rec+1,ccount); + ++ccount; } - break; + } + break; case MAILMIME_MESSAGE: + { + QValueList<int>countlist = recList; + countlist.append(current_count); + /* the own header is always at recursion 0 - we don't need that */ + if (current_rec > 0) { + part.setPositionlist(countlist); + r = mailmessage_fetch_section(message,mime,&data,&len); + part.setSize(len); + part.setPositionlist(countlist); + b = gen_attachment_id(); + part.setIdentifier(b); + part.setType("message"); + part.setSubtype("rfc822"); + bodyCache[b]=new encodedString(data,len); + target.addPart(part); + } if (mime->mm_data.mm_message.mm_msg_mime != NULL) { - traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); + traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); } - break; + } + break; } } RecBody Genericwrapper::parseMail( mailmessage * msg ) { int err = MAILIMF_NO_ERROR; mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBody body; memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); - traverseBody(body,msg,mime); + QValueList<int>recList; + traverseBody(body,msg,mime,recList); return body; } RecMail *Genericwrapper::parseHeader( const char *header ) { int err = MAILIMF_NO_ERROR; size_t curTok = 0; RecMail *mail = new RecMail(); mailimf_fields *fields = 0; mailimf_references * refs = 0; mailimf_keywords*keys = 0; QString status; QString value; QBitArray mFlags(7); err = mailimf_fields_parse( (char *) header, strlen( header ), &curTok, &fields ); for ( clistiter *current = clist_begin( fields->fld_list ); current != NULL; current = current->next ) { mailimf_field *field = (mailimf_field *) current->data; switch ( field->fld_type ) { case MAILIMF_FIELD_FROM: mail->setFrom( parseMailboxList( field->fld_data.fld_from->frm_mb_list ) ); break; case MAILIMF_FIELD_TO: mail->setTo( parseAddressList( field->fld_data.fld_to->to_addr_list ) ); diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h index 54d6ea9..c00d864 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.h +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h @@ -24,36 +24,36 @@ struct mailsession; * mbox and pop3 (later mh, too) mail access. * it is not desigend to make a instance of it! */ class Genericwrapper : public AbstractMail { Q_OBJECT public: Genericwrapper(); virtual ~Genericwrapper(); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual void cleanMimeCache(); protected: RecMail *parseHeader( const char *header ); RecBody parseMail( mailmessage * msg ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); QString parseDateTime( mailimf_date_time *date ); - void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); + void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=0); static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); static void fillParameters(RecPart&target,clist*parameters); static QString getencoding(mailmime_mechanism*aEnc); virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox); QString msgTempName; unsigned int last_msg_id; QMap<QString,encodedString*> bodyCache; }; #endif |