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 | |
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
-rw-r--r-- | noncore/net/mail/accountview.cpp | 143 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 18 | ||||
-rw-r--r-- | noncore/net/mail/genericwrapper.h | 2 | ||||
-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 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 124 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 8 | ||||
-rw-r--r-- | noncore/net/mail/newmaildir.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/newmaildir.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.cpp | 7 | ||||
-rw-r--r-- | noncore/net/mail/pop3wrapper.h | 3 |
14 files changed, 373 insertions, 84 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 8aac14b..30765cf 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp @@ -124,423 +124,532 @@ IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start } } pitem=(IMAPfolderItem*)pitem->nextSibling(); } return pitem; } void IMAPviewItem::refresh(QList<RecMail>&) { refreshFolders(false); } void IMAPviewItem::refreshFolders(bool force) { if (childCount()>0 && force==false) return; QList<Folder> *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } Folder *it; QListViewItem*item = 0; QListViewItem*titem = 0; QString fname,del,search; int pos; // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! folders->setAutoDelete(false); for ( it = folders->first(); it; it = folders->next() ) { if (it->getDisplayName().lower()=="inbox") { item = new IMAPfolderItem( it, this , item ); folders->remove(it); qDebug("inbox found"); break; } } for ( it = folders->first(); it; it = folders->next() ) { fname = it->getDisplayName(); pos = fname.findRev(it->Separator()); if (pos != -1) { fname = fname.left(pos); } IMAPfolderItem*pitem = findSubItem(fname); if (pitem) { titem = item; item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); /* setup the short name */ item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); item = titem; } else { item = new IMAPfolderItem( it, this , item ); } } 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->insertItem(QObject::tr("Refresh folder list",contextName),0); + m->insertItem(QObject::tr("Create new folder",contextName),1); m->insertSeparator(); - m->insertItem(QObject::tr("Disconnect","IMAPviewItem"),2); + m->insertItem(QObject::tr("Disconnect",contextName),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(); } IMAPfolderItem::~IMAPfolderItem() { delete folder; } IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) : AccountViewItem( parent , after ) { folder = folderInit; imap = parent; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_IMAPFOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) : AccountViewItem( parent,after ) { folder = folderInit; imap = master; if (folder->getDisplayName().lower()!="inbox") { setPixmap( 0, PIXMAP_IMAPFOLDER ); } else { setPixmap( 0, PIXMAP_INBOXFOLDER); } setText( 0, folder->getDisplayName() ); } const QString& IMAPfolderItem::Delemiter()const { return folder->Separator(); } bool IMAPfolderItem::matchName(const QString&name)const { return folder->getDisplayName()==name; } void IMAPfolderItem::refresh(QList<RecMail>&target) { if (folder->may_select()) { imap->getWrapper()->listMessages( folder->getName(),target ); } else { target.clear(); } } 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); + m->insertItem(QObject::tr("Refresh header list",contextName),0); + m->insertItem(QObject::tr("Delete all mails",contextName),1); } if (folder->no_inferior()==false) { - m->insertItem(QObject::tr("Create new subfolder","IMAPfolderItem"),2); + m->insertItem(QObject::tr("Create new subfolder",contextName),2); } if (folder->getDisplayName().lower()!="inbox") { - m->insertItem(QObject::tr("Delete folder","IMAPfolderItem"),3); + m->insertItem(QObject::tr("Delete folder",contextName),3); } } return m; } void IMAPfolderItem::deleteAllMails() { - int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails","IMAPfolderItem"), - QObject::tr("<center>Realy delete all mails in box <br>%1</center>","IMAPfolderItem").arg(folder->getDisplayName()), - QObject::tr("Yes","IMAPfolderItem"), - QObject::tr("No","IMAPfolderItem"),QString::null,1,1); + int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), + QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()), + QObject::tr("Yes",contextName), + QObject::tr("No",contextName),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("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>","IMAPfolderItem").arg(folder->getDisplayName()), - QObject::tr("Yes","IMAPfolderItem"), - QObject::tr("No","IMAPfolderItem"),QString::null,1,1); + int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), + QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), + QObject::tr("Yes",contextName), + QObject::tr("No",contextName),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 + QListView*v=listView(); + IMAPviewItem * box = imap; + /* be carefull - after that this object is destroyd so don't use * any member of it after that call!!*/ imap->refreshFolders(true); + if (v) { + v->setSelected(box,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 */ +const QString AccountViewItem::contextName="AccountViewItem"; + AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) : QListView( parent, name, flags ) { connect( this, SIGNAL( selectionChanged( 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<AccountViewItem *>(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<AccountViewItem *>(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<Account> list ) { clear(); QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); (void) new MBOXviewItem(localfolders,this); Account *it; for ( it = list.first(); it; it = list.next() ) { if ( it->getType().compare( "IMAP" ) == 0 ) { IMAPaccount *imap = static_cast<IMAPaccount *>(it); qDebug( "added IMAP " + imap->getAccountName() ); (void) new IMAPviewItem( imap, this ); } else if ( it->getType().compare( "POP3" ) == 0 ) { POP3account *pop3 = static_cast<POP3account *>(it); qDebug( "added POP3 " + pop3->getAccountName() ); (void) new POP3viewItem( pop3, this ); } } } void AccountView::refresh(QListViewItem *item) { qDebug("AccountView refresh..."); if ( item ) { m_currentItem = item; QList<RecMail> headerlist; headerlist.setAutoDelete(true); AccountViewItem *view = static_cast<AccountViewItem *>(item); view->refresh(headerlist); emit refreshMailview(&headerlist); } } void AccountView::refreshCurrent() { m_currentItem = currentItem(); if ( !m_currentItem ) return; QList<RecMail> headerlist; headerlist.setAutoDelete(true); AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); view->refresh(headerlist); emit refreshMailview(&headerlist); } void AccountView::refreshAll() { } RecBody AccountView::fetchBody(const RecMail&aMail) { QListViewItem*item = selectedItem (); if (!item) return RecBody(); AccountViewItem *view = static_cast<AccountViewItem *>(item); return view->fetchBody(aMail); } /** * MBOX Account stuff */ MBOXviewItem::MBOXviewItem( const QString&aPath, QListView *parent ) : AccountViewItem( parent ) { m_Path = aPath; wrapper = AbstractMail::getWrapper( m_Path ); setPixmap( 0, PIXMAP_LOCALFOLDER ); setText( 0, " Local Folders" ); setOpen( true ); } MBOXviewItem::~MBOXviewItem() { delete wrapper; } AbstractMail *MBOXviewItem::getWrapper() { return wrapper; } void MBOXviewItem::refresh( QList<RecMail> & ) { + refresh(false); +} + +void MBOXviewItem::refresh(bool force) +{ + if (childCount()>0 && force==false) return; QList<Folder> *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } Folder *it; QListViewItem*item = 0; for ( it = folders->first(); it; it = folders->next() ) { item = new MBOXfolderItem( it, this , item ); item->setSelectable(it->may_select()); } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! folders->setAutoDelete(false); delete folders; } RecBody MBOXviewItem::fetchBody( const RecMail &mail ) { - qDebug( "POP3 fetchBody" ); + qDebug( "MBOX fetchBody" ); return wrapper->fetchBody( mail ); } +QPopupMenu * MBOXviewItem::getContextMenu() +{ + QPopupMenu *m = new QPopupMenu(0); + if (m) { + m->insertItem(QObject::tr("Refresh folder list",contextName),0); + m->insertItem(QObject::tr("Create new folder",contextName),1); + } + return m; +} + +void MBOXviewItem::createFolder() +{ + Newmdirdlg ndirdlg(0,0,true); + ndirdlg.showMaximized(); + if (ndirdlg.exec()) { + QString ndir = ndirdlg.Newdir(); + if (wrapper->createMbox(ndir)) { + refresh(true); + } + } +} + +void MBOXviewItem::contextMenuSelected(int which) +{ + switch (which) { + case 0: + refresh(true); + break; + case 1: + createFolder(); + break; + default: + break; + } +} + MBOXfolderItem::~MBOXfolderItem() { delete folder; } MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) : AccountViewItem( parent,after ) { folder = folderInit; mbox = parent; if (folder->getDisplayName().lower() == "outgoing") { setPixmap( 0, PIXMAP_OUTBOXFOLDER ); } else if (folder->getDisplayName().lower() == "inbox") { setPixmap( 0, PIXMAP_INBOXFOLDER); } else { setPixmap( 0, PIXMAP_MBOXFOLDER ); } setText( 0, folder->getDisplayName() ); } void MBOXfolderItem::refresh(QList<RecMail>&target) { if (folder->may_select()) mbox->getWrapper()->listMessages( folder->getName(),target ); } RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) { return mbox->getWrapper()->fetchBody(aMail); } + +void MBOXfolderItem::deleteAllMails() +{ + int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), + QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).arg(folder->getDisplayName()), + QObject::tr("Yes",contextName), + QObject::tr("No",contextName),QString::null,1,1); + qDebug("Auswahl: %i",yesno); + if (yesno == 0) { + if (mbox->getWrapper()->deleteAllMail(folder)) { + AccountView * view = (AccountView*)listView(); + if (view) view->refreshCurrent(); + } + } +} + +void MBOXfolderItem::deleteFolder() +{ + int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), + QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), + QObject::tr("Yes",contextName), + QObject::tr("No",contextName),QString::null,1,1); + qDebug("Auswahl: %i",yesno); + if (yesno == 0) { + if (mbox->getWrapper()->deleteMbox(folder)) { + QListView*v=listView(); + MBOXviewItem * box = mbox; + /* be carefull - after that this object is destroyd so don't use + * any member of it after that call!!*/ + mbox->refresh(true); + if (v) { + v->setSelected(box,true); + } + } + } +} + +QPopupMenu * MBOXfolderItem::getContextMenu() +{ + QPopupMenu *m = new QPopupMenu(0); + if (m) { + m->insertItem(QObject::tr("Delete all mails",contextName),0); + m->insertItem(QObject::tr("Delete folder",contextName),1); + } + return m; +} + +void MBOXfolderItem::contextMenuSelected(int which) +{ + switch(which) { + case 0: + deleteAllMails(); + break; + case 1: + deleteFolder(); + break; + default: + break; + } +} diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index e7fe038..98abf44 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h @@ -1,157 +1,173 @@ #ifndef ACCOUNTVIEW_H #define ACCOUNTVIEW_H #include <qlistview.h> #include <qlist.h> #include "settings.h" #include "mailwrapper.h" #include "abstractmail.h" class POP3wrapper; class RecMail; class RecBody; class QPopupMenu; class AccountViewItem : public QListViewItem { public: AccountViewItem( QListView *parent ) : QListViewItem( parent ) {} AccountViewItem( QListViewItem *parent) : QListViewItem( parent) {} AccountViewItem( QListViewItem *parent , QListViewItem*after ) : QListViewItem( parent,after ) {} virtual void refresh(QList<RecMail>&)=0; virtual RecBody fetchBody(const RecMail&)=0; virtual QPopupMenu * getContextMenu(){return 0;}; virtual void contextMenuSelected(int){} +protected: + static const QString contextName; }; class POP3viewItem : public AccountViewItem { public: POP3viewItem( POP3account *a, QListView *parent ); ~POP3viewItem(); virtual void refresh( QList<RecMail> &target ); virtual RecBody fetchBody( const RecMail &mail ); AbstractMail *getWrapper(); private: POP3account *account; AbstractMail *wrapper; }; class POP3folderItem : public AccountViewItem { public: POP3folderItem( Folder *folder, POP3viewItem *parent , QListViewItem*after ); ~POP3folderItem(); virtual void refresh(QList<RecMail>&); virtual RecBody fetchBody(const RecMail&); private: Folder *folder; POP3viewItem *pop3; }; class IMAPfolderItem; class IMAPviewItem : public AccountViewItem { friend class IMAPfolderItem; public: IMAPviewItem( IMAPaccount *a, QListView *parent ); ~IMAPviewItem(); virtual void refresh(QList<RecMail>&); 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; AbstractMail *wrapper; }; class IMAPfolderItem : public AccountViewItem { public: IMAPfolderItem( Folder *folder, IMAPviewItem *parent , QListViewItem*after ); IMAPfolderItem( Folder *folder, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ); ~IMAPfolderItem(); virtual void refresh(QList<RecMail>&); 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(); + virtual void deleteAllMails(); private: Folder *folder; IMAPviewItem *imap; }; class MBOXviewItem : public AccountViewItem { + friend class MBOXfolderItem; public: // MBOXviewItem( MBOXaccount *a, QListView *parent ); MBOXviewItem( const QString&aMboxPath, QListView *parent ); ~MBOXviewItem(); virtual void refresh( QList<RecMail> &target ); virtual RecBody fetchBody( const RecMail &mail ); AbstractMail *getWrapper(); + virtual QPopupMenu * getContextMenu(); + virtual void contextMenuSelected(int); + +protected: + virtual void refresh(bool force=false); + virtual void createFolder(); + private: // MBOXaccount *account; QString m_Path; AbstractMail *wrapper; }; class MBOXfolderItem : public AccountViewItem { public: MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); ~MBOXfolderItem(); virtual void refresh(QList<RecMail>&); virtual RecBody fetchBody(const RecMail&); + virtual QPopupMenu * getContextMenu(); + virtual void contextMenuSelected(int); + +protected: + virtual void deleteAllMails(); + virtual void deleteFolder(); private: Folder *folder; MBOXviewItem *mbox; }; class AccountView : public QListView { Q_OBJECT public: AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); void populate( QList<Account> list ); RecBody fetchBody(const RecMail&aMail); public slots: 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<RecMail>*); private: QListViewItem* m_currentItem; }; #endif diff --git a/noncore/net/mail/genericwrapper.h b/noncore/net/mail/genericwrapper.h index 12f6928..90c4b50 100644 --- a/noncore/net/mail/genericwrapper.h +++ b/noncore/net/mail/genericwrapper.h @@ -1,59 +1,57 @@ #ifndef __GENERIC_WRAPPER_H #define __GENERIC_WRAPPER_H #include "abstractmail.h" #include <qmap.h> #include <qstring.h> #include <libetpan/clist.h> class RecMail; class RecBody; class encodedString; struct mailpop3; struct mailmessage; struct mailmime; struct mailmime_mechanism; struct mailimf_mailbox_list; struct mailimf_mailbox; struct mailimf_date_time; struct mailimf_group; struct mailimf_address_list; /* this class hold just the funs shared between * mbox and pop3 (later mh, too) mail access. * it is not desigend to make a instance of it! */ class Genericwrapper : public AbstractMail { Q_OBJECT public: Genericwrapper(); virtual ~Genericwrapper(); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual void cleanMimeCache(); protected: RecMail *parseHeader( const char *header ); RecBody parseMail( mailmessage * msg ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); QString parseDateTime( mailimf_date_time *date ); void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); 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; }; #endif 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 @@ -1,59 +1,57 @@ #ifndef __GENERIC_WRAPPER_H #define __GENERIC_WRAPPER_H #include "abstractmail.h" #include <qmap.h> #include <qstring.h> #include <libetpan/clist.h> class RecMail; class RecBody; class encodedString; struct mailpop3; struct mailmessage; struct mailmime; struct mailmime_mechanism; struct mailimf_mailbox_list; struct mailimf_mailbox; struct mailimf_date_time; struct mailimf_group; struct mailimf_address_list; /* this class hold just the funs shared between * mbox and pop3 (later mh, too) mail access. * it is not desigend to make a instance of it! */ class Genericwrapper : public AbstractMail { Q_OBJECT public: Genericwrapper(); virtual ~Genericwrapper(); virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part); virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part); virtual QString fetchTextPart(const RecMail&mail,const RecPart&part); virtual void cleanMimeCache(); protected: RecMail *parseHeader( const char *header ); RecBody parseMail( mailmessage * msg ); QString parseMailboxList( mailimf_mailbox_list *list ); QString parseMailbox( mailimf_mailbox *box ); QString parseGroup( mailimf_group *group ); QString parseAddressList( mailimf_address_list *list ); QString parseDateTime( mailimf_date_time *date ); void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,unsigned int current_rek=0); 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; }; #endif 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,293 +1,367 @@ #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) { QDir dir(MBOXPath); if (!dir.exists()) { dir.mkdir(MBOXPath); } } MBOXwrapper::~MBOXwrapper() { } 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) { qDebug("Error filling message list"); if (env_list) { 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) { qDebug("could not fetch envelope of message %i", i); continue; } RecMail * mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); if (r == MAIL_ERROR_NOT_IMPLEMENTED) { mFlags.setBit(FLAG_SEEN); } mailimf_single_fields single_fields; mailimf_single_fields_init(&single_fields, msg->msg_fields); mail->setMsgsize(msg->msg_size); mail->setFlags(mFlags); mail->setMbox(mailbox); mail->setNumber(i+1); if (single_fields.fld_subject) mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); if (single_fields.fld_from) mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); if (single_fields.fld_to) mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); if (single_fields.fld_cc) mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); if (single_fields.fld_bcc) mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); if (single_fields.fld_orig_date) mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); if (single_fields.fld_message_id->mid_value) mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } 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() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); QDir dir(MBOXPath); if (!dir.exists()) return folders; dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); QStringList entries = dir.entryList(); QStringList::ConstIterator it = entries.begin(); for (;it!=entries.end();++it) { Folder*inb=new Folder(*it,"/"); folders->append(inb); } return folders; } 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); mailstorage_free(storage); return; } r = mailsession_remove_message(folder->fld_session,mail.getNumber()); if (r != MAIL_NO_ERROR) { qDebug("error deleting mail"); } mailfolder_free(folder); mailstorage_free(storage); } void MBOXwrapper::answeredMail(const RecMail&) { } RecBody MBOXwrapper::fetchBody( const RecMail &mail ) { RecBody body; mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail.getMbox(); 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); mailstorage_free(storage); return body; } r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); if (r != MAIL_NO_ERROR) { qDebug("Error fetching mail %i",mail.getNumber()); mailfolder_free(folder); mailstorage_free(storage); return body; } r = mailmessage_fetch(msg,&data,&size); if (r != MAIL_NO_ERROR) { qDebug("Error fetching mail %i",mail.getNumber()); mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return body; } body = parseMail(msg); mailmessage_fetch_result_free(msg,data); mailfolder_free(folder); mailstorage_free(storage); return body; } 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) { QString p = MBOXPath+"/"; 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); } void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) { RecBody body; mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail.getMbox(); 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; } *target = data; *length = size; mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); } void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) { QString p = MBOXPath+"/"; p+=mailbox; mailmbox_folder*f = 0; int r = mailmbox_init(p.latin1(),0,1,0,&f); 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"); } } 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 @@ -1,35 +1,41 @@ #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 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,198 +1,199 @@ #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 POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { account = a; m_pop3 = NULL; msgTempName = a->getFileName()+"_msg_cache"; last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); QFile msg_cache(msgTempName); if (msg_cache.exists()) { msg_cache.remove(); } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { //qDebug( "POP3: %i of %i", current, maximum ); } RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message; size_t length = 0; login(); if ( !m_pop3 ) { return RecBody(); } RecBody body; mailmessage * msg = 0; QFile msg_cache(msgTempName); if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { qDebug("Message to large: %i",mail.Msgsize()); return body; } cleanMimeCache(); if (mail.getNumber()!=last_msg_id) { if (msg_cache.exists()) { msg_cache.remove(); } msg_cache.open(IO_ReadWrite|IO_Truncate); last_msg_id = mail.getNumber(); err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); last_msg_id = 0; return RecBody(); } msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; message = (char*)malloc(msg.length()+1*sizeof(char)); memset(message,0,msg.length()+1); memcpy(message,msg.latin1(),msg.length()); } /* transform to libetpan stuff */ msg = mailmessage_new(); mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); generic_message_t * msg_data; msg_data = (generic_message_t *)msg->msg_data; msg_data->msg_fetched = 1; msg_data->msg_message = message; msg_data->msg_length = strlen(message); /* parse the mail */ body = parseMail(msg); /* clean up */ mailmessage_free(msg); free(message); /* finish */ return body; } void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char * header = 0; /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ size_t length = 0; 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; err = mailpop3_get_msg_info(m_pop3,i+1,&info); if (info->msg_deleted) continue; err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); free(header); return; } RecMail *mail = parseHeader( header ); mail->setNumber( info->msg_index ); mail->setWrapper(this); 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() { /* we'll hold the line */ if ( m_pop3 != NULL ) return; const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = strdup( login.getUser().latin1() ); pass = strdup( login.getPassword().latin1() ); } else { // cancel qDebug( "POP3: Login canceled" ); return; } } else { user = account->getUser().latin1(); pass = account->getPassword().latin1(); } m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } qDebug( "POP3: connected!" ); // login // TODO: decide if apop or plain login should be used err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); logout(); return; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; 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 @@ -1,32 +1,33 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" #include "genericwrapper.h" #include <qstring.h> 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(); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); - + POP3account *account; + mailpop3 *m_pop3; }; #endif diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 6d69263..162a0c9 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp @@ -1,293 +1,367 @@ #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) { QDir dir(MBOXPath); if (!dir.exists()) { dir.mkdir(MBOXPath); } } MBOXwrapper::~MBOXwrapper() { } 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) { qDebug("Error filling message list"); if (env_list) { 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) { qDebug("could not fetch envelope of message %i", i); continue; } RecMail * mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); if (r == MAIL_ERROR_NOT_IMPLEMENTED) { mFlags.setBit(FLAG_SEEN); } mailimf_single_fields single_fields; mailimf_single_fields_init(&single_fields, msg->msg_fields); mail->setMsgsize(msg->msg_size); mail->setFlags(mFlags); mail->setMbox(mailbox); mail->setNumber(i+1); if (single_fields.fld_subject) mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); if (single_fields.fld_from) mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); if (single_fields.fld_to) mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); if (single_fields.fld_cc) mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); if (single_fields.fld_bcc) mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); if (single_fields.fld_orig_date) mail->setDate( parseDateTime( single_fields.fld_orig_date->dt_date_time ) ); if (single_fields.fld_message_id->mid_value) mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } 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() { QList<Folder> * folders = new QList<Folder>(); folders->setAutoDelete( false ); QDir dir(MBOXPath); if (!dir.exists()) return folders; dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); QStringList entries = dir.entryList(); QStringList::ConstIterator it = entries.begin(); for (;it!=entries.end();++it) { Folder*inb=new Folder(*it,"/"); folders->append(inb); } return folders; } 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); mailstorage_free(storage); return; } r = mailsession_remove_message(folder->fld_session,mail.getNumber()); if (r != MAIL_NO_ERROR) { qDebug("error deleting mail"); } mailfolder_free(folder); mailstorage_free(storage); } void MBOXwrapper::answeredMail(const RecMail&) { } RecBody MBOXwrapper::fetchBody( const RecMail &mail ) { RecBody body; mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail.getMbox(); 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); mailstorage_free(storage); return body; } r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); if (r != MAIL_NO_ERROR) { qDebug("Error fetching mail %i",mail.getNumber()); mailfolder_free(folder); mailstorage_free(storage); return body; } r = mailmessage_fetch(msg,&data,&size); if (r != MAIL_NO_ERROR) { qDebug("Error fetching mail %i",mail.getNumber()); mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); return body; } body = parseMail(msg); mailmessage_fetch_result_free(msg,data); mailfolder_free(folder); mailstorage_free(storage); return body; } 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) { QString p = MBOXPath+"/"; 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); } void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) { RecBody body; mailstorage*storage = mailstorage_new(NULL); QString p = MBOXPath+"/"; p+=mail.getMbox(); 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; } *target = data; *length = size; mailfolder_free(folder); mailstorage_free(storage); mailmessage_free(msg); } void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) { QString p = MBOXPath+"/"; p+=mailbox; mailmbox_folder*f = 0; int r = mailmbox_init(p.latin1(),0,1,0,&f); 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"); } } 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/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index f64ad52..226a544 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h @@ -1,35 +1,41 @@ #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 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/newmaildir.cpp b/noncore/net/mail/newmaildir.cpp index 3fc66f4..ab0d4e3 100644 --- a/noncore/net/mail/newmaildir.cpp +++ b/noncore/net/mail/newmaildir.cpp @@ -1,34 +1,38 @@ #include "newmaildir.h" #include <qdialog.h> #include <qvariant.h> #include <qlineedit.h> #include <qcheckbox.h> -Newmdirdlg::Newmdirdlg( QWidget* parent, const char* name) +Newmdirdlg::Newmdirdlg( QWidget* parent, const char* name,bool no_sub) : Newmdirdlgui(parent,name,true),ndir(""),possible_subs(false) { + if (no_sub) { + subdirsPossibleBox->setChecked(false); + subdirsPossibleBox->hide(); + } } 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 index 1eb904e..496eaf4 100644 --- a/noncore/net/mail/newmaildir.h +++ b/noncore/net/mail/newmaildir.h @@ -1,20 +1,20 @@ #include "newmaildirui.h" #include <qvariant.h> class Newmdirdlg : public Newmdirdlgui { Q_OBJECT public: - Newmdirdlg( QWidget* parent = 0, const char* name = 0); + Newmdirdlg( QWidget* parent = 0, const char* name = 0,bool no_sub=false); ~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/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp index efd83ba..b85fbf6 100644 --- a/noncore/net/mail/pop3wrapper.cpp +++ b/noncore/net/mail/pop3wrapper.cpp @@ -1,198 +1,199 @@ #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 POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { account = a; m_pop3 = NULL; msgTempName = a->getFileName()+"_msg_cache"; last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); QFile msg_cache(msgTempName); if (msg_cache.exists()) { msg_cache.remove(); } } void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { //qDebug( "POP3: %i of %i", current, maximum ); } RecBody POP3wrapper::fetchBody( const RecMail &mail ) { int err = MAILPOP3_NO_ERROR; char *message; size_t length = 0; login(); if ( !m_pop3 ) { return RecBody(); } RecBody body; mailmessage * msg = 0; QFile msg_cache(msgTempName); if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { qDebug("Message to large: %i",mail.Msgsize()); return body; } cleanMimeCache(); if (mail.getNumber()!=last_msg_id) { if (msg_cache.exists()) { msg_cache.remove(); } msg_cache.open(IO_ReadWrite|IO_Truncate); last_msg_id = mail.getNumber(); err = mailpop3_retr( m_pop3, mail.getNumber(), &message, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving body with index %i", mail.getNumber() ); last_msg_id = 0; return RecBody(); } msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; message = (char*)malloc(msg.length()+1*sizeof(char)); memset(message,0,msg.length()+1); memcpy(message,msg.latin1(),msg.length()); } /* transform to libetpan stuff */ msg = mailmessage_new(); mailmessage_init(msg, NULL, data_message_driver, 0, strlen(message)); generic_message_t * msg_data; msg_data = (generic_message_t *)msg->msg_data; msg_data->msg_fetched = 1; msg_data->msg_message = message; msg_data->msg_length = strlen(message); /* parse the mail */ body = parseMail(msg); /* clean up */ mailmessage_free(msg); free(message); /* finish */ return body; } void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { int err = MAILPOP3_NO_ERROR; char * header = 0; /* these vars are used recurcive! set it to 0!!!!!!!!!!!!!!!!! */ size_t length = 0; 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; err = mailpop3_get_msg_info(m_pop3,i+1,&info); if (info->msg_deleted) continue; err = mailpop3_header( m_pop3, info->msg_index, &header, &length ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "POP3: error retrieving header msgid: %i", info->msg_index ); free(header); return; } RecMail *mail = parseHeader( header ); mail->setNumber( info->msg_index ); mail->setWrapper(this); 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() { /* we'll hold the line */ if ( m_pop3 != NULL ) return; const char *server, *user, *pass; uint16_t port; int err = MAILPOP3_NO_ERROR; server = account->getServer().latin1(); port = account->getPort().toUInt(); if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = strdup( login.getUser().latin1() ); pass = strdup( login.getPassword().latin1() ); } else { // cancel qDebug( "POP3: Login canceled" ); return; } } else { user = account->getUser().latin1(); pass = account->getPassword().latin1(); } m_pop3 = mailpop3_new( 200, &pop3_progress ); // connect if (account->getSSL()) { err = mailpop3_ssl_connect( m_pop3, (char*)server, port ); } else { err = mailpop3_socket_connect( m_pop3, (char*)server, port ); } if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error connecting to %s\n reason: %s", server, m_pop3->pop3_response ); mailpop3_free( m_pop3 ); m_pop3 = NULL; return; } qDebug( "POP3: connected!" ); // login // TODO: decide if apop or plain login should be used err = mailpop3_login( m_pop3, (char *) user, (char *) pass ); if ( err != MAILPOP3_NO_ERROR ) { qDebug( "pop3: error logging in: %s", m_pop3->pop3_response ); logout(); return; } qDebug( "POP3: logged in!" ); } void POP3wrapper::logout() { int err = MAILPOP3_NO_ERROR; diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h index b738cca..7502720 100644 --- a/noncore/net/mail/pop3wrapper.h +++ b/noncore/net/mail/pop3wrapper.h @@ -1,32 +1,33 @@ #ifndef __POP3WRAPPER #define __POP3WRAPPER #include "mailwrapper.h" #include "genericwrapper.h" #include <qstring.h> 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(); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); virtual RecBody fetchBody( const RecMail &mail ); static void pop3_progress( size_t current, size_t maximum ); protected: void login(); void logout(); - + POP3account *account; + mailpop3 *m_pop3; }; #endif |