Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.cpp | 393 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 59 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 412 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 43 |
6 files changed, 476 insertions, 440 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 3cb8f7d..416795b 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp @@ -3,2 +3,3 @@ #include "pop3wrapper.h" +#include "mboxwrapper.h" #include "mailtypes.h" @@ -22,2 +23,7 @@ AbstractMail* AbstractMail::getWrapper(POP3account *a) +AbstractMail* AbstractMail::getWrapper(const QString&a) +{ + return new MBOXwrapper(a); +} + encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc) diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 8dd2e12..509b68e 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -29,2 +29,3 @@ public: virtual void answeredMail(const RecMail&mail)=0; + virtual void cleanMimeCache(){}; @@ -32,2 +33,4 @@ public: static AbstractMail* getWrapper(POP3account *a); + /* mbox only! */ + static AbstractMail* getWrapper(const QString&a); diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp new file mode 100644 index 0000000..447cad0 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp @@ -0,0 +1,393 @@ +#include "genericwrapper.h" +#include <libetpan/mailmime.h> +#include <libetpan/data_message_driver.h> +#include "mailtypes.h" + +Genericwrapper::Genericwrapper() + : AbstractMail() +{ + bodyCache.clear(); +} + +Genericwrapper::~Genericwrapper() +{ + cleanMimeCache(); +} + +void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) +{ + if (!mime) { + return; + } + mailmime_field*field = 0; + mailmime_single_fields fields; + memset(&fields, 0, sizeof(struct mailmime_single_fields)); + if (mime->mm_mime_fields != NULL) { + mailmime_single_fields_init(&fields, mime->mm_mime_fields, + mime->mm_content_type); + } + + mailmime_content*type = fields.fld_content; + clistcell*current; + if (!type) { + target.setType("text"); + target.setSubtype("plain"); + } else { + target.setSubtype(type->ct_subtype); + switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { + case MAILMIME_DISCRETE_TYPE_TEXT: + target.setType("text"); + break; + case MAILMIME_DISCRETE_TYPE_IMAGE: + target.setType("image"); + break; + case MAILMIME_DISCRETE_TYPE_AUDIO: + target.setType("audio"); + break; + case MAILMIME_DISCRETE_TYPE_VIDEO: + target.setType("video"); + break; + case MAILMIME_DISCRETE_TYPE_APPLICATION: + target.setType("application"); + break; + case MAILMIME_DISCRETE_TYPE_EXTENSION: + default: + if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { + target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); + } + break; + } + if (type->ct_parameters) { + fillParameters(target,type->ct_parameters); + } + } + if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { + for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { + field = (mailmime_field*)current->data; + switch(field->fld_type) { + case MAILMIME_FIELD_TRANSFER_ENCODING: + target.setEncoding(getencoding(field->fld_data.fld_encoding)); + break; + case MAILMIME_FIELD_ID: + target.setIdentifier(field->fld_data.fld_id); + break; + case MAILMIME_FIELD_DESCRIPTION: + target.setDescription(field->fld_data.fld_description); + break; + default: + break; + } + } + } +} + +void Genericwrapper::fillParameters(RecPart&target,clist*parameters) +{ + if (!parameters) {return;} + clistcell*current=0; + mailmime_parameter*param; + for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { + param = (mailmime_parameter*)current->data; + if (param) { + target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); + } + } +} + +QString Genericwrapper::getencoding(mailmime_mechanism*aEnc) +{ + QString enc="7bit"; + if (!aEnc) return enc; + switch(aEnc->enc_type) { + case MAILMIME_MECHANISM_7BIT: + 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) +{ + 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; + + switch (mime->mm_type) { + case MAILMIME_SINGLE: + r = mailmessage_fetch_section(message,mime,&data,&len); + part.setSize(len); + 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; + case MAILMIME_MULTIPLE: + 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); + } + break; + case MAILMIME_MESSAGE: + if (mime->mm_data.mm_message.mm_msg_mime != NULL) { + traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); + } + 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); + return body; +} + +RecMail *Genericwrapper::parseHeader( const char *header ) +{ + int err = MAILIMF_NO_ERROR; + size_t curTok = 0; + RecMail *mail = new RecMail(); + mailimf_fields *fields; + mailimf_references * refs; + mailimf_keywords*keys; + 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 ) ); + break; + case MAILIMF_FIELD_CC: + mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); + break; + case MAILIMF_FIELD_BCC: + mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); + break; + case MAILIMF_FIELD_SUBJECT: + mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); + break; + case MAILIMF_FIELD_ORIG_DATE: + mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); + break; + case MAILIMF_FIELD_MESSAGE_ID: + mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); + break; + case MAILIMF_FIELD_REFERENCES: + refs = field->fld_data.fld_references; + if (refs && refs->mid_list && clist_count(refs->mid_list)) { + char * text = (char*)refs->mid_list->first->data; + mail->setReplyto(QString(text)); + } + break; + case MAILIMF_FIELD_KEYWORDS: + keys = field->fld_data.fld_keywords; + for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { + qDebug("Keyword: %s",(char*)cur->data); + } + break; + case MAILIMF_FIELD_OPTIONAL_FIELD: + status = field->fld_data.fld_optional_field->fld_name; + value = field->fld_data.fld_optional_field->fld_value; + if (status.lower()=="status") { + if (value.lower()=="ro") { + mFlags.setBit(FLAG_SEEN); + } + } else if (status.lower()=="x-status") { + qDebug("X-Status: %s",value.latin1()); + if (value.lower()=="a") { + mFlags.setBit(FLAG_ANSWERED); + } + } else { +// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, +// field->fld_data.fld_optional_field->fld_value); + } + break; + default: + qDebug("Non parsed field"); + break; + } + } + if (fields) mailimf_fields_free(fields); + mail->setFlags(mFlags); + return mail; +} + +QString Genericwrapper::parseDateTime( mailimf_date_time *date ) +{ + char tmp[23]; + + snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", + date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); + + return QString( tmp ); +} + +QString Genericwrapper::parseAddressList( mailimf_address_list *list ) +{ + QString result( "" ); + + bool first = true; + if (list == 0) return result; + for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { + mailimf_address *addr = (mailimf_address *) current->data; + + if ( !first ) { + result.append( "," ); + } else { + first = false; + } + + switch ( addr->ad_type ) { + case MAILIMF_ADDRESS_MAILBOX: + result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); + break; + case MAILIMF_ADDRESS_GROUP: + result.append( parseGroup( addr->ad_data.ad_group ) ); + break; + default: + qDebug( "Generic: unkown mailimf address type" ); + break; + } + } + + return result; +} + +QString Genericwrapper::parseGroup( mailimf_group *group ) +{ + QString result( "" ); + + result.append( group->grp_display_name ); + result.append( ": " ); + + if ( group->grp_mb_list != NULL ) { + result.append( parseMailboxList( group->grp_mb_list ) ); + } + + result.append( ";" ); + + return result; +} + +QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) +{ + QString result( "" ); + + if ( box->mb_display_name == NULL ) { + result.append( box->mb_addr_spec ); + } else { + result.append( convert_String(box->mb_display_name).latin1() ); + result.append( " <" ); + result.append( box->mb_addr_spec ); + result.append( ">" ); + } + + return result; +} + +QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) +{ + QString result( "" ); + + bool first = true; + for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { + mailimf_mailbox *box = (mailimf_mailbox *) current->data; + + if ( !first ) { + result.append( "," ); + } else { + first = false; + } + + result.append( parseMailbox( box ) ); + } + + return result; +} + +encodedString* Genericwrapper::fetchDecodedPart(const RecMail&,const RecPart&part) +{ + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = decode_String(it.data(),part.Encoding()); + return t; +} + +encodedString* Genericwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) +{ + QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); + if (it==bodyCache.end()) return new encodedString(); + encodedString*t = it.data(); + return t; +} + +QString Genericwrapper::fetchTextPart(const RecMail&mail,const RecPart&part) +{ + encodedString*t = fetchDecodedPart(mail,part); + QString text=t->Content(); + delete t; + return text; +} + +void Genericwrapper::cleanMimeCache() +{ + QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); + for (;it!=bodyCache.end();++it) { + encodedString*t = it.data(); + //it.setValue(0); + if (t) delete t; + } + bodyCache.clear(); + qDebug("Genericwrapper: cache cleaned"); +} diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h new file mode 100644 index 0000000..12f6928 --- a/dev/null +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h @@ -0,0 +1,59 @@ +#ifndef __GENERIC_WRAPPER_H +#define __GENERIC_WRAPPER_H + +#include "abstractmail.h" +#include <qmap.h> +#include <qstring.h> +#include <libetpan/clist.h> + +class RecMail; +class RecBody; +class encodedString; +struct mailpop3; +struct mailmessage; +struct mailmime; +struct mailmime_mechanism; +struct mailimf_mailbox_list; +struct mailimf_mailbox; +struct mailimf_date_time; +struct mailimf_group; +struct mailimf_address_list; + +/* this class hold just the funs shared between + * 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); + static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); + static void fillParameters(RecPart&target,clist*parameters); + static QString getencoding(mailmime_mechanism*aEnc); + + POP3account *account; + mailpop3 *m_pop3; + QString msgTempName; + unsigned int last_msg_id; + QMap<QString,encodedString*> bodyCache; +}; + +#endif diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index d3447f4..efd83ba 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -13,2 +13,3 @@ POP3wrapper::POP3wrapper( POP3account *a ) + : Genericwrapper() { @@ -18,3 +19,2 @@ POP3wrapper::POP3wrapper( POP3account *a ) last_msg_id = 0; - bodyCache.clear(); } @@ -28,14 +28,2 @@ POP3wrapper::~POP3wrapper() } - cleanUpCache(); -} - -void POP3wrapper::cleanUpCache() -{ - QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); - for (;it!=bodyCache.end();++it) { - encodedString*t = it.data(); - //it.setValue(0); - if (t) delete t; - } - bodyCache.clear(); } @@ -59,2 +47,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) RecBody body; + mailmessage * msg = 0; @@ -66,3 +55,3 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } - cleanUpCache(); + cleanMimeCache(); if (mail.getNumber()!=last_msg_id) { @@ -94,31 +83,6 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) } - body = parseMail(message); - free(message); - return body; -} - -RecBody POP3wrapper::parseMail( char *message ) -{ - int err = MAILIMF_NO_ERROR; - /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ - size_t curTok = 0; - mailimf_message *result = 0; - mailmessage * msg=0; - mailmime_single_fields fields; - - /* is bound to msg and will be freed there */ - struct mailmime * mime=0; - - RecBody body; - - - err = mailimf_message_parse( (char *) message, strlen( message ), &curTok, &result ); - if ( err != MAILIMF_NO_ERROR ) { - if (result) mailimf_message_free(result); - return body; - } - char*body_msg = message; + /* transform to libetpan stuff */ msg = mailmessage_new(); - mailmessage_init(msg, NULL, data_message_driver, 0, strlen(body_msg)); + mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); generic_message_t * msg_data; @@ -126,12 +90,13 @@ RecBody POP3wrapper::parseMail( char *message ) msg_data->msg_fetched = 1; - msg_data->msg_message = body_msg; - msg_data->msg_length = strlen(body_msg); + msg_data->msg_message = message; + msg_data->msg_length = strlen(message); + /* parse the mail */ + body = parseMail(msg); - memset(&fields, 0, sizeof(struct mailmime_single_fields)); - err = mailmessage_get_bodystructure(msg,&mime); - traverseBody(body,msg,mime); - + /* clean up */ mailmessage_free(msg); + free(message); + /* finish */ return body; @@ -171,171 +136,2 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) -RecMail *POP3wrapper::parseHeader( const char *header ) -{ - int err = MAILIMF_NO_ERROR; - size_t curTok = 0; - RecMail *mail = new RecMail(); - mailimf_fields *fields; - mailimf_references * refs; - mailimf_keywords*keys; - 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 ) ); - break; - case MAILIMF_FIELD_CC: - mail->setCC( parseAddressList( field->fld_data.fld_cc->cc_addr_list ) ); - break; - case MAILIMF_FIELD_BCC: - mail->setBcc( parseAddressList( field->fld_data.fld_bcc->bcc_addr_list ) ); - break; - case MAILIMF_FIELD_SUBJECT: - mail->setSubject(convert_String( field->fld_data.fld_subject->sbj_value ) ); - break; - case MAILIMF_FIELD_ORIG_DATE: - mail->setDate( parseDateTime( field->fld_data.fld_orig_date->dt_date_time ) ); - break; - case MAILIMF_FIELD_MESSAGE_ID: - mail->setMsgid(QString(field->fld_data.fld_message_id->mid_value)); - break; - case MAILIMF_FIELD_REFERENCES: - refs = field->fld_data.fld_references; - if (refs && refs->mid_list && clist_count(refs->mid_list)) { - char * text = (char*)refs->mid_list->first->data; - mail->setReplyto(QString(text)); - } - break; - case MAILIMF_FIELD_KEYWORDS: - keys = field->fld_data.fld_keywords; - for (clistcell*cur = clist_begin(keys->kw_list);cur!=0;cur=clist_next(cur)) { - qDebug("Keyword: %s",(char*)cur->data); - } - break; - case MAILIMF_FIELD_OPTIONAL_FIELD: - status = field->fld_data.fld_optional_field->fld_name; - value = field->fld_data.fld_optional_field->fld_value; - if (status.lower()=="status") { - if (value.lower()=="ro") { - mFlags.setBit(FLAG_SEEN); - } - } else if (status.lower()=="x-status") { - qDebug("X-Status: %s",value.latin1()); - if (value.lower()=="a") { - mFlags.setBit(FLAG_ANSWERED); - } - } else { -// qDebug("Optionales feld: %s -> %s)",field->fld_data.fld_optional_field->fld_name, -// field->fld_data.fld_optional_field->fld_value); - } - break; - default: - qDebug("Non parsed field"); - break; - } - } - if (fields) mailimf_fields_free(fields); - mail->setFlags(mFlags); - return mail; -} - -QString POP3wrapper::parseDateTime( mailimf_date_time *date ) -{ - char tmp[23]; - - snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i", - date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone ); - - return QString( tmp ); -} - -QString POP3wrapper::parseAddressList( mailimf_address_list *list ) -{ - QString result( "" ); - - bool first = true; - for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { - mailimf_address *addr = (mailimf_address *) current->data; - - if ( !first ) { - result.append( "," ); - } else { - first = false; - } - - switch ( addr->ad_type ) { - case MAILIMF_ADDRESS_MAILBOX: - result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); - break; - case MAILIMF_ADDRESS_GROUP: - result.append( parseGroup( addr->ad_data.ad_group ) ); - break; - default: - qDebug( "POP3: unkown mailimf address type" ); - break; - } - } - - return result; -} - -QString POP3wrapper::parseGroup( mailimf_group *group ) -{ - QString result( "" ); - - result.append( group->grp_display_name ); - result.append( ": " ); - - if ( group->grp_mb_list != NULL ) { - result.append( parseMailboxList( group->grp_mb_list ) ); - } - - result.append( ";" ); - - return result; -} - -QString POP3wrapper::parseMailbox( mailimf_mailbox *box ) -{ - QString result( "" ); - - if ( box->mb_display_name == NULL ) { - result.append( box->mb_addr_spec ); - } else { - result.append( convert_String(box->mb_display_name).latin1() ); - result.append( " <" ); - result.append( box->mb_addr_spec ); - result.append( ">" ); - } - - return result; -} - -QString POP3wrapper::parseMailboxList( mailimf_mailbox_list *list ) -{ - QString result( "" ); - - bool first = true; - for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { - mailimf_mailbox *box = (mailimf_mailbox *) current->data; - - if ( !first ) { - result.append( "," ); - } else { - first = false; - } - - result.append( parseMailbox( box ) ); - } - - return result; -} - void POP3wrapper::login() @@ -421,10 +217,2 @@ QList<Folder>* POP3wrapper::listFolders() -QString POP3wrapper::fetchTextPart(const RecMail&mail,const RecPart&part) -{ - encodedString*t = fetchDecodedPart(mail,part); - QString text=t->Content(); - delete t; - return text; -} - void POP3wrapper::deleteMail(const RecMail&mail) @@ -442,177 +230 @@ void POP3wrapper::answeredMail(const RecMail&) } - -encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&part) -{ - QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); - if (it==bodyCache.end()) return new encodedString(); - encodedString*t = decode_String(it.data(),part.Encoding()); - return t; -} - -encodedString* POP3wrapper::fetchRawPart(const RecMail&mail,const RecPart&part) -{ - QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part.Identifier()); - if (it==bodyCache.end()) return new encodedString(); - encodedString*t = it.data(); - return t; -} - -void POP3wrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rec) -{ - if (current_rec >= 10) { - qDebug("too deep recursion!"); - } - if (!message || !mime) { - return; - } - int r; - char*data = 0; - size_t len; - clistiter * cur = 0; - int res; - QString b; - RecPart part; - - switch (mime->mm_type) { - case MAILMIME_SINGLE: - r = mailmessage_fetch_section(message,mime,&data,&len); - part.setSize(len); - 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; - case MAILMIME_MULTIPLE: - 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); - } - break; - case MAILMIME_MESSAGE: - if (mime->mm_data.mm_message.mm_msg_mime != NULL) { - traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,current_rec+1); - } - break; - } -} - -QString POP3wrapper::getencoding(mailmime_mechanism*aEnc) -{ - QString enc="7bit"; - if (!aEnc) return enc; - switch(aEnc->enc_type) { - case MAILMIME_MECHANISM_7BIT: - 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 POP3wrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime) -{ - if (!mime) { - return; - } - mailmime_field*field = 0; - mailmime_single_fields fields; - memset(&fields, 0, sizeof(struct mailmime_single_fields)); - if (mime->mm_mime_fields != NULL) { - mailmime_single_fields_init(&fields, mime->mm_mime_fields, - mime->mm_content_type); - } - - mailmime_content*type = fields.fld_content; - clistcell*current; - if (!type) { - target.setType("text"); - target.setSubtype("plain"); - } else { - target.setSubtype(type->ct_subtype); - switch(type->ct_type->tp_data.tp_discrete_type->dt_type) { - case MAILMIME_DISCRETE_TYPE_TEXT: - target.setType("text"); - break; - case MAILMIME_DISCRETE_TYPE_IMAGE: - target.setType("image"); - break; - case MAILMIME_DISCRETE_TYPE_AUDIO: - target.setType("audio"); - break; - case MAILMIME_DISCRETE_TYPE_VIDEO: - target.setType("video"); - break; - case MAILMIME_DISCRETE_TYPE_APPLICATION: - target.setType("application"); - break; - case MAILMIME_DISCRETE_TYPE_EXTENSION: - default: - if (type->ct_type->tp_data.tp_discrete_type->dt_extension) { - target.setType(type->ct_type->tp_data.tp_discrete_type->dt_extension); - } - break; - } - if (type->ct_parameters) { - fillParameters(target,type->ct_parameters); - } - } - if (mime->mm_mime_fields && mime->mm_mime_fields->fld_list) { - for (current=clist_begin(mime->mm_mime_fields->fld_list);current!=0;current=clist_next(current)) { - field = (mailmime_field*)current->data; - switch(field->fld_type) { - case MAILMIME_FIELD_TRANSFER_ENCODING: - target.setEncoding(getencoding(field->fld_data.fld_encoding)); - break; - case MAILMIME_FIELD_ID: - target.setIdentifier(field->fld_data.fld_id); - break; - case MAILMIME_FIELD_DESCRIPTION: - target.setDescription(field->fld_data.fld_description); - break; - default: - break; - } - } - } -} - -void POP3wrapper::fillParameters(RecPart&target,clist*parameters) -{ - if (!parameters) {return;} - clistcell*current=0; - mailmime_parameter*param; - for (current=clist_begin(parameters);current!=0;current=clist_next(current)) { - param = (mailmime_parameter*)current->data; - if (param) { - target.addParameter(QString(param->pa_name).lower(),QString(param->pa_value)); - } - } -} diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index 75d70f8..b738cca 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -3,22 +3,8 @@ -#include <libetpan/clist.h> #include "mailwrapper.h" -#include "abstractmail.h" -#include <qmap.h> +#include "genericwrapper.h" #include <qstring.h> -class RecMail; -class RecBody; -class encodedString; -struct mailpop3; -struct mailmessage; -struct mailmime; -struct mailmime_mechanism; -struct mailimf_mailbox_list; -struct mailimf_mailbox; -struct mailimf_date_time; -struct mailimf_group; -struct mailimf_address_list; -class POP3wrapper : public AbstractMail +class POP3wrapper : public Genericwrapper { @@ -32,5 +18,2 @@ public: virtual QList<Folder>* listFolders(); - virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); - virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); - virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); @@ -39,3 +22,3 @@ public: - RecBody fetchBody( const RecMail &mail ); + virtual RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); @@ -46,22 +29,2 @@ protected: - RecMail *parseHeader( const char *header ); - RecBody parseMail( char *message ); - 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 cleanUpCache(); - - void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); - static void fillSingleBody(RecPart&target,mailmessage*message,mailmime*mime); - static void fillParameters(RecPart&target,clist*parameters); - static QString POP3wrapper::getencoding(mailmime_mechanism*aEnc); - - POP3account *account; - mailpop3 *m_pop3; - QString msgTempName; - unsigned int last_msg_id; - QMap<QString,encodedString*> bodyCache; }; |