From 7812187f6732eef351e501d993aa664b7e351cbb Mon Sep 17 00:00:00 2001 From: alwin Date: Sat, 27 Dec 2003 18:23:23 +0000 Subject: folder handling for imap mostly impelemented, context menus for imap-mail-folders implemented. --- diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h index 509b68e..b609aa7 100644 --- a/noncore/net/mail/abstractmail.h +++ b/noncore/net/mail/abstractmail.h @@ -28,6 +28,15 @@ 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); diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 59e8bc0..8aac14b 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp @@ -2,11 +2,13 @@ #include "accountview.h" #include "mailtypes.h" #include "defines.h" +#include "newmaildir.h" +#include +#include /** * POP3 Account stuff */ - POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) : AccountViewItem( parent ) { @@ -128,7 +130,12 @@ IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start void IMAPviewItem::refresh(QList&) { - if (childCount()>0) return; + refreshFolders(false); +} + +void IMAPviewItem::refreshFolders(bool force) +{ + if (childCount()>0 && force==false) return; QList *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); @@ -164,18 +171,61 @@ void IMAPviewItem::refresh(QList&) if (pitem) { titem = item; item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); - item->setSelectable(it->may_select()); /* setup the short name */ item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); item = titem; } else { item = new IMAPfolderItem( it, this , item ); - item->setSelectable(it->may_select()); } } delete folders; } +QPopupMenu * IMAPviewItem::getContextMenu() +{ + QPopupMenu *m = new QPopupMenu(0); + if (m) { + m->insertItem(QObject::tr("Refresh folder list","IMAPviewItem"),0); + m->insertItem(QObject::tr("Create new folder","IMAPviewItem"),1); + m->insertSeparator(); + m->insertItem(QObject::tr("Disconnect","IMAPviewItem"),2); + } + return m; +} + +void IMAPviewItem::createNewFolder() +{ + Newmdirdlg ndirdlg; + ndirdlg.showMaximized(); + if (ndirdlg.exec()) { + QString ndir = ndirdlg.Newdir(); + bool makesubs = ndirdlg.subpossible(); + QString delemiter = "/"; + IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); + if (item) { + delemiter = item->Delemiter(); + } + if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { + refreshFolders(true); + } + } +} + +void IMAPviewItem::contextMenuSelected(int id) +{ + qDebug("Id selected: %i",id); + switch (id) { + case 0: + refreshFolders(true); + break; + case 1: + createNewFolder(); + break; + default: + break; + } +} + RecBody IMAPviewItem::fetchBody(const RecMail&) { return RecBody(); @@ -212,6 +262,11 @@ IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QLi setText( 0, folder->getDisplayName() ); } +const QString& IMAPfolderItem::Delemiter()const +{ + return folder->Separator(); +} + bool IMAPfolderItem::matchName(const QString&name)const { return folder->getDisplayName()==name; @@ -219,8 +274,11 @@ bool IMAPfolderItem::matchName(const QString&name)const void IMAPfolderItem::refresh(QList&target) { - if (folder->may_select()) + if (folder->may_select()) { imap->getWrapper()->listMessages( folder->getName(),target ); + } else { + target.clear(); + } } RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) @@ -228,6 +286,90 @@ RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) return imap->getWrapper()->fetchBody(aMail); } +QPopupMenu * IMAPfolderItem::getContextMenu() +{ + QPopupMenu *m = new QPopupMenu(0); + if (m) { + if (folder->may_select()) { + m->insertItem(QObject::tr("Refresh header list","IMAPfolderItem"),0); + m->insertItem(QObject::tr("Delete all mails","IMAPfolderItem"),1); + } + if (folder->no_inferior()==false) { + m->insertItem(QObject::tr("Create new subfolder","IMAPfolderItem"),2); + } + if (folder->getDisplayName().lower()!="inbox") { + m->insertItem(QObject::tr("Delete folder","IMAPfolderItem"),3); + } + } + return m; +} + +void IMAPfolderItem::deleteAllMails() +{ + int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails","IMAPfolderItem"), + QObject::tr("
Realy delete all mails in box
%1
","IMAPfolderItem").arg(folder->getDisplayName()), + QObject::tr("Yes","IMAPfolderItem"), + QObject::tr("No","IMAPfolderItem"),QString::null,1,1); + qDebug("Auswahl: %i",yesno); + if (yesno == 0) { + if (imap->getWrapper()->deleteAllMail(folder)) { + AccountView * view = (AccountView*)listView(); + if (view) view->refreshCurrent(); + } + } +} + +void IMAPfolderItem::createNewFolder() +{ + Newmdirdlg ndirdlg; + ndirdlg.showMaximized(); + if (ndirdlg.exec()) { + QString ndir = ndirdlg.Newdir(); + bool makesubs = ndirdlg.subpossible(); + QString delemiter = Delemiter(); + if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { + imap->refreshFolders(true); + } + } +} + +void IMAPfolderItem::deleteFolder() +{ + int yesno = QMessageBox::warning(0,QObject::tr("Delete folder","IMAPfolderItem"), + QObject::tr("
Realy delete folder
%1
and all if it content?
","IMAPfolderItem").arg(folder->getDisplayName()), + QObject::tr("Yes","IMAPfolderItem"), + QObject::tr("No","IMAPfolderItem"),QString::null,1,1); + qDebug("Auswahl: %i",yesno); + if (yesno == 0) { + if (imap->getWrapper()->deleteMbox(folder)) { + /* be carefull - after that this object is destroyd so don't call + * any member of it after that call!!*/ + imap->refreshFolders(true); + } + } +} + +void IMAPfolderItem::contextMenuSelected(int id) +{ + qDebug("Selected id: %i",id); + AccountView * view = (AccountView*)listView(); + switch(id) { + case 0: + view->refreshCurrent(); + break; + case 1: + deleteAllMails(); + break; + case 2: + createNewFolder(); + break; + case 3: + deleteFolder(); + break; + default: + break; + } +} /** * Generic stuff @@ -237,10 +379,33 @@ AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) : QListView( parent, name, flags ) { connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), - SLOT( refresh( QListViewItem * ) ) ); + SLOT( refresh( QListViewItem * ) ) ); + connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, + SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); + setSorting(0); } +void AccountView::slotContextMenu(int id) +{ + AccountViewItem *view = static_cast(currentItem()); + if (!view) return; + view->contextMenuSelected(id); +} + +void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) +{ + if (button==1) {return;} + if (!item) return; + AccountViewItem *view = static_cast(item); + QPopupMenu*m = view->getContextMenu(); + if (!m) return; + connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); + m->setFocus(); + m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); + delete m; +} + void AccountView::populate( QList list ) { clear(); @@ -277,6 +442,7 @@ void AccountView::refresh(QListViewItem *item) { void AccountView::refreshCurrent() { + m_currentItem = currentItem(); if ( !m_currentItem ) return; QList headerlist; headerlist.setAutoDelete(true); @@ -378,4 +544,3 @@ RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) { return mbox->getWrapper()->fetchBody(aMail); } - diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index 35499ac..e7fe038 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h @@ -11,6 +11,7 @@ class POP3wrapper; class RecMail; class RecBody; +class QPopupMenu; class AccountViewItem : public QListViewItem { @@ -21,6 +22,8 @@ public: AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {} virtual void refresh(QList&)=0; virtual RecBody fetchBody(const RecMail&)=0; + virtual QPopupMenu * getContextMenu(){return 0;}; + virtual void contextMenuSelected(int){} }; class POP3viewItem : public AccountViewItem @@ -55,16 +58,20 @@ class IMAPfolderItem; class IMAPviewItem : public AccountViewItem { - + friend class IMAPfolderItem; public: IMAPviewItem( IMAPaccount *a, QListView *parent ); ~IMAPviewItem(); virtual void refresh(QList&); virtual RecBody fetchBody(const RecMail&); AbstractMail *getWrapper(); + virtual QPopupMenu * getContextMenu(); + virtual void contextMenuSelected(int); protected: IMAPfolderItem*findSubItem(const QString&path,IMAPfolderItem*start=0); + virtual void refreshFolders(bool force=false); + virtual void createNewFolder(); private: IMAPaccount *account; @@ -81,6 +88,14 @@ public: virtual void refresh(QList&); virtual RecBody fetchBody(const RecMail&); bool matchName(const QString&name)const; + virtual void deleteAllMails(); + virtual QPopupMenu * getContextMenu(); + virtual void contextMenuSelected(int); + virtual const QString& Delemiter()const; +protected: + virtual void createNewFolder(); + virtual void deleteFolder(); + private: Folder *folder; IMAPviewItem *imap; @@ -126,10 +141,12 @@ public: RecBody fetchBody(const RecMail&aMail); public slots: - void refreshAll(); - void refresh(QListViewItem *item); - void refreshCurrent(); - + virtual void refreshAll(); + virtual void refresh(QListViewItem *item); + virtual void refreshCurrent(); + virtual void slotHold(int, QListViewItem *,const QPoint&,int); + virtual void slotContextMenu(int id); + signals: void refreshMailview(QList*); diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp index ab20249..406c57c 100644 --- a/noncore/net/mail/imapwrapper.cpp +++ b/noncore/net/mail/imapwrapper.cpp @@ -1,7 +1,6 @@ - #include - #include +#include #include "imapwrapper.h" #include "mailtypes.h" @@ -71,7 +70,7 @@ 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; @@ -80,7 +79,7 @@ void IMAPwrapper::login() /* 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; @@ -115,15 +114,17 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList &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!!!! */ @@ -155,7 +156,7 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList &target ) } } } 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); } @@ -166,6 +167,8 @@ QList* IMAPwrapper::listFolders() int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; + clistcell*cur_flag = 0; + mailimap_mbx_list_flags*bflags = 0; QList * folders = new QList(); folders->setAutoDelete( false ); @@ -184,6 +187,8 @@ QList* IMAPwrapper::listFolders() 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-- ) { @@ -192,8 +197,17 @@ QList* IMAPwrapper::listFolders() // 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); @@ -207,12 +221,11 @@ QList* IMAPwrapper::listFolders() 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! @@ -224,9 +237,14 @@ QList* IMAPwrapper::listFolders() 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); @@ -818,3 +836,87 @@ 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/imapwrapper.h b/noncore/net/mail/imapwrapper.h index f046297..9b20288 100644 --- a/noncore/net/mail/imapwrapper.h +++ b/noncore/net/mail/imapwrapper.h @@ -27,12 +27,16 @@ public: 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: 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 @@ -28,6 +28,15 @@ 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); 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,7 +1,6 @@ - #include - #include +#include #include "imapwrapper.h" #include "mailtypes.h" @@ -71,7 +70,7 @@ 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; @@ -80,7 +79,7 @@ void IMAPwrapper::login() /* 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; @@ -115,15 +114,17 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList &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!!!! */ @@ -155,7 +156,7 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList &target ) } } } 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); } @@ -166,6 +167,8 @@ QList* IMAPwrapper::listFolders() int err = MAILIMAP_NO_ERROR; clist *result = 0; clistcell *current = 0; + clistcell*cur_flag = 0; + mailimap_mbx_list_flags*bflags = 0; QList * folders = new QList(); folders->setAutoDelete( false ); @@ -184,6 +187,8 @@ QList* IMAPwrapper::listFolders() 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-- ) { @@ -192,8 +197,17 @@ QList* IMAPwrapper::listFolders() // 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); @@ -207,12 +221,11 @@ QList* IMAPwrapper::listFolders() 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! @@ -224,9 +237,14 @@ QList* IMAPwrapper::listFolders() 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); @@ -818,3 +836,87 @@ 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 @@ -27,12 +27,16 @@ public: 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: 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 @@ -28,8 +28,8 @@ 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 ); 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 @@ -69,7 +69,8 @@ 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: @@ -80,12 +81,12 @@ 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; - + static QString decodeFolderName( const QString &name ); + bool m_MaySelect,m_NoInferior; }; #endif diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro index ea5fb58..2c15a7b 100644 --- a/noncore/net/mail/mail.pro +++ b/noncore/net/mail/mail.pro @@ -15,13 +15,14 @@ HEADERS = defines.h \ mailtypes.h \ mailistviewitem.h \ pop3wrapper.h \ - abstractmail.h \ - settingsdialog.h \ - statuswidget.h \ - smtpwrapper.h \ - genericwrapper.h \ - mboxwrapper.h \ - sendmailprogress.h + abstractmail.h \ + settingsdialog.h \ + statuswidget.h \ + smtpwrapper.h \ + genericwrapper.h \ + mboxwrapper.h \ + sendmailprogress.h \ + newmaildir.h SOURCES = main.cpp \ opiemail.cpp \ @@ -38,13 +39,14 @@ SOURCES = main.cpp \ settings.cpp \ mailtypes.cpp \ pop3wrapper.cpp \ - abstractmail.cpp \ - settingsdialog.cpp \ - statuswidget.cpp \ - smtpwrapper.cpp \ - genericwrapper.cpp \ - mboxwrapper.cpp \ - sendmailprogress.cpp + abstractmail.cpp \ + settingsdialog.cpp \ + statuswidget.cpp \ + smtpwrapper.cpp \ + genericwrapper.cpp \ + mboxwrapper.cpp \ + sendmailprogress.cpp \ + newmaildir.cpp INTERFACES = editaccountsui.ui \ selectmailtypeui.ui \ @@ -55,9 +57,10 @@ INTERFACES = editaccountsui.ui \ addresspickerui.ui \ logindialogui.ui \ composemailui.ui \ - settingsdialogui.ui \ - statuswidgetui.ui \ - sendmailprogressui.ui + settingsdialogui.ui \ + statuswidgetui.ui \ + sendmailprogressui.ui \ + newmaildirui.ui INCLUDEPATH += $(OPIEDIR)/include diff --git a/noncore/net/mail/mailwrapper.cpp b/noncore/net/mail/mailwrapper.cpp index 6479783..9398823 100644 --- a/noncore/net/mail/mailwrapper.cpp +++ b/noncore/net/mail/mailwrapper.cpp @@ -28,8 +28,8 @@ 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 ); diff --git a/noncore/net/mail/mailwrapper.h b/noncore/net/mail/mailwrapper.h index 8fd886f..a60777d 100644 --- a/noncore/net/mail/mailwrapper.h +++ b/noncore/net/mail/mailwrapper.h @@ -69,7 +69,8 @@ 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: @@ -80,12 +81,12 @@ 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; - + static QString decodeFolderName( const QString &name ); + bool m_MaySelect,m_NoInferior; }; #endif diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp index dc8c188..cf4cbe8 100644 --- a/noncore/net/mail/mainwindow.cpp +++ b/noncore/net/mail/mainwindow.cpp @@ -117,24 +117,18 @@ MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) layout->setStretchFactor( folderView, 1 ); layout->setStretchFactor( mailView, 2 ); - slotAdjustLayout(); QPEApplication::setStylusOperation( mailView->viewport(),QPEApplication::RightOnHold); - + QPEApplication::setStylusOperation( folderView->viewport(),QPEApplication::RightOnHold); + connect( mailView, SIGNAL( mouseButtonClicked(int, QListViewItem *,const QPoint&,int ) ),this, SLOT( mailLeftClicked( int, QListViewItem *,const QPoint&,int ) ) ); - connect( mailView, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, SLOT( mailHold( int, QListViewItem *,const QPoint&,int ) ) ); -#if 0 - connect( mailView, SIGNAL( rightButtonClicked( QListViewItem *,const QPoint&,int ) ),this, - SLOT( mailHold(QListViewItem *,const QPoint&,int) )); -#endif connect(folderView, SIGNAL(refreshMailview(QList*)),this,SLOT(refreshMailView(QList*))); - QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); - + QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); } diff --git a/noncore/net/mail/newmaildir.cpp b/noncore/net/mail/newmaildir.cpp new file mode 100644 index 0000000..3fc66f4 --- a/dev/null +++ b/noncore/net/mail/newmaildir.cpp @@ -0,0 +1,34 @@ +#include "newmaildir.h" +#include +#include +#include +#include + +Newmdirdlg::Newmdirdlg( QWidget* parent, const char* name) + : Newmdirdlgui(parent,name,true),ndir(""),possible_subs(false) +{ +} + +Newmdirdlg::~Newmdirdlg() +{ +} + +void Newmdirdlg::accept() +{ + ndir = dirnameEdit->text(); + possible_subs = subdirsPossibleBox->isChecked(); + if (ndir.isEmpty()) { + return; + } + Newmdirdlgui::accept(); +} + +const QString&Newmdirdlg::Newdir()const +{ + return ndir; +} + +const bool Newmdirdlg::subpossible()const +{ + return possible_subs; +} diff --git a/noncore/net/mail/newmaildir.h b/noncore/net/mail/newmaildir.h new file mode 100644 index 0000000..1eb904e --- a/dev/null +++ b/noncore/net/mail/newmaildir.h @@ -0,0 +1,20 @@ +#include "newmaildirui.h" +#include + +class Newmdirdlg : public Newmdirdlgui +{ + Q_OBJECT +public: + Newmdirdlg( QWidget* parent = 0, const char* name = 0); + ~Newmdirdlg(); + + const QString&Newdir()const; + const bool subpossible()const; + +protected slots: + virtual void accept(); + +protected: + QString ndir; + bool possible_subs; +}; diff --git a/noncore/net/mail/newmaildirui.ui b/noncore/net/mail/newmaildirui.ui new file mode 100644 index 0000000..72b2d04 --- a/dev/null +++ b/noncore/net/mail/newmaildirui.ui @@ -0,0 +1,100 @@ + +Newmdirdlgui + + QDialog + + name + newmdirdlg + + + geometry + + 0 + 0 + 223 + 110 + + + + caption + Enter directory name + + + + margin + 11 + + + spacing + 6 + + + QLayoutWidget + + name + Layout5 + + + + margin + 0 + + + spacing + 6 + + + QLabel + + name + dirnameLabel + + + text + Directory name: + + + + QLineEdit + + name + dirnameEdit + + + + + + QCheckBox + + name + subdirsPossibleBox + + + text + Directory contains other subdirs + + + + + name + Spacer4 + + + orientation + Vertical + + + sizeType + Expanding + + + sizeHint + + 20 + 20 + + + + + + -- cgit v0.9.0.2