summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp85
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h1
2 files changed, 5 insertions, 81 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 3fe319b..eb2c031 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -145,372 +145,297 @@ void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mi
clistiter * cur = 0;
QString b;
RecPart part;
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());
if (countlist.count()>2) {
bodyCache[b]=r;
target.addPart(part);
} else {
delete r;
}
b = QString(res->Content());
delete res;
target.setBodytext(b);
target.setDescription(part);
} else {
bodyCache[b]=new encodedString(data,len);
target.addPart(part);
}
}
break;
case MAILMIME_MULTIPLE:
{
unsigned int ccount = 1;
mailmime*cbody=0;
QValueList<int>countlist = recList;
for (cur = clist_begin(mime->mm_data.mm_multipart.mm_mp_list) ; cur != NULL ; cur = clist_next(cur)) {
cbody = (mailmime*)clist_content(cur);
if (cbody->mm_type==MAILMIME_MULTIPLE) {
RecPart targetPart;
targetPart.setType("multipart");
countlist.append(current_count);
targetPart.setPositionlist(countlist);
target.addPart(targetPart);
}
traverseBody(target,message, cbody,countlist,current_rec+1,ccount);
if (cbody->mm_type==MAILMIME_MULTIPLE) {
countlist = recList;
}
++ccount;
}
}
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,countlist,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);
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 ) );
- 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");
}
void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to)
{
int r;
mailmessage_list * env_list = 0;
r = mailsession_get_messages_list(session,&env_list);
if (r != MAIL_NO_ERROR) {
qDebug("Error message list");
return;
}
r = mailsession_get_envelopes_list(session, env_list);
if (r != MAIL_NO_ERROR) {
qDebug("Error filling message list");
if (env_list) {
mailmessage_list_free(env_list);
}
return;
}
mailimf_references * refs;
uint32_t i = 0;
for(; i < carray_count(env_list->msg_tab) ; ++i) {
mailmessage * msg;
QBitArray mFlags(7);
msg = (mailmessage*)carray_get(env_list->msg_tab, i);
if (msg->msg_fields == NULL) {
//qDebug("could not fetch envelope of message %i", i);
continue;
}
RecMail * mail = new RecMail();
mail->setWrapper(this);
mail_flags * flag_result = 0;
r = mailmessage_get_flags(msg,&flag_result);
if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
mFlags.setBit(FLAG_SEEN);
}
mailimf_single_fields single_fields;
mailimf_single_fields_init(&single_fields, msg->msg_fields);
mail->setMsgsize(msg->msg_size);
mail->setFlags(mFlags);
mail->setMbox(mailbox);
mail->setNumber(msg->msg_index);
if (single_fields.fld_subject)
mail->setSubject( convert_String(single_fields.fld_subject->sbj_value));
if (single_fields.fld_from)
mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list));
if (!mbox_as_to) {
if (single_fields.fld_to)
mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
} else {
mail->setTo(mailbox);
}
if (single_fields.fld_cc)
mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) );
if (single_fields.fld_bcc)
mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) );
if (single_fields.fld_orig_date)
mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) );
- // crashes when accessing pop3 account
- // if (single_fields.fld_message_id->mid_value)
- // mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
+ // crashes when accessing pop3 account?
+ if (single_fields.fld_message_id->mid_value) {
+ mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
+ qDebug("Msqgid == %s",mail->Msgid().latin1());
+ }
refs = single_fields.fld_references;
if (refs && refs->mid_list && clist_count(refs->mid_list)) {
char * text = (char*)refs->mid_list->first->data;
mail->setReplyto(QString(text));
}
target.append(mail);
}
if (env_list) {
mailmessage_list_free(env_list);
}
}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index b451416..0870912 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,66 +1,65 @@
#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;
struct mailsession;
struct mailstorage;
struct mailfolder;
/* 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();
virtual int deleteMbox(const Folder*){return 1;}
virtual void logout(){};
virtual void storeMessage(const char*msg,size_t length, const QString&folder){};
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,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
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,bool mbox_as_to=false);
QString msgTempName;
unsigned int last_msg_id;
QMap<QString,encodedString*> bodyCache;
mailstorage * m_storage;
mailfolder*m_folder;
};
#endif