author | alwin <alwin> | 2003-12-27 18:23:23 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-27 18:23:23 (UTC) |
commit | 7812187f6732eef351e501d993aa664b7e351cbb (patch) (side-by-side diff) | |
tree | fe2ed5fc0d8c67983956ecf543a54d2e6355a627 /noncore/net/mail/libmailwrapper | |
parent | 583f9d5f33fa055fe8ee612f344d06faae1ef330 (diff) | |
download | opie-7812187f6732eef351e501d993aa664b7e351cbb.zip opie-7812187f6732eef351e501d993aa664b7e351cbb.tar.gz opie-7812187f6732eef351e501d993aa664b7e351cbb.tar.bz2 |
folder handling for imap mostly impelemented, context menus for
imap-mail-folders implemented.
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/abstractmail.h | 9 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 124 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mailwrapper.h | 9 |
5 files changed, 133 insertions, 17 deletions
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h index 509b68e..b609aa7 100644 --- a/noncore/net/mail/libmailwrapper/abstractmail.h +++ b/noncore/net/mail/libmailwrapper/abstractmail.h @@ -27,8 +27,17 @@ public: virtual void deleteMail(const RecMail&mail)=0; virtual void answeredMail(const RecMail&mail)=0; virtual void cleanMimeCache(){}; + virtual int deleteAllMail(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 deleteMbox(const Folder*){return 1;} static AbstractMail* getWrapper(IMAPaccount *a); static AbstractMail* getWrapper(POP3account *a); /* mbox only! */ diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp index ab20249..406c57c 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp @@ -1,8 +1,7 @@ - #include <stdlib.h> - #include <libetpan/libetpan.h> +#include <qpe/global.h> #include "imapwrapper.h" #include "mailtypes.h" #include "logindialog.h" @@ -70,18 +69,18 @@ void IMAPwrapper::login() if ( err != MAILIMAP_NO_ERROR && err != MAILIMAP_NO_ERROR_AUTHENTICATED && err != MAILIMAP_NO_ERROR_NON_AUTHENTICATED ) { - qDebug("error connecting server: %s",m_imap->imap_response); + Global::statusMessage(tr("error connecting imap server: %1").arg(m_imap->imap_response)); mailimap_free( m_imap ); m_imap = 0; return; } /* login */ err = mailimap_login_simple( m_imap, (char*)user, (char*)pass ); if ( err != MAILIMAP_NO_ERROR ) { - qDebug("error logging in imap: %s",m_imap->imap_response); + Global::statusMessage(tr("error logging in imap server: %1").arg(m_imap->imap_response)); err = mailimap_close( m_imap ); mailimap_free( m_imap ); m_imap = 0; } @@ -114,17 +113,19 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) } /* select mailbox READONLY for operations */ err = mailimap_examine( m_imap, (char*)mb); if ( err != MAILIMAP_NO_ERROR ) { - qDebug("error selecting mailbox: %s",m_imap->imap_response); + Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); return; } int last = m_imap->imap_selection_info->sel_exists; if (last == 0) { - qDebug("mailbox has no mails"); + Global::statusMessage(tr("Mailbox has no mails")); return; + } else { + Global::statusMessage(tr("Mailbox has %1 mails").arg(last)); } /* the range has to start at 1!!! not with 0!!!! */ set = mailimap_set_new_interval( 1, last ); @@ -154,9 +155,9 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target ) target.append(m); } } } else { - qDebug("Error fetching headers: %s",m_imap->imap_response); + Global::statusMessage(tr("Error fetching headers: %1").arg(m_imap->imap_response)); } if (result) mailimap_fetch_list_free(result); } @@ -165,8 +166,10 @@ QList<Folder>* IMAPwrapper::listFolders() const char *path, *mask; int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; + clistcell*cur_flag = 0; + mailimap_mbx_list_flags*bflags = 0; QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); login(); @@ -183,18 +186,29 @@ QList<Folder>* IMAPwrapper::listFolders() mask = "INBOX" ; mailimap_mailbox_list *list; err = mailimap_list( m_imap, (char*)"", (char*)mask, &result ); QString del; + bool selectable = true; + bool no_inferiors = false; if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( int i = result->count; i > 0; i-- ) { list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; del = list->mb_delimiter; - folders->append( new IMAPFolder(temp,del,true,account->getPrefix())); current = current->next; + if ( (bflags = list->mb_flag) ) { + selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& + bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); + for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { + if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { + no_inferiors = true; + } + } + } + folders->append( new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); } } else { qDebug("error fetching folders: %s",m_imap->imap_response); } @@ -206,14 +220,13 @@ QList<Folder>* IMAPwrapper::listFolders() mask = "*" ; path = account->getPrefix().latin1(); if (!path) path = ""; qDebug(path); - bool selectable = true; - mailimap_mbx_list_flags*bflags; err = mailimap_list( m_imap, (char*)path, (char*)mask, &result ); if ( err == MAILIMAP_NO_ERROR ) { current = result->first; for ( current=clist_begin(result);current!=NULL;current=clist_next(current)) { + no_inferiors = false; list = (mailimap_mailbox_list *) current->data; // it is better use the deep copy mechanism of qt itself // instead of using strdup! temp = list->mb_name; @@ -223,11 +236,16 @@ QList<Folder>* IMAPwrapper::listFolders() continue; if ( (bflags = list->mb_flag) ) { selectable = !(bflags->mbf_type==MAILIMAP_MBX_LIST_FLAGS_SFLAG&& bflags->mbf_sflag==MAILIMAP_MBX_LIST_SFLAG_NOSELECT); + for(cur_flag=clist_begin(bflags->mbf_oflags);cur_flag;cur_flag=clist_next(cur_flag)) { + if ( ((mailimap_mbx_list_oflag*)cur_flag->data)->of_type==MAILIMAP_MBX_LIST_OFLAG_NOINFERIORS) { + no_inferiors = true; + } + } } del = list->mb_delimiter; - folders->append(new IMAPFolder(temp,del,selectable,account->getPrefix())); + folders->append(new IMAPFolder(temp,del,selectable,no_inferiors,account->getPrefix())); } } else { qDebug("error fetching folders %s",m_imap->imap_response); } @@ -817,4 +835,88 @@ encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&pa encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part) { return fetchRawPart(mail,part.Positionlist(),false); } + +int IMAPwrapper::deleteAllMail(const Folder*folder) +{ + login(); + if (!m_imap) { + return 0; + } + mailimap_flag_list*flist; + mailimap_set *set; + mailimap_store_att_flags * store_flags; + int err = mailimap_select( m_imap, folder->getName().latin1()); + if ( err != MAILIMAP_NO_ERROR ) { + Global::statusMessage(tr("error selecting mailbox: %1").arg(m_imap->imap_response)); + return 0; + } + int last = m_imap->imap_selection_info->sel_exists; + if (last == 0) { + Global::statusMessage(tr("Mailbox has no mails!")); + return 0; + } + flist = mailimap_flag_list_new_empty(); + mailimap_flag_list_add(flist,mailimap_flag_new_deleted()); + store_flags = mailimap_store_att_flags_new_set_flags(flist); + set = mailimap_set_new_interval( 1, last ); + err = mailimap_store(m_imap,set,store_flags); + mailimap_set_free( set ); + mailimap_store_att_flags_free(store_flags); + if (err != MAILIMAP_NO_ERROR) { + Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); + return 0; + } + qDebug("deleting mail: %s",m_imap->imap_response); + /* should we realy do that at this moment? */ + err = mailimap_expunge(m_imap); + if (err != MAILIMAP_NO_ERROR) { + Global::statusMessage(tr("error deleting mail: %s").arg(m_imap->imap_response)); + 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; +} diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h index f046297..9b20288 100644 --- a/noncore/net/mail/libmailwrapper/imapwrapper.h +++ b/noncore/net/mail/libmailwrapper/imapwrapper.h @@ -26,14 +26,18 @@ public: virtual void listMessages(const QString & mailbox,QList<RecMail>&target ); 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*); diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp index 6479783..9398823 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp @@ -27,10 +27,10 @@ const QString& Folder::Separator()const { return separator; } -IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,const QString&prefix ) - : Folder( name,sep ),m_MaySelect(select) +IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) + : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) { // Decode IMAP foldername nameDisplay = IMAPFolder::decodeFolderName( name ); qDebug( "folder " + name + " - displayed as " + nameDisplay ); diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h index 8fd886f..a60777d 100644 --- a/noncore/net/mail/libmailwrapper/mailwrapper.h +++ b/noncore/net/mail/libmailwrapper/mailwrapper.h @@ -68,9 +68,10 @@ class Folder : public QObject public: Folder( const QString&init_name,const QString&sep ); const QString&getDisplayName()const { return nameDisplay; } const QString&getName()const { return name; } - virtual bool may_select()const{return true;}; + virtual bool may_select()const{return true;} + virtual bool no_inferior()const{return true;} const QString&Separator()const; protected: QString nameDisplay, name, separator; @@ -79,13 +80,13 @@ protected: class IMAPFolder : public Folder { public: - IMAPFolder(const QString&name, const QString&sep, bool select=true,const QString&prefix="" ); + IMAPFolder(const QString&name, const QString&sep, bool select=true,bool noinf=false,const QString&prefix="" ); virtual bool may_select()const{return m_MaySelect;} + virtual bool no_inferior()const{return m_NoInferior;} private: static QString decodeFolderName( const QString &name ); - bool m_MaySelect; - + bool m_MaySelect,m_NoInferior; }; #endif |