-rw-r--r-- | noncore/net/mail/abstractmail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/abstractmail.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 40 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailtypes.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/mailtypes.h | 7 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 21 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 1 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 11 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 2 |
18 files changed, 180 insertions, 2 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp index 416795b..f303d72 100644 --- a/noncore/net/mail/abstractmail.cpp +++ b/noncore/net/mail/abstractmail.cpp @@ -43,48 +43,52 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin mimetype = MAILMIME_MECHANISM_8BIT; } else if (enc.lower()=="binary") { mimetype = MAILMIME_MECHANISM_BINARY; } int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, &result_text,&target_length); encodedString* result = new encodedString(); if (err == MAILIMF_NO_ERROR) { result->setContent(result_text,target_length); } qDebug("Decode string finished"); return result; } QString AbstractMail::convert_String(const char*text) { size_t index = 0; char*res = 0; /* attention - doesn't work with arm systems! */ int err = mailmime_encoded_phrase_parse("iso-8859-1", text, strlen(text),&index, "iso-8859-1",&res); if (err != MAILIMF_NO_ERROR) { if (res) free(res); return QString(text); } if (res) { QString result(res); free(res); return result; } return QString(text); } /* cp & paste from launcher */ QString AbstractMail::gen_attachment_id() { QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; QTextStream stream(&file); return "{" + stream.read().stripWhiteSpace() + "}"; } +int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) +{ + return 0; +} diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index 5dc4cab..dab9e10 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h @@ -1,51 +1,53 @@ #ifndef __abstract_mail_ #define __abstract_mail_ #include <qobject.h> #include "settings.h" class RecMail; class RecBody; class RecPart; class IMAPwrapper; class POP3wrapper; class Folder; class encodedString; +struct folderStat; class AbstractMail:public QObject { Q_OBJECT public: AbstractMail(){}; virtual ~AbstractMail(){} virtual QList<Folder>* listFolders()=0; virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; virtual RecBody fetchBody(const RecMail&mail)=0; virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; virtual void deleteMail(const RecMail&mail)=0; virtual void answeredMail(const RecMail&mail)=0; virtual void cleanMimeCache(){}; virtual int deleteAllMail(const Folder*){return 1;} virtual int deleteMbox(const Folder*){return 1;} /* mail box methods */ /* parameter is the box to create. * if the implementing subclass has prefixes, * them has to be appended automatic. */ - virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} + virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); /* mbox only! */ static AbstractMail* getWrapper(const QString&a); protected: static encodedString*decode_String(const encodedString*text,const QString&enc); static QString convert_String(const char*text); static QString gen_attachment_id(); }; #endif diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index b437df0..f1d42c2 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp @@ -889,48 +889,88 @@ int IMAPwrapper::deleteAllMail(const Folder*folder) return 0; } qDebug("Delete successfull %s",m_imap->imap_response); return 1; } int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) { if (folder.length()==0) return 0; login(); if (!m_imap) {return 0;} QString pre = account->getPrefix(); if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { pre+=delemiter; } if (parentfolder) { pre += parentfolder->getDisplayName()+delemiter; } pre+=folder; if (getsubfolder) { if (delemiter.length()>0) { pre+=delemiter; } else { Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); return 0; } } qDebug("Creating %s",pre.latin1()); int res = mailimap_create(m_imap,pre.latin1()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } int IMAPwrapper::deleteMbox(const Folder*folder) { if (!folder) return 0; login(); if (!m_imap) {return 0;} int res = mailimap_delete(m_imap,folder->getName()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } + +void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) +{ + mailimap_status_att_list * att_list =0; + mailimap_mailbox_data_status * status=0; + clistiter * cur = 0; + int r = 0; + int res = 0; + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + login(); + if (!m_imap) { + return; + } + att_list = mailimap_status_att_list_new_empty(); + if (!att_list) return; + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); + r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); + for (cur = clist_begin(status->st_info_list); + cur != NULL ; cur = clist_next(cur)) { + mailimap_status_info * status_info; + status_info = (mailimap_status_info *)clist_content(cur); + switch (status_info->st_att) { + case MAILIMAP_STATUS_ATT_MESSAGES: + target_stat.message_count = status_info->st_value; + break; + case MAILIMAP_STATUS_ATT_RECENT: + target_stat.message_recent = status_info->st_value; + break; + case MAILIMAP_STATUS_ATT_UNSEEN: + target_stat.message_unseen = status_info->st_value; + break; + } + } + mailimap_mailbox_data_status_free(status); + mailimap_status_att_list_free(att_list); +} diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h index 7941046..8f5a2b5 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h @@ -1,67 +1,68 @@ #ifndef __IMAPWRAPPER #define __IMAPWRAPPER #include <qlist.h> #include "mailwrapper.h" #include "abstractmail.h" #include <libetpan/clist.h> struct mailimap; struct mailimap_body; struct mailimap_body_type_1part; struct mailimap_body_type_text; struct mailimap_body_type_basic; struct mailimap_body_type_msg; struct mailimap_body_type_mpart; struct mailimap_body_fields; struct mailimap_msg_att; class encodedString; class IMAPwrapper : public AbstractMail { Q_OBJECT public: IMAPwrapper( IMAPaccount *a ); virtual ~IMAPwrapper(); virtual QList<Folder>* listFolders(); virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual int deleteAllMail(const Folder*folder); virtual RecBody fetchBody(const RecMail&mail); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); virtual int deleteMbox(const Folder*folder); static void imap_progress( size_t current, size_t maximum ); protected: RecMail*parse_list_result(mailimap_msg_att*); void login(); void logout(); virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); /* just helpers */ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); static QStringList address_list_to_stringlist(clist*list); IMAPaccount *account; mailimap *m_imap; }; #endif diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp index 416795b..f303d72 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.cpp +++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp @@ -43,48 +43,52 @@ encodedString* AbstractMail::decode_String(const encodedString*text,const QStrin mimetype = MAILMIME_MECHANISM_8BIT; } else if (enc.lower()=="binary") { mimetype = MAILMIME_MECHANISM_BINARY; } int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype, &result_text,&target_length); encodedString* result = new encodedString(); if (err == MAILIMF_NO_ERROR) { result->setContent(result_text,target_length); } qDebug("Decode string finished"); return result; } QString AbstractMail::convert_String(const char*text) { size_t index = 0; char*res = 0; /* attention - doesn't work with arm systems! */ int err = mailmime_encoded_phrase_parse("iso-8859-1", text, strlen(text),&index, "iso-8859-1",&res); if (err != MAILIMF_NO_ERROR) { if (res) free(res); return QString(text); } if (res) { QString result(res); free(res); return result; } return QString(text); } /* cp & paste from launcher */ QString AbstractMail::gen_attachment_id() { QFile file( "/proc/sys/kernel/random/uuid" ); if (!file.open(IO_ReadOnly ) ) return QString::null; QTextStream stream(&file); return "{" + stream.read().stripWhiteSpace() + "}"; } +int AbstractMail::createMbox(const QString&,const Folder*,const QString& delemiter,bool) +{ + return 0; +} diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 5dc4cab..dab9e10 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -1,51 +1,53 @@ #ifndef __abstract_mail_ #define __abstract_mail_ #include <qobject.h> #include "settings.h" class RecMail; class RecBody; class RecPart; class IMAPwrapper; class POP3wrapper; class Folder; class encodedString; +struct folderStat; class AbstractMail:public QObject { Q_OBJECT public: AbstractMail(){}; virtual ~AbstractMail(){} virtual QList<Folder>* listFolders()=0; virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0; + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX")=0; virtual RecBody fetchBody(const RecMail&mail)=0; virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0; virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0; virtual void deleteMail(const RecMail&mail)=0; virtual void answeredMail(const RecMail&mail)=0; virtual void cleanMimeCache(){}; virtual int deleteAllMail(const Folder*){return 1;} virtual int deleteMbox(const Folder*){return 1;} /* mail box methods */ /* parameter is the box to create. * if the implementing subclass has prefixes, * them has to be appended automatic. */ - virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false){return 0;} + virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); /* mbox only! */ static AbstractMail* getWrapper(const QString&a); protected: static encodedString*decode_String(const encodedString*text,const QString&enc); static QString convert_String(const char*text); static QString gen_attachment_id(); }; #endif diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index b437df0..f1d42c2 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -889,48 +889,88 @@ int IMAPwrapper::deleteAllMail(const Folder*folder) return 0; } qDebug("Delete successfull %s",m_imap->imap_response); return 1; } int IMAPwrapper::createMbox(const QString&folder,const Folder*parentfolder,const QString& delemiter,bool getsubfolder) { if (folder.length()==0) return 0; login(); if (!m_imap) {return 0;} QString pre = account->getPrefix(); if (delemiter.length()>0 && pre.findRev(delemiter)!=pre.length()-1) { pre+=delemiter; } if (parentfolder) { pre += parentfolder->getDisplayName()+delemiter; } pre+=folder; if (getsubfolder) { if (delemiter.length()>0) { pre+=delemiter; } else { Global::statusMessage(tr("Cannot create folder %1 for holding subfolders").arg(pre)); return 0; } } qDebug("Creating %s",pre.latin1()); int res = mailimap_create(m_imap,pre.latin1()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } int IMAPwrapper::deleteMbox(const Folder*folder) { if (!folder) return 0; login(); if (!m_imap) {return 0;} int res = mailimap_delete(m_imap,folder->getName()); if (res != MAILIMAP_NO_ERROR) { Global::statusMessage(tr("%1").arg(m_imap->imap_response)); return 0; } return 1; } + +void IMAPwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) +{ + mailimap_status_att_list * att_list =0; + mailimap_mailbox_data_status * status=0; + clistiter * cur = 0; + int r = 0; + int res = 0; + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + login(); + if (!m_imap) { + return; + } + att_list = mailimap_status_att_list_new_empty(); + if (!att_list) return; + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_MESSAGES); + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_RECENT); + r = mailimap_status_att_list_add(att_list, MAILIMAP_STATUS_ATT_UNSEEN); + r = mailimap_status(m_imap, mailbox.latin1(), att_list, &status); + for (cur = clist_begin(status->st_info_list); + cur != NULL ; cur = clist_next(cur)) { + mailimap_status_info * status_info; + status_info = (mailimap_status_info *)clist_content(cur); + switch (status_info->st_att) { + case MAILIMAP_STATUS_ATT_MESSAGES: + target_stat.message_count = status_info->st_value; + break; + case MAILIMAP_STATUS_ATT_RECENT: + target_stat.message_recent = status_info->st_value; + break; + case MAILIMAP_STATUS_ATT_UNSEEN: + target_stat.message_unseen = status_info->st_value; + break; + } + } + mailimap_mailbox_data_status_free(status); + mailimap_status_att_list_free(att_list); +} diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index 7941046..8f5a2b5 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h @@ -1,67 +1,68 @@ #ifndef __IMAPWRAPPER #define __IMAPWRAPPER #include <qlist.h> #include "mailwrapper.h" #include "abstractmail.h" #include <libetpan/clist.h> struct mailimap; struct mailimap_body; struct mailimap_body_type_1part; struct mailimap_body_type_text; struct mailimap_body_type_basic; struct mailimap_body_type_msg; struct mailimap_body_type_mpart; struct mailimap_body_fields; struct mailimap_msg_att; class encodedString; class IMAPwrapper : public AbstractMail { Q_OBJECT public: IMAPwrapper( IMAPaccount *a ); virtual ~IMAPwrapper(); virtual QList<Folder>* listFolders(); virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual int deleteAllMail(const Folder*folder); virtual RecBody fetchBody(const RecMail&mail); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual int createMbox(const QString&,const Folder*parentfolder=0,const QString& delemiter="/",bool getsubfolder=false); virtual int deleteMbox(const Folder*folder); static void imap_progress( size_t current, size_t maximum ); protected: RecMail*parse_list_result(mailimap_msg_att*); void login(); void logout(); virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc=""); virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call); void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description); void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which); void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which); void fillSingleMsgPart(RecPart&target_part,mailimap_body_type_msg*which); void fillMultiPart(RecPart&target_part,mailimap_body_type_mpart*which); void traverseBody(const RecMail&mail,mailimap_body*body,RecBody&target_body,int current_recursion,QValueList<int>recList,int current_count=1); /* just helpers */ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which); static QStringList address_list_to_stringlist(clist*list); IMAPaccount *account; mailimap *m_imap; }; #endif diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h index abfbe65..05c4816 100644 --- a/noncore/net/mail/libmailwrapper/mailtypes.h +++ b/noncore/net/mail/libmailwrapper/mailtypes.h @@ -137,49 +137,56 @@ public: class encodedString { public: encodedString(); /* creates an new content string. it makes a deep copy of it! */ encodedString(const char*nContent,unsigned int length); /* Take over the nContent. Means: it will just copy the pointer, not the content. so make sure: No one else frees the string, the string has allocated with malloc for compatibility with c-based libs */ encodedString(char*nContent,unsigned int nSize); /* copy construkor - makes ALWAYS a deep copy!!!! */ encodedString(const encodedString&old); /* assign operator - makes ALWAYS a deep copy!!!! */ encodedString& operator=(const encodedString&old); /* destructor - cleans the content */ virtual ~encodedString(); /* returns a pointer to the content - do not delete yoursel! */ const char*Content()const; /* returns the lengths of the content 'cause it must not be a null-terminated string! */ const int Length()const; /* makes a deep copy of nContent! */ void setContent(const char*nContent,int nSize); /* Take over the nContent. Means: it will just copy the pointer, not the content. so make sure: No one else frees the string, the string has allocated with malloc for compatibility with c-based libs */ void setContent(char*nContent,int nSize); protected: char * content; unsigned int size; void init(); void copy_old(const encodedString&old); void clean(); }; +struct folderStat +{ + unsigned int message_count; + unsigned int message_unseen; + unsigned int message_recent; +}; + #endif diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 0aa33dd..540a971 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp @@ -256,48 +256,69 @@ int MBOXwrapper::deleteAllMail(const Folder*tfolder) 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; } +void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) +{ + mailfolder*folder = 0; + mailstorage*storage = mailstorage_new(NULL); + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + QString p = MBOXPath+"/"+mailbox; + QFile fi(p); + if (!fi.exists()) { + Global::statusMessage(tr("Mailbox doesn't exist.")); + return; + } + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); + folder = mailfolder_new( storage,(char*)p.latin1(),NULL); + r = mailfolder_connect(folder); + r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, + &target_stat.message_recent,&target_stat.message_unseen); + if (folder) mailfolder_free(folder); + if (storage) mailstorage_free(storage); +} diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 226a544..f822997 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h @@ -1,41 +1,42 @@ #ifndef __MBOX_WRAPPER_H #define __MBOX_WRAPPER_H #include "genericwrapper.h" #include <qstring.h> class RecMail; class RecBody; struct mailmbox_folder; class MBOXwrapper : public Genericwrapper { Q_OBJECT public: MBOXwrapper(const QString & dir); virtual ~MBOXwrapper(); virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); virtual QList<Folder>* listFolders(); + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); 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 de90dd1..d76d82a 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -171,48 +171,59 @@ void POP3wrapper::logout() } 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 = 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; int res = 1; 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; } return res; } + +void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) +{ + login(); + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + if (!m_pop3) return; + int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, + &target_stat.message_recent,&target_stat.message_unseen); +} diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index b3a42be..536cadc 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -1,37 +1,39 @@ #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(); + /* mailbox will be ignored */ + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 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; mailstorage*m_pop3; mailfolder*m_folder; }; #endif diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h index abfbe65..05c4816 100644 --- a/noncore/net/mail/mailtypes.h +++ b/noncore/net/mail/mailtypes.h @@ -137,49 +137,56 @@ public: class encodedString { public: encodedString(); /* creates an new content string. it makes a deep copy of it! */ encodedString(const char*nContent,unsigned int length); /* Take over the nContent. Means: it will just copy the pointer, not the content. so make sure: No one else frees the string, the string has allocated with malloc for compatibility with c-based libs */ encodedString(char*nContent,unsigned int nSize); /* copy construkor - makes ALWAYS a deep copy!!!! */ encodedString(const encodedString&old); /* assign operator - makes ALWAYS a deep copy!!!! */ encodedString& operator=(const encodedString&old); /* destructor - cleans the content */ virtual ~encodedString(); /* returns a pointer to the content - do not delete yoursel! */ const char*Content()const; /* returns the lengths of the content 'cause it must not be a null-terminated string! */ const int Length()const; /* makes a deep copy of nContent! */ void setContent(const char*nContent,int nSize); /* Take over the nContent. Means: it will just copy the pointer, not the content. so make sure: No one else frees the string, the string has allocated with malloc for compatibility with c-based libs */ void setContent(char*nContent,int nSize); protected: char * content; unsigned int size; void init(); void copy_old(const encodedString&old); void clean(); }; +struct folderStat +{ + unsigned int message_count; + unsigned int message_unseen; + unsigned int message_recent; +}; + #endif diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 0aa33dd..540a971 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp @@ -256,48 +256,69 @@ int MBOXwrapper::deleteAllMail(const Folder*tfolder) 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; } +void MBOXwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) +{ + mailfolder*folder = 0; + mailstorage*storage = mailstorage_new(NULL); + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + QString p = MBOXPath+"/"+mailbox; + QFile fi(p); + if (!fi.exists()) { + Global::statusMessage(tr("Mailbox doesn't exist.")); + return; + } + int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); + folder = mailfolder_new( storage,(char*)p.latin1(),NULL); + r = mailfolder_connect(folder); + r = mailsession_status_folder(folder->fld_session,(char*)mailbox.latin1(),&target_stat.message_count, + &target_stat.message_recent,&target_stat.message_unseen); + if (folder) mailfolder_free(folder); + if (storage) mailstorage_free(storage); +} diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index 226a544..f822997 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h @@ -1,41 +1,42 @@ #ifndef __MBOX_WRAPPER_H #define __MBOX_WRAPPER_H #include "genericwrapper.h" #include <qstring.h> class RecMail; class RecBody; struct mailmbox_folder; class MBOXwrapper : public Genericwrapper { Q_OBJECT public: MBOXwrapper(const QString & dir); virtual ~MBOXwrapper(); virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); virtual QList<Folder>* listFolders(); + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); 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/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index de90dd1..d76d82a 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -171,48 +171,59 @@ void POP3wrapper::logout() } 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 = 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; int res = 1; 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; } return res; } + +void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) +{ + login(); + target_stat.message_count = 0; + target_stat.message_unseen = 0; + target_stat.message_recent = 0; + if (!m_pop3) return; + int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, + &target_stat.message_recent,&target_stat.message_unseen); +} diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index b3a42be..536cadc 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h @@ -1,37 +1,39 @@ #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(); + /* mailbox will be ignored */ + virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 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; mailstorage*m_pop3; mailfolder*m_folder; }; #endif |