-rw-r--r-- | noncore/net/mail/accountview.cpp | 77 | ||||
-rw-r--r-- | noncore/net/mail/accountview.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 68 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.cpp | 43 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/pop3wrapper.h | 1 |
6 files changed, 157 insertions, 40 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 62cbf62..3048e49 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp @@ -239,13 +239,12 @@ void IMAPviewItem::removeChilds() QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } - } const QStringList&IMAPviewItem::subFolders() { return currentFolders; } @@ -703,53 +702,74 @@ void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) refreshCurrent(); } /** * MH Account stuff */ - +/* MH is a little bit different - the top folder can contains messages other than in IMAP and + POP3 and MBOX */ MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) : AccountViewItem( parent ) { m_Path = aPath; /* be carefull - the space within settext is wanted - thats why the string twice */ wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); setPixmap( 0, PIXMAP_LOCALFOLDER ); setText( 0, " Local Folders" ); setOpen( true ); + folder = 0; } MHviewItem::~MHviewItem() { delete wrapper; + if (folder) delete folder; } AbstractMail *MHviewItem::getWrapper() { return wrapper; } -void MHviewItem::refresh( QList<RecMail> & ) +void MHviewItem::refresh( QList<RecMail> & target) { refresh(false); + getWrapper()->listMessages( "",target ); } -void MHviewItem::refresh(bool force) +void MHviewItem::removeChilds() { - if (childCount()>0 && force==false) return; - QList<Folder> *folders = wrapper->listFolders(); QListViewItem *child = firstChild(); while ( child ) { QListViewItem *tmp = child; child = child->nextSibling(); delete tmp; } +} + +void MHviewItem::refresh(bool force) +{ + if (childCount()>0 && force==false) return; + removeChilds(); + QList<Folder> *folders = wrapper->listFolders(); Folder *it; - QListViewItem*item = 0; + MHfolderItem*item = 0; + MHfolderItem*pmaster = 0; + QString fname = ""; for ( it = folders->first(); it; it = folders->next() ) { - item = new MHfolderItem( it, this , item ); + fname = it->getDisplayName(); + /* this folder itself */ + if (fname=="/") { + folder = it; + continue; + } + if (pmaster) { + item = new MHfolderItem( it, pmaster, item, this ); + } else { + item = new MHfolderItem( it, this , item ); + } item->setSelectable(it->may_select()); } // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! folders->setAutoDelete(false); delete folders; } @@ -763,12 +783,14 @@ RecBody MHviewItem::fetchBody( const RecMail &mail ) QPopupMenu * MHviewItem::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); + m->insertItem(QObject::tr("Delete all mails",contextName),2); + m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); } return m; } void MHviewItem::createFolder() { @@ -779,16 +801,24 @@ void MHviewItem::createFolder() if (wrapper->createMbox(ndir)) { refresh(true); } } } +void MHviewItem::downloadMails() +{ + AccountView*bl = accountView(); + if (!bl) return; + bl->downloadMails(folder,getWrapper()); +} + QStringList MHviewItem::subFolders() { QStringList result; QListViewItem *child = firstChild(); + result.append("/"); while ( child ) { MHfolderItem *tmp = (MHfolderItem*)child; child = child->nextSibling(); result.append(tmp->getFolder()->getDisplayName()); } qDebug("Size of result: %i",result.count()); @@ -801,12 +831,18 @@ void MHviewItem::contextMenuSelected(int which) case 0: refresh(true); break; case 1: createFolder(); break; + case 2: + deleteAllMail(getWrapper(),folder); + break; + case 3: + downloadMails(); + break; default: break; } } MHfolderItem::~MHfolderItem() @@ -816,20 +852,37 @@ MHfolderItem::~MHfolderItem() MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) : AccountViewItem( parent,after ) { folder = folderInit; mbox = parent; - if (folder->getDisplayName().lower() == "outgoing") { + initName(); +} + +MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) + : AccountViewItem( parent,after ) +{ + folder = folderInit; + mbox = master; + initName(); +} + +void MHfolderItem::initName() +{ + QString bName = folder->getDisplayName(); + if (bName.startsWith("/")&&bName.length()>1) { + bName.replace(0,1,""); + } + if (bName.lower() == "outgoing") { setPixmap( 0, PIXMAP_OUTBOXFOLDER ); - } else if (folder->getDisplayName().lower() == "inbox") { + } else if (bName.lower() == "inbox") { setPixmap( 0, PIXMAP_INBOXFOLDER); } else { setPixmap( 0, PIXMAP_MBOXFOLDER ); } - setText( 0, folder->getDisplayName() ); + setText( 0, bName ); } Folder*MHfolderItem::getFolder() { return folder; } @@ -870,12 +923,13 @@ QPopupMenu * MHfolderItem::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); m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); + m->insertItem(QObject::tr("Create new folder",contextName),3); } return m; } void MHfolderItem::downloadMails() { @@ -897,6 +951,7 @@ void MHfolderItem::contextMenuSelected(int which) downloadMails(); break; default: break; } } + diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h index f5a2973..60e2b4b 100644 --- a/noncore/net/mail/accountview.h +++ b/noncore/net/mail/accountview.h @@ -131,33 +131,37 @@ public: virtual QPopupMenu * getContextMenu(); virtual void contextMenuSelected(int); QStringList subFolders(); virtual void refresh(bool force=false); protected: + void downloadMails(); + void removeChilds(); virtual void createFolder(); QString m_Path; AbstractMail *wrapper; - + Folder *folder; }; class MHfolderItem : public AccountViewItem { public: MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after ); + MHfolderItem( Folder *folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master); virtual ~MHfolderItem(); virtual void refresh(QList<RecMail>&); virtual RecBody fetchBody(const RecMail&); virtual QPopupMenu * getContextMenu(); virtual void contextMenuSelected(int); virtual Folder*getFolder(); protected: void downloadMails(); virtual void deleteFolder(); + void initName(); Folder *folder; MHviewItem *mbox; }; class AccountView : public QListView { diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 5adba55..512f778 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp @@ -328,6 +328,74 @@ const QString&MHwrapper::getType()const } const QString&MHwrapper::getName()const { return MHName; } +void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) +{ + init_storage(); + if (!m_storage) { + return; + } + if (targetWrapper != this) { + qDebug("Using generic"); + Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit); + return; + } + qDebug("Using internal routines for move/copy"); + QString tf = buildPath(targetFolder); + int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); + if (r != MAIL_NO_ERROR) { + qDebug("Error selecting source mailbox"); + return; + } + if (moveit) { + r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); + } else { + r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1()); + } + if (r != MAIL_NO_ERROR) { + qDebug("Error copy/moving mail internal (%i)",r); + } +} + +void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit) +{ + init_storage(); + if (!m_storage) { + return; + } + if (targetWrapper != this) { + qDebug("Using generic"); + Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit); + return; + } + if (!fromFolder) return; + int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1()); + if (r!=MAIL_NO_ERROR) { + qDebug("error selecting source folder!"); + return; + } + QString tf = buildPath(targetFolder); + mailmessage_list*l=0; + r = mailsession_get_messages_list(m_storage->sto_session,&l); + if (r != MAIL_NO_ERROR) { + qDebug("Error message list"); + } + unsigned j = 0; + for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) { + mailmessage * msg; + msg = (mailmessage*)carray_get(l->msg_tab, i); + j = msg->msg_index; + if (moveit) { + r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1()); + } else { + r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1()); + } + if (r != MAIL_NO_ERROR) { + qDebug("Error copy/moving mail internal (%i)",r); + break; + } + } + if (l) mailmessage_list_free(l); +} diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h index 7f028b4..79dec30 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.h +++ b/noncore/net/mail/libmailwrapper/mhwrapper.h @@ -19,12 +19,14 @@ public: virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); virtual QList<Folder>* listFolders(); virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); virtual void deleteMail(const RecMail&mail); virtual void answeredMail(const RecMail&mail); + virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); + virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit); 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); diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp index f5eca4a..14c2059 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp @@ -11,13 +11,12 @@ #define HARD_MSG_SIZE_LIMIT 5242880 POP3wrapper::POP3wrapper( POP3account *a ) : Genericwrapper() { account = a; m_pop3 = NULL; - m_folder = NULL; msgTempName = a->getFileName()+"_msg_cache"; last_msg_id = 0; } POP3wrapper::~POP3wrapper() { logout(); @@ -55,13 +54,13 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) { 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 = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); + err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&message,&length); msg_cache.writeBlock(message,length); } else { QString msg=""; msg_cache.open(IO_ReadOnly); message = new char[4096]; @@ -91,23 +90,25 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) { if (message) free(message); return body; } -void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { +void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) +{ login(); if (!m_pop3) return; uint32_t res_messages,res_recent,res_unseen; - mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); - parseList(target,m_folder->fld_session,"INBOX"); + mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen); + parseList(target,m_pop3->sto_session,"INBOX"); Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); } -void POP3wrapper::login() { +void POP3wrapper::login() +{ if (account->getOffline()) return; /* we'll hold the line */ if ( m_pop3 != NULL ) return; @@ -154,38 +155,26 @@ void POP3wrapper::login() { //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, (char*)user,(char*)pass,0,0,0); - - m_folder = mailfolder_new(m_pop3, NULL, NULL); - - if (m_folder==0) { - Global::statusMessage(tr("Error initializing folder")); - mailstorage_free(m_pop3); - m_pop3 = NULL; - return; - } - err = mailfolder_connect(m_folder); + err = mailstorage_connect(m_pop3); if (err != MAIL_NO_ERROR) { qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); Global::statusMessage(tr("Error initializing folder")); - mailfolder_free(m_folder); - m_folder = 0; mailstorage_free(m_pop3); m_pop3 = 0; } } -void POP3wrapper::logout() { +void POP3wrapper::logout() +{ int err = MAILPOP3_NO_ERROR; if ( m_pop3 == NULL ) return; - mailfolder_free(m_folder); - m_folder = 0; mailstorage_free(m_pop3); m_pop3 = 0; } QList<Folder>* POP3wrapper::listFolders() { @@ -197,13 +186,13 @@ QList<Folder>* POP3wrapper::listFolders() { } void POP3wrapper::deleteMail(const RecMail&mail) { login(); if (!m_pop3) return; - int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); + int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber()); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("error deleting mail")); } } void POP3wrapper::answeredMail(const RecMail&) {} @@ -212,19 +201,19 @@ int POP3wrapper::deleteAllMail(const Folder*) { login(); if (!m_pop3) return 0; int res = 1; uint32_t result = 0; - int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); + int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error getting folder info")); return 0; } for (unsigned int i = 0; i < result; ++i) { - err = mailsession_remove_message(m_folder->fld_session,i+1); + err = mailsession_remove_message(m_pop3->sto_session,i+1); if (err != MAIL_NO_ERROR) { Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); res=0; } break; } @@ -235,22 +224,22 @@ void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { login(); target_stat.message_count = 0; target_stat.message_unseen = 0; target_stat.message_recent = 0; if (!m_pop3) return; - int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, + int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count, &target_stat.message_recent,&target_stat.message_unseen); } encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { char*target=0; size_t length=0; encodedString*res = 0; mailmessage * mailmsg = 0; - int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); + int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg); err = mailmessage_fetch(mailmsg,&target,&length); if (mailmsg) mailmessage_free(mailmsg); if (target) { res = new encodedString(target,length); } @@ -258,9 +247,9 @@ encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { } const QString&POP3wrapper::getType()const { return account->getType(); } -const QString&POP3wrapper::getName()const { +const QString&POP3wrapper::getName()const{ return account->getAccountName(); } diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h index d2b708d..a24b9cf 100644 --- a/noncore/net/mail/libmailwrapper/pop3wrapper.h +++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h @@ -34,10 +34,9 @@ public: static void pop3_progress( size_t current, size_t maximum ); protected: void login(); POP3account *account; mailstorage*m_pop3; - mailfolder*m_folder; }; #endif |