summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-30 00:14:47 (UTC)
committer alwin <alwin>2003-12-30 00:14:47 (UTC)
commitb636d3d91e8456b22bc450b3d7f3a862b7f615a9 (patch) (side-by-side diff)
tree2d7fe53175453a28e4e1d08496f6f611221c1936
parent2ecab614a6b91658b1608c62134cd14e257e55b7 (diff)
downloadopie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.zip
opie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.tar.gz
opie-b636d3d91e8456b22bc450b3d7f3a862b7f615a9.tar.bz2
re-worked pop3 (use the more generic interface)
shared some more functions between mbox and pop3
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/mail/genericwrapper.cpp69
-rw-r--r--noncore/net/mail/genericwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp69
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp68
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp150
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h5
-rw-r--r--noncore/net/mail/mboxwrapper.cpp68
-rw-r--r--noncore/net/mail/pop3wrapper.cpp150
-rw-r--r--noncore/net/mail/pop3wrapper.h5
10 files changed, 264 insertions, 324 deletions
diff --git a/noncore/net/mail/genericwrapper.cpp b/noncore/net/mail/genericwrapper.cpp
index c1b6e48..bef6ae5 100644
--- a/noncore/net/mail/genericwrapper.cpp
+++ b/noncore/net/mail/genericwrapper.cpp
@@ -1,393 +1,458 @@
#include "genericwrapper.h"
-#include <libetpan/mailmime.h>
-#include <libetpan/data_message_driver.h>
+#include <libetpan/libetpan.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 = 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)
+{
+ 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(i+1);
+ 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 (single_fields.fld_to)
+ mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
+ 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 ) );
+ if (single_fields.fld_message_id->mid_value)
+ mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
+ 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/genericwrapper.h b/noncore/net/mail/genericwrapper.h
index 90c4b50..54d6ea9 100644
--- a/noncore/net/mail/genericwrapper.h
+++ b/noncore/net/mail/genericwrapper.h
@@ -1,57 +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;
+struct mailsession;
/* 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);
+ 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 c1b6e48..bef6ae5 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -1,393 +1,458 @@
#include "genericwrapper.h"
-#include <libetpan/mailmime.h>
-#include <libetpan/data_message_driver.h>
+#include <libetpan/libetpan.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 = 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)
+{
+ 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(i+1);
+ 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 (single_fields.fld_to)
+ mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
+ 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 ) );
+ if (single_fields.fld_message_id->mid_value)
+ mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
+ 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 90c4b50..54d6ea9 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -1,57 +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;
+struct mailsession;
/* 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);
+ 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/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
index 162a0c9..0aa33dd 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp
@@ -1,367 +1,303 @@
#include "mboxwrapper.h"
#include "mailtypes.h"
#include "mailwrapper.h"
#include <libetpan/libetpan.h>
#include <qdir.h>
#include <stdlib.h>
#include <qpe/global.h>
MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
: Genericwrapper(),MBOXPath(mbox_dir)
{
QDir dir(MBOXPath);
if (!dir.exists()) {
dir.mkdir(MBOXPath);
}
}
MBOXwrapper::~MBOXwrapper()
{
}
void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
{
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mailbox;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
- mailmessage_list * env_list = 0;
- r = mailsession_get_messages_list(folder->fld_session,&env_list);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error message list");
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
- r = mailsession_get_envelopes_list(folder->fld_session, env_list);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error filling message list");
- if (env_list) {
- mailmessage_list_free(env_list);
- }
- mailfolder_free(folder);
- mailstorage_free(storage);
- 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(i+1);
- 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 (single_fields.fld_to)
- mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
- 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 ) );
- if (single_fields.fld_message_id->mid_value)
- mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
- 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));
- }
+ parseList(target,folder->fld_session,mailbox);
- target.append(mail);
- }
- if (env_list) {
- mailmessage_list_free(env_list);
- }
mailfolder_disconnect(folder);
mailfolder_free(folder);
mailstorage_free(storage);
- Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i));
+ Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
}
QList<Folder>* MBOXwrapper::listFolders()
{
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
QDir dir(MBOXPath);
if (!dir.exists()) return folders;
dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
QStringList entries = dir.entryList();
QStringList::ConstIterator it = entries.begin();
for (;it!=entries.end();++it) {
Folder*inb=new Folder(*it,"/");
folders->append(inb);
}
return folders;
}
void MBOXwrapper::deleteMail(const RecMail&mail)
{
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailsession_remove_message(folder->fld_session,mail.getNumber());
if (r != MAIL_NO_ERROR) {
qDebug("error deleting mail");
}
mailfolder_free(folder);
mailstorage_free(storage);
}
void MBOXwrapper::answeredMail(const RecMail&)
{
}
RecBody MBOXwrapper::fetchBody( const RecMail &mail )
{
RecBody body;
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
mailmessage * msg;
char*data=0;
size_t size;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
if (r != MAIL_NO_ERROR) {
qDebug("Error fetching mail %i",mail.getNumber());
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
r = mailmessage_fetch(msg,&data,&size);
if (r != MAIL_NO_ERROR) {
qDebug("Error fetching mail %i",mail.getNumber());
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
return body;
}
body = parseMail(msg);
mailmessage_fetch_result_free(msg,data);
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
{
qDebug("MBOX %i von %i",current,maximum);
}
int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
{
QString p = MBOXPath+"/";
p+=folder;
QFileInfo fi(p);
if (fi.exists()) {
Global::statusMessage(tr("Mailbox exists."));
return 0;
}
mailmbox_folder*f = 0;
if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error init folder"));
return 0;
}
if (f) mailmbox_done(f);
return 1;
}
void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
{
QString p = MBOXPath+"/";
p+=folder;
mailmbox_folder*f = 0;
int r = mailmbox_init(p.latin1(),0,1,0,&f);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error init folder"));
return;
}
r = mailmbox_append_message(f,msg,length);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error writing to message folder"));
}
mailmbox_done(f);
}
void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
{
RecBody body;
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
mailmessage * msg;
char*data=0;
size_t size;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailmessage_fetch(msg,&data,&size);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
return;
}
*target = data;
*length = size;
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
}
void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
{
QString p = MBOXPath+"/";
p+=mailbox;
mailmbox_folder*f = 0;
int r = mailmbox_init(p.latin1(),0,1,0,&f);
if (r != MAIL_NO_ERROR) {
qDebug("Error init folder");
return;
}
deleteMails(f,target);
mailmbox_done(f);
}
void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
{
if (!f) return;
int r;
for (unsigned int i=0; i < target.count();++i) {
r = mailmbox_delete_msg(f,target.at(i)->getNumber());
if (r!=MAILMBOX_NO_ERROR) {
qDebug("error delete mail");
}
}
r = mailmbox_expunge(f);
if (r != MAILMBOX_NO_ERROR) {
qDebug("error expunge mailbox");
}
}
int MBOXwrapper::deleteAllMail(const Folder*tfolder)
{
if (!tfolder) return 0;
QString p = MBOXPath+tfolder->getDisplayName();
int res = 1;
mailfolder*folder = 0;
mailmessage_list*l=0;
mailstorage*storage = mailstorage_new(NULL);
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
res = 0;
}
if (res) {
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
res = 0;
}
}
if (res) {
r = mailsession_get_messages_list(folder->fld_session,&l);
if (r != MAIL_NO_ERROR) {
qDebug("Error message list");
res=0;
}
}
for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
r = mailsession_remove_message(folder->fld_session,i+1);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
res = 0;
break;
}
}
if (l) mailmessage_list_free(l);
if (folder) mailfolder_free(folder);
if (storage) mailstorage_free(storage);
return res;
}
int MBOXwrapper::deleteMbox(const Folder*tfolder)
{
if (!tfolder) return 0;
QString p = MBOXPath+tfolder->getDisplayName();
QFile fi(p);
if (!fi.exists()) {
Global::statusMessage(tr("Mailbox doesn't exist."));
return 0;
}
if (!fi.remove()) {
Global::statusMessage(tr("Error deleting Mailbox."));
return 0;
}
return 1;
}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index 2e70dee..de90dd1 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -1,254 +1,218 @@
#include <stdlib.h>
#include "pop3wrapper.h"
#include "mailtypes.h"
#include "logindialog.h"
#include <libetpan/libetpan.h>
#include <qpe/global.h>
#include <qfile.h>
+#include <qstring.h>
/* we don't fetch messages larger than 5 MB */
#define HARD_MSG_SIZE_LIMIT 5242880
POP3wrapper::POP3wrapper( POP3account *a )
: Genericwrapper()
{
account = a;
m_pop3 = NULL;
+ m_folder = NULL;
msgTempName = a->getFileName()+"_msg_cache";
last_msg_id = 0;
}
POP3wrapper::~POP3wrapper()
{
logout();
QFile msg_cache(msgTempName);
if (msg_cache.exists()) {
msg_cache.remove();
}
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
- //qDebug( "POP3: %i of %i", current, maximum );
+ qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
{
int err = MAILPOP3_NO_ERROR;
- char *message;
+ char *message = 0;
size_t length = 0;
login();
if ( !m_pop3 ) {
return RecBody();
}
RecBody body;
- mailmessage * msg = 0;
-
- QFile msg_cache(msgTempName);
-
+ mailmessage * mailmsg;
if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
qDebug("Message to large: %i",mail.Msgsize());
return body;
}
+
+ QFile msg_cache(msgTempName);
+
cleanMimeCache();
+
if (mail.getNumber()!=last_msg_id) {
if (msg_cache.exists()) {
msg_cache.remove();
}
msg_cache.open(IO_ReadWrite|IO_Truncate);
last_msg_id = mail.getNumber();
- err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
- last_msg_id = 0;
- return RecBody();
- }
+ err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
+ err = mailmessage_fetch(mailmsg,&message,&length);
msg_cache.writeBlock(message,length);
} else {
QString msg="";
msg_cache.open(IO_ReadOnly);
message = new char[4096];
memset(message,0,4096);
while (msg_cache.readBlock(message,4095)>0) {
msg+=message;
memset(message,0,4096);
}
delete message;
message = (char*)malloc(msg.length()+1*sizeof(char));
memset(message,0,msg.length()+1);
memcpy(message,msg.latin1(),msg.length());
- }
-
/* transform to libetpan stuff */
- msg = mailmessage_new();
- mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
+ mailmsg = mailmessage_new();
+ mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
generic_message_t * msg_data;
- msg_data = (generic_message_t *)msg->msg_data;
+ msg_data = (generic_message_t *)mailmsg->msg_data;
msg_data->msg_fetched = 1;
msg_data->msg_message = message;
msg_data->msg_length = strlen(message);
-
- /* parse the mail */
- body = parseMail(msg);
+ }
+ body = parseMail(mailmsg);
/* clean up */
- mailmessage_free(msg);
- free(message);
+ if (mailmsg) mailmessage_free(mailmsg);
+ if (message) free(message);
- /* finish */
return body;
}
void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
{
- int err = MAILPOP3_NO_ERROR;
- char * header = 0;
- /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
- size_t length = 0;
- carray * messages = 0;
-
login();
if (!m_pop3) return;
-
- mailpop3_list( m_pop3, &messages );
-
- for (unsigned int i = 0; i < carray_count(messages);++i) {
- mailpop3_msg_info *info;
- err = mailpop3_get_msg_info(m_pop3,i+1,&info);
- if (info->msg_deleted)
- continue;
- err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
- free(header);
- return;
- }
- RecMail *mail = parseHeader( header );
- mail->setNumber( info->msg_index );
- mail->setWrapper(this);
- mail->setMsgsize(info->msg_size);
- target.append( mail );
- free(header);
- }
- Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count));
+ uint32_t res_messages,res_recent,res_unseen;
+ mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
+ parseList(target,m_folder->fld_session,"INBOX");
+ Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
}
void POP3wrapper::login()
{
/* we'll hold the line */
if ( m_pop3 != NULL ) return;
const char *server, *user, *pass;
uint16_t port;
int err = MAILPOP3_NO_ERROR;
server = account->getServer().latin1();
port = account->getPort().toUInt();
if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
login.show();
if ( QDialog::Accepted == login.exec() ) {
// ok
- user = strdup( login.getUser().latin1() );
- pass = strdup( login.getPassword().latin1() );
+ user = login.getUser().latin1();
+ pass = login.getPassword().latin1();
} else {
// cancel
qDebug( "POP3: Login canceled" );
return;
}
} else {
user = account->getUser().latin1();
pass = account->getPassword().latin1();
}
- m_pop3 = mailpop3_new( 200, &pop3_progress );
+ bool ssl = account->getSSL();
- // connect
- if (account->getSSL()) {
- err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
- } else {
- err = mailpop3_socket_connect( m_pop3, (char*)server, port );
- }
+ m_pop3=mailstorage_new(NULL);
+ pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
+ (char*)user,(char*)pass,0,0,0);
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "pop3: error connecting to %s\n reason: %s", server,
- m_pop3->pop3_response );
- mailpop3_free( m_pop3 );
+ m_folder = mailfolder_new(m_pop3, NULL, NULL);
+
+ if (m_folder==0) {
+ Global::statusMessage(tr("Error initializing folder"));
+ mailstorage_free(m_pop3);
m_pop3 = NULL;
return;
}
- qDebug( "POP3: connected!" );
-
- // login
- // TODO: decide if apop or plain login should be used
- err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
- logout();
- return;
+ err = mailfolder_connect(m_folder);
+ if (err != MAIL_NO_ERROR) {
+ Global::statusMessage(tr("Error initializing folder"));
+ mailfolder_free(m_folder);
+ m_folder = 0;
+ mailstorage_free(m_pop3);
+ m_pop3 = 0;
}
-
qDebug( "POP3: logged in!" );
}
void POP3wrapper::logout()
{
int err = MAILPOP3_NO_ERROR;
if ( m_pop3 == NULL ) return;
- err = mailpop3_quit( m_pop3 );
- mailpop3_free( m_pop3 );
- m_pop3 = NULL;
+ mailfolder_free(m_folder);
+ m_folder = 0;
+ mailstorage_free(m_pop3);
+ m_pop3 = 0;
}
QList<Folder>* POP3wrapper::listFolders()
{
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
- int err = mailpop3_dele(m_pop3,mail.getNumber());
- if (err != MAILPOP3_NO_ERROR) {
+ int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
+ if (err != MAIL_NO_ERROR) {
Global::statusMessage(tr("error deleting mail"));
}
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
int POP3wrapper::deleteAllMail(const Folder*)
{
login();
if (!m_pop3) return 0;
- carray * messages = 0;
-
- /* if connected this info is cached! */
- int err = 0;
- mailpop3_list( m_pop3, &messages );
-
int res = 1;
- for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
- mailpop3_msg_info *info;
- err = mailpop3_get_msg_info(m_pop3,i+1,&info);
- if (info->msg_deleted)
- continue;
- err = mailpop3_dele(m_pop3,i+1);
- if (err != MAILPOP3_NO_ERROR) {
+
+ uint32_t result = 0;
+ int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
+ if (err != MAIL_NO_ERROR) {
+ Global::statusMessage(tr("Error getting folder info"));
+ return 0;
+ }
+ for (unsigned int i = 0; i < result; ++i) {
+ err = mailsession_remove_message(m_folder->fld_session,i+1);
+ if (err != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
res = 0;
- break;
}
+ break;
}
return res;
}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 2efffdd..b3a42be 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -1,34 +1,37 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "genericwrapper.h"
#include <qstring.h>
+struct mailstorage;
+struct mailfolder;
class POP3wrapper : public Genericwrapper
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
virtual int deleteAllMail(const Folder*);
virtual RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
protected:
void login();
void logout();
POP3account *account;
- mailpop3 *m_pop3;
+ mailstorage*m_pop3;
+ mailfolder*m_folder;
};
#endif
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp
index 162a0c9..0aa33dd 100644
--- a/noncore/net/mail/mboxwrapper.cpp
+++ b/noncore/net/mail/mboxwrapper.cpp
@@ -1,367 +1,303 @@
#include "mboxwrapper.h"
#include "mailtypes.h"
#include "mailwrapper.h"
#include <libetpan/libetpan.h>
#include <qdir.h>
#include <stdlib.h>
#include <qpe/global.h>
MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
: Genericwrapper(),MBOXPath(mbox_dir)
{
QDir dir(MBOXPath);
if (!dir.exists()) {
dir.mkdir(MBOXPath);
}
}
MBOXwrapper::~MBOXwrapper()
{
}
void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
{
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mailbox;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
- mailmessage_list * env_list = 0;
- r = mailsession_get_messages_list(folder->fld_session,&env_list);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error message list");
- mailfolder_free(folder);
- mailstorage_free(storage);
- return;
- }
- r = mailsession_get_envelopes_list(folder->fld_session, env_list);
- if (r != MAIL_NO_ERROR) {
- qDebug("Error filling message list");
- if (env_list) {
- mailmessage_list_free(env_list);
- }
- mailfolder_free(folder);
- mailstorage_free(storage);
- 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(i+1);
- 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 (single_fields.fld_to)
- mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) );
- 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 ) );
- if (single_fields.fld_message_id->mid_value)
- mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
- 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));
- }
+ parseList(target,folder->fld_session,mailbox);
- target.append(mail);
- }
- if (env_list) {
- mailmessage_list_free(env_list);
- }
mailfolder_disconnect(folder);
mailfolder_free(folder);
mailstorage_free(storage);
- Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i));
+ Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
}
QList<Folder>* MBOXwrapper::listFolders()
{
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
QDir dir(MBOXPath);
if (!dir.exists()) return folders;
dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable);
QStringList entries = dir.entryList();
QStringList::ConstIterator it = entries.begin();
for (;it!=entries.end();++it) {
Folder*inb=new Folder(*it,"/");
folders->append(inb);
}
return folders;
}
void MBOXwrapper::deleteMail(const RecMail&mail)
{
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailsession_remove_message(folder->fld_session,mail.getNumber());
if (r != MAIL_NO_ERROR) {
qDebug("error deleting mail");
}
mailfolder_free(folder);
mailstorage_free(storage);
}
void MBOXwrapper::answeredMail(const RecMail&)
{
}
RecBody MBOXwrapper::fetchBody( const RecMail &mail )
{
RecBody body;
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
mailmessage * msg;
char*data=0;
size_t size;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
qDebug("Error initializing mbox");
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
if (r != MAIL_NO_ERROR) {
qDebug("Error fetching mail %i",mail.getNumber());
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
r = mailmessage_fetch(msg,&data,&size);
if (r != MAIL_NO_ERROR) {
qDebug("Error fetching mail %i",mail.getNumber());
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
return body;
}
body = parseMail(msg);
mailmessage_fetch_result_free(msg,data);
mailfolder_free(folder);
mailstorage_free(storage);
return body;
}
void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
{
qDebug("MBOX %i von %i",current,maximum);
}
int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
{
QString p = MBOXPath+"/";
p+=folder;
QFileInfo fi(p);
if (fi.exists()) {
Global::statusMessage(tr("Mailbox exists."));
return 0;
}
mailmbox_folder*f = 0;
if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error init folder"));
return 0;
}
if (f) mailmbox_done(f);
return 1;
}
void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder)
{
QString p = MBOXPath+"/";
p+=folder;
mailmbox_folder*f = 0;
int r = mailmbox_init(p.latin1(),0,1,0,&f);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error init folder"));
return;
}
r = mailmbox_append_message(f,msg,length);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error writing to message folder"));
}
mailmbox_done(f);
}
void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length)
{
RecBody body;
mailstorage*storage = mailstorage_new(NULL);
QString p = MBOXPath+"/";
p+=mail.getMbox();
mailmessage * msg;
char*data=0;
size_t size;
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
mailfolder*folder;
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
mailfolder_free(folder);
mailstorage_free(storage);
return;
}
r = mailmessage_fetch(msg,&data,&size);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
return;
}
*target = data;
*length = size;
mailfolder_free(folder);
mailstorage_free(storage);
mailmessage_free(msg);
}
void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
{
QString p = MBOXPath+"/";
p+=mailbox;
mailmbox_folder*f = 0;
int r = mailmbox_init(p.latin1(),0,1,0,&f);
if (r != MAIL_NO_ERROR) {
qDebug("Error init folder");
return;
}
deleteMails(f,target);
mailmbox_done(f);
}
void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target)
{
if (!f) return;
int r;
for (unsigned int i=0; i < target.count();++i) {
r = mailmbox_delete_msg(f,target.at(i)->getNumber());
if (r!=MAILMBOX_NO_ERROR) {
qDebug("error delete mail");
}
}
r = mailmbox_expunge(f);
if (r != MAILMBOX_NO_ERROR) {
qDebug("error expunge mailbox");
}
}
int MBOXwrapper::deleteAllMail(const Folder*tfolder)
{
if (!tfolder) return 0;
QString p = MBOXPath+tfolder->getDisplayName();
int res = 1;
mailfolder*folder = 0;
mailmessage_list*l=0;
mailstorage*storage = mailstorage_new(NULL);
int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
res = 0;
}
if (res) {
folder = mailfolder_new( storage,(char*)p.latin1(),NULL);
r = mailfolder_connect(folder);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error initializing mbox"));
res = 0;
}
}
if (res) {
r = mailsession_get_messages_list(folder->fld_session,&l);
if (r != MAIL_NO_ERROR) {
qDebug("Error message list");
res=0;
}
}
for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
r = mailsession_remove_message(folder->fld_session,i+1);
if (r != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
res = 0;
break;
}
}
if (l) mailmessage_list_free(l);
if (folder) mailfolder_free(folder);
if (storage) mailstorage_free(storage);
return res;
}
int MBOXwrapper::deleteMbox(const Folder*tfolder)
{
if (!tfolder) return 0;
QString p = MBOXPath+tfolder->getDisplayName();
QFile fi(p);
if (!fi.exists()) {
Global::statusMessage(tr("Mailbox doesn't exist."));
return 0;
}
if (!fi.remove()) {
Global::statusMessage(tr("Error deleting Mailbox."));
return 0;
}
return 1;
}
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index 2e70dee..de90dd1 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -1,254 +1,218 @@
#include <stdlib.h>
#include "pop3wrapper.h"
#include "mailtypes.h"
#include "logindialog.h"
#include <libetpan/libetpan.h>
#include <qpe/global.h>
#include <qfile.h>
+#include <qstring.h>
/* we don't fetch messages larger than 5 MB */
#define HARD_MSG_SIZE_LIMIT 5242880
POP3wrapper::POP3wrapper( POP3account *a )
: Genericwrapper()
{
account = a;
m_pop3 = NULL;
+ m_folder = NULL;
msgTempName = a->getFileName()+"_msg_cache";
last_msg_id = 0;
}
POP3wrapper::~POP3wrapper()
{
logout();
QFile msg_cache(msgTempName);
if (msg_cache.exists()) {
msg_cache.remove();
}
}
void POP3wrapper::pop3_progress( size_t current, size_t maximum )
{
- //qDebug( "POP3: %i of %i", current, maximum );
+ qDebug( "POP3: %i of %i", current, maximum );
}
RecBody POP3wrapper::fetchBody( const RecMail &mail )
{
int err = MAILPOP3_NO_ERROR;
- char *message;
+ char *message = 0;
size_t length = 0;
login();
if ( !m_pop3 ) {
return RecBody();
}
RecBody body;
- mailmessage * msg = 0;
-
- QFile msg_cache(msgTempName);
-
+ mailmessage * mailmsg;
if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
qDebug("Message to large: %i",mail.Msgsize());
return body;
}
+
+ QFile msg_cache(msgTempName);
+
cleanMimeCache();
+
if (mail.getNumber()!=last_msg_id) {
if (msg_cache.exists()) {
msg_cache.remove();
}
msg_cache.open(IO_ReadWrite|IO_Truncate);
last_msg_id = mail.getNumber();
- err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "POP3: error retrieving body with index %i", mail.getNumber() );
- last_msg_id = 0;
- return RecBody();
- }
+ err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg);
+ err = mailmessage_fetch(mailmsg,&message,&length);
msg_cache.writeBlock(message,length);
} else {
QString msg="";
msg_cache.open(IO_ReadOnly);
message = new char[4096];
memset(message,0,4096);
while (msg_cache.readBlock(message,4095)>0) {
msg+=message;
memset(message,0,4096);
}
delete message;
message = (char*)malloc(msg.length()+1*sizeof(char));
memset(message,0,msg.length()+1);
memcpy(message,msg.latin1(),msg.length());
- }
-
/* transform to libetpan stuff */
- msg = mailmessage_new();
- mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message));
+ mailmsg = mailmessage_new();
+ mailmessage_init(mailmsg, NULL, data_message_driver, 0, strlen(message));
generic_message_t * msg_data;
- msg_data = (generic_message_t *)msg->msg_data;
+ msg_data = (generic_message_t *)mailmsg->msg_data;
msg_data->msg_fetched = 1;
msg_data->msg_message = message;
msg_data->msg_length = strlen(message);
-
- /* parse the mail */
- body = parseMail(msg);
+ }
+ body = parseMail(mailmsg);
/* clean up */
- mailmessage_free(msg);
- free(message);
+ if (mailmsg) mailmessage_free(mailmsg);
+ if (message) free(message);
- /* finish */
return body;
}
void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
{
- int err = MAILPOP3_NO_ERROR;
- char * header = 0;
- /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */
- size_t length = 0;
- carray * messages = 0;
-
login();
if (!m_pop3) return;
-
- mailpop3_list( m_pop3, &messages );
-
- for (unsigned int i = 0; i < carray_count(messages);++i) {
- mailpop3_msg_info *info;
- err = mailpop3_get_msg_info(m_pop3,i+1,&info);
- if (info->msg_deleted)
- continue;
- err = mailpop3_header( m_pop3, info->msg_index, &header, &length );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "POP3: error retrieving header msgid: %i", info->msg_index );
- free(header);
- return;
- }
- RecMail *mail = parseHeader( header );
- mail->setNumber( info->msg_index );
- mail->setWrapper(this);
- mail->setMsgsize(info->msg_size);
- target.append( mail );
- free(header);
- }
- Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(carray_count(messages)-m_pop3->pop3_deleted_count));
+ uint32_t res_messages,res_recent,res_unseen;
+ mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen);
+ parseList(target,m_folder->fld_session,"INBOX");
+ Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
}
void POP3wrapper::login()
{
/* we'll hold the line */
if ( m_pop3 != NULL ) return;
const char *server, *user, *pass;
uint16_t port;
int err = MAILPOP3_NO_ERROR;
server = account->getServer().latin1();
port = account->getPort().toUInt();
if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
login.show();
if ( QDialog::Accepted == login.exec() ) {
// ok
- user = strdup( login.getUser().latin1() );
- pass = strdup( login.getPassword().latin1() );
+ user = login.getUser().latin1();
+ pass = login.getPassword().latin1();
} else {
// cancel
qDebug( "POP3: Login canceled" );
return;
}
} else {
user = account->getUser().latin1();
pass = account->getPassword().latin1();
}
- m_pop3 = mailpop3_new( 200, &pop3_progress );
+ bool ssl = account->getSSL();
- // connect
- if (account->getSSL()) {
- err = mailpop3_ssl_connect( m_pop3, (char*)server, port );
- } else {
- err = mailpop3_socket_connect( m_pop3, (char*)server, port );
- }
+ m_pop3=mailstorage_new(NULL);
+ pop3_mailstorage_init(m_pop3,(char*)server,port,NULL,CONNECTION_TYPE_TRY_STARTTLS,POP3_AUTH_TYPE_TRY_APOP,
+ (char*)user,(char*)pass,0,0,0);
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "pop3: error connecting to %s\n reason: %s", server,
- m_pop3->pop3_response );
- mailpop3_free( m_pop3 );
+ m_folder = mailfolder_new(m_pop3, NULL, NULL);
+
+ if (m_folder==0) {
+ Global::statusMessage(tr("Error initializing folder"));
+ mailstorage_free(m_pop3);
m_pop3 = NULL;
return;
}
- qDebug( "POP3: connected!" );
-
- // login
- // TODO: decide if apop or plain login should be used
- err = mailpop3_login( m_pop3, (char *) user, (char *) pass );
- if ( err != MAILPOP3_NO_ERROR ) {
- qDebug( "pop3: error logging in: %s", m_pop3->pop3_response );
- logout();
- return;
+ err = mailfolder_connect(m_folder);
+ if (err != MAIL_NO_ERROR) {
+ Global::statusMessage(tr("Error initializing folder"));
+ mailfolder_free(m_folder);
+ m_folder = 0;
+ mailstorage_free(m_pop3);
+ m_pop3 = 0;
}
-
qDebug( "POP3: logged in!" );
}
void POP3wrapper::logout()
{
int err = MAILPOP3_NO_ERROR;
if ( m_pop3 == NULL ) return;
- err = mailpop3_quit( m_pop3 );
- mailpop3_free( m_pop3 );
- m_pop3 = NULL;
+ mailfolder_free(m_folder);
+ m_folder = 0;
+ mailstorage_free(m_pop3);
+ m_pop3 = 0;
}
QList<Folder>* POP3wrapper::listFolders()
{
QList<Folder> * folders = new QList<Folder>();
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX","/");
folders->append(inb);
return folders;
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
login();
if (!m_pop3) return;
- int err = mailpop3_dele(m_pop3,mail.getNumber());
- if (err != MAILPOP3_NO_ERROR) {
+ int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber());
+ if (err != MAIL_NO_ERROR) {
Global::statusMessage(tr("error deleting mail"));
}
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
int POP3wrapper::deleteAllMail(const Folder*)
{
login();
if (!m_pop3) return 0;
- carray * messages = 0;
-
- /* if connected this info is cached! */
- int err = 0;
- mailpop3_list( m_pop3, &messages );
-
int res = 1;
- for (unsigned int i = 0; messages!=0 && i < carray_count(messages);++i) {
- mailpop3_msg_info *info;
- err = mailpop3_get_msg_info(m_pop3,i+1,&info);
- if (info->msg_deleted)
- continue;
- err = mailpop3_dele(m_pop3,i+1);
- if (err != MAILPOP3_NO_ERROR) {
+
+ uint32_t result = 0;
+ int err = mailsession_messages_number(m_folder->fld_session,NULL,&result);
+ if (err != MAIL_NO_ERROR) {
+ Global::statusMessage(tr("Error getting folder info"));
+ return 0;
+ }
+ for (unsigned int i = 0; i < result; ++i) {
+ err = mailsession_remove_message(m_folder->fld_session,i+1);
+ if (err != MAIL_NO_ERROR) {
Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
res = 0;
- break;
}
+ break;
}
return res;
}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 2efffdd..b3a42be 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -1,34 +1,37 @@
#ifndef __POP3WRAPPER
#define __POP3WRAPPER
#include "mailwrapper.h"
#include "genericwrapper.h"
#include <qstring.h>
+struct mailstorage;
+struct mailfolder;
class POP3wrapper : public Genericwrapper
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
virtual int deleteAllMail(const Folder*);
virtual RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
protected:
void login();
void logout();
POP3account *account;
- mailpop3 *m_pop3;
+ mailstorage*m_pop3;
+ mailfolder*m_folder;
};
#endif