author | alwin <alwin> | 2003-12-28 02:45:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-28 02:45:07 (UTC) |
commit | d1a7eb08cad465c5fc0de53f75aaecf7803f0945 (patch) (side-by-side diff) | |
tree | 422b73af760cdd44e4fbbc96bd6876a15939ff19 /noncore/net/mail/libmailwrapper/mboxwrapper.cpp | |
parent | e889485e945d8fa9564566f286114be10d2a1ce5 (diff) | |
download | opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.zip opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.tar.gz opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.tar.bz2 |
- dir handling for mbox accounts (delete, new, delete all mail)
- fixed memory leaks in mbox account class
- reduced count of used string constants while using "tr" with context string
- mbox displays messages into global status bar
- fixed a possible raise condition when deleting a mail directory
Diffstat (limited to 'noncore/net/mail/libmailwrapper/mboxwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 126 |
1 files changed, 100 insertions, 26 deletions
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 @@ -3,7 +3,7 @@ #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) @@ -25,11 +25,8 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 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) { @@ -37,5 +34,4 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailfolder_free(folder); mailstorage_free(storage); - free(fname); return; } @@ -46,5 +42,4 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailfolder_free(folder); mailstorage_free(storage); - free(fname); return; } @@ -57,10 +52,10 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 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); @@ -111,5 +106,5 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) mailfolder_free(folder); mailstorage_free(storage); - free(fname); + Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); } @@ -135,8 +130,7 @@ void MBOXwrapper::deleteMail(const RecMail&mail) 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) { @@ -168,7 +162,7 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail ) 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) { @@ -206,6 +200,20 @@ void MBOXwrapper::mbox_progress( size_t current, size_t 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; } @@ -217,10 +225,10 @@ void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folde 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); @@ -237,10 +245,10 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 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); @@ -249,5 +257,5 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 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); @@ -256,5 +264,5 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) 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); @@ -279,4 +287,12 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 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()); @@ -289,5 +305,63 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 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; } |