Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/genericwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 124 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 8 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 7 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 3 |
5 files changed, 112 insertions, 32 deletions
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h index 12f6928..90c4b50 100644 --- a/noncore/net/mail/libmailwrapper/genericwrapper.h +++ b/noncore/net/mail/libmailwrapper/genericwrapper.h @@ -48,10 +48,8 @@ protected: 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; }; diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 6d69263..162a0c9 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp @@ -1,11 +1,11 @@ #include "mboxwrapper.h" #include "mailtypes.h" #include "mailwrapper.h" #include <libetpan/libetpan.h> -#include <libetpan/mailstorage.h> #include <qdir.h> #include <stdlib.h> +#include <qpe/global.h> MBOXwrapper::MBOXwrapper(const QString & mbox_dir) : Genericwrapper(),MBOXPath(mbox_dir) { @@ -23,30 +23,25 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mailbox; - char*fname = 0; - fname = strdup(p.latin1()); - - int r = mbox_mailstorage_init(storage,fname,0,0,0); + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,fname,NULL); + 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); - free(fname); 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); - free(fname); return; } r = mailsession_get_envelopes_list(folder->fld_session, env_list); if (r != MAIL_NO_ERROR) { @@ -55,14 +50,14 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailmessage_list_free(env_list); } mailfolder_free(folder); mailstorage_free(storage); - free(fname); return; } mailimf_references * refs; - for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { + 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) { @@ -109,9 +104,9 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) } mailfolder_disconnect(folder); mailfolder_free(folder); mailstorage_free(storage); - free(fname); + Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); } QList<Folder>* MBOXwrapper::listFolders() { @@ -133,12 +128,11 @@ void MBOXwrapper::deleteMail(const RecMail&mail) { mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail.getMbox(); - mailmessage * msg; - int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,strdup(p.latin1()),NULL); + folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { qDebug("Error initializing mbox"); mailfolder_free(folder); @@ -166,11 +160,11 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail ) mailmessage * msg; char*data=0; size_t size; - int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,strdup(p.latin1()),NULL); + folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { qDebug("Error initializing mbox"); mailfolder_free(folder); @@ -204,10 +198,24 @@ void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) { qDebug("MBOX %i von %i",current,maximum); } -void MBOXwrapper::createFolder(const QString&) +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) { @@ -215,14 +223,14 @@ void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folde p+=folder; mailmbox_folder*f = 0; int r = mailmbox_init(p.latin1(),0,1,0,&f); if (r != MAIL_NO_ERROR) { - qDebug("Error init folder"); + Global::statusMessage(tr("Error init folder")); return; } r = mailmbox_append_message(f,msg,length); if (r != MAIL_NO_ERROR) { - qDebug("Error writing message folder"); + Global::statusMessage(tr("Error writing to message folder")); } mailmbox_done(f); } @@ -235,28 +243,28 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) mailmessage * msg; char*data=0; size_t size; - int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); mailfolder*folder; - folder = mailfolder_new( storage,strdup(p.latin1()),NULL); + folder = mailfolder_new( storage,(char*)p.latin1(),NULL); r = mailfolder_connect(folder); if (r != MAIL_NO_ERROR) { - qDebug("Error initializing mbox"); + 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) { - qDebug("Error fetching mail %i",mail.getNumber()); + 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) { - qDebug("Error fetching mail %i",mail.getNumber()); + Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return; @@ -277,8 +285,16 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 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"); @@ -287,7 +303,65 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) r = mailmbox_expunge(f); if (r != MAILMBOX_NO_ERROR) { qDebug("error expunge mailbox"); } - mailmbox_done(f); +} + +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/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index f64ad52..226a544 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h @@ -5,8 +5,9 @@ #include <qstring.h> class RecMail; class RecBody; +struct mailmbox_folder; class MBOXwrapper : public Genericwrapper { Q_OBJECT @@ -18,18 +19,23 @@ public: virtual QList<Folder>* listFolders(); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); - virtual void createFolder(const QString&aFolder); + + virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); + virtual int deleteMbox(const Folder*); + virtual void storeMessage(const char*msg,size_t length, const QString&folder); virtual RecBody fetchBody( const RecMail &mail ); static void mbox_progress( size_t current, size_t maximum ); virtual void fetchRawBody(const RecMail&mail,char**target,size_t*length); virtual void deleteMails(const QString & mailbox,QList<RecMail> &target); + virtual int deleteAllMail(const Folder*); protected: + static void deleteMails(mailmbox_folder*f,QList<RecMail> &target); QString MBOXPath; }; #endif diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index efd83ba..b85fbf6 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -1,11 +1,10 @@ #include <stdlib.h> #include "pop3wrapper.h" #include "mailtypes.h" #include "logindialog.h" -#include <libetpan/mailpop3.h> -#include <libetpan/mailmime.h> -#include <libetpan/data_message_driver.h> +#include <libetpan/libetpan.h> +#include <qpe/global.h> #include <qfile.h> /* we don't fetch messages larger than 5 MB */ #define HARD_MSG_SIZE_LIMIT 5242880 @@ -111,8 +110,9 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 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; @@ -131,8 +131,9 @@ void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) 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)); } void POP3wrapper::login() { diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index b738cca..7502720 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -25,8 +25,9 @@ public: protected: void login(); void logout(); - + POP3account *account; + mailpop3 *m_pop3; }; #endif |