summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp77
-rw-r--r--noncore/net/mail/accountview.h6
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp68
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp43
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h1
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
@@ -229,33 +229,32 @@ IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start
229 return pitem; 229 return pitem;
230} 230}
231 231
232void IMAPviewItem::refresh(QList<RecMail>&) 232void IMAPviewItem::refresh(QList<RecMail>&)
233{ 233{
234 refreshFolders(false); 234 refreshFolders(false);
235} 235}
236 236
237void IMAPviewItem::removeChilds() 237void IMAPviewItem::removeChilds()
238{ 238{
239 QListViewItem *child = firstChild(); 239 QListViewItem *child = firstChild();
240 while ( child ) { 240 while ( child ) {
241 QListViewItem *tmp = child; 241 QListViewItem *tmp = child;
242 child = child->nextSibling(); 242 child = child->nextSibling();
243 delete tmp; 243 delete tmp;
244 } 244 }
245
246} 245}
247 246
248const QStringList&IMAPviewItem::subFolders() 247const QStringList&IMAPviewItem::subFolders()
249{ 248{
250 return currentFolders; 249 return currentFolders;
251} 250}
252 251
253void IMAPviewItem::refreshFolders(bool force) 252void IMAPviewItem::refreshFolders(bool force)
254{ 253{
255 if (childCount()>0 && force==false) return; 254 if (childCount()>0 && force==false) return;
256 if (account->getOffline()) return; 255 if (account->getOffline()) return;
257 256
258 removeChilds(); 257 removeChilds();
259 currentFolders.clear(); 258 currentFolders.clear();
260 QList<Folder> *folders = wrapper->listFolders(); 259 QList<Folder> *folders = wrapper->listFolders();
261 260
@@ -693,153 +692,207 @@ void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper)
693 return; 692 return;
694 } 693 }
695 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) { 694 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) {
696 QMessageBox::critical(0,tr("Error creating new Folder"), 695 QMessageBox::critical(0,tr("Error creating new Folder"),
697 tr("<center>Error while creating<br>new folder - breaking.</center>")); 696 tr("<center>Error while creating<br>new folder - breaking.</center>"));
698 return; 697 return;
699 } 698 }
700 qDebug("Targetfolder: %s",targetFolder.latin1()); 699 qDebug("Targetfolder: %s",targetFolder.latin1());
701 qDebug("Fromfolder: %s",fromFolder->getName().latin1()); 700 qDebug("Fromfolder: %s",fromFolder->getName().latin1());
702 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); 701 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails());
703 refreshCurrent(); 702 refreshCurrent();
704} 703}
705 704
706/** 705/**
707 * MH Account stuff 706 * MH Account stuff
708 */ 707 */
709 708/* MH is a little bit different - the top folder can contains messages other than in IMAP and
709 POP3 and MBOX */
710MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) 710MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
711 : AccountViewItem( parent ) 711 : AccountViewItem( parent )
712{ 712{
713 m_Path = aPath; 713 m_Path = aPath;
714 /* be carefull - the space within settext is wanted - thats why the string twice */ 714 /* be carefull - the space within settext is wanted - thats why the string twice */
715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); 715 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
716 setPixmap( 0, PIXMAP_LOCALFOLDER ); 716 setPixmap( 0, PIXMAP_LOCALFOLDER );
717 setText( 0, " Local Folders" ); 717 setText( 0, " Local Folders" );
718 setOpen( true ); 718 setOpen( true );
719 folder = 0;
719} 720}
720 721
721MHviewItem::~MHviewItem() 722MHviewItem::~MHviewItem()
722{ 723{
723 delete wrapper; 724 delete wrapper;
725 if (folder) delete folder;
724} 726}
725 727
726AbstractMail *MHviewItem::getWrapper() 728AbstractMail *MHviewItem::getWrapper()
727{ 729{
728 return wrapper; 730 return wrapper;
729} 731}
730 732
731void MHviewItem::refresh( QList<RecMail> & ) 733void MHviewItem::refresh( QList<RecMail> & target)
732{ 734{
733 refresh(false); 735 refresh(false);
736 getWrapper()->listMessages( "",target );
734} 737}
735 738
736void MHviewItem::refresh(bool force) 739void MHviewItem::removeChilds()
737{ 740{
738 if (childCount()>0 && force==false) return;
739 QList<Folder> *folders = wrapper->listFolders();
740 QListViewItem *child = firstChild(); 741 QListViewItem *child = firstChild();
741 while ( child ) { 742 while ( child ) {
742 QListViewItem *tmp = child; 743 QListViewItem *tmp = child;
743 child = child->nextSibling(); 744 child = child->nextSibling();
744 delete tmp; 745 delete tmp;
745 } 746 }
747}
748
749void MHviewItem::refresh(bool force)
750{
751 if (childCount()>0 && force==false) return;
752 removeChilds();
753 QList<Folder> *folders = wrapper->listFolders();
746 Folder *it; 754 Folder *it;
747 QListViewItem*item = 0; 755 MHfolderItem*item = 0;
756 MHfolderItem*pmaster = 0;
757 QString fname = "";
748 for ( it = folders->first(); it; it = folders->next() ) { 758 for ( it = folders->first(); it; it = folders->next() ) {
749 item = new MHfolderItem( it, this , item ); 759 fname = it->getDisplayName();
760 /* this folder itself */
761 if (fname=="/") {
762 folder = it;
763 continue;
764 }
765 if (pmaster) {
766 item = new MHfolderItem( it, pmaster, item, this );
767 } else {
768 item = new MHfolderItem( it, this , item );
769 }
750 item->setSelectable(it->may_select()); 770 item->setSelectable(it->may_select());
751 } 771 }
752 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 772 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
753 folders->setAutoDelete(false); 773 folders->setAutoDelete(false);
754 delete folders; 774 delete folders;
755} 775}
756 776
757RecBody MHviewItem::fetchBody( const RecMail &mail ) 777RecBody MHviewItem::fetchBody( const RecMail &mail )
758{ 778{
759 qDebug( "MH fetchBody" ); 779 qDebug( "MH fetchBody" );
760 return wrapper->fetchBody( mail ); 780 return wrapper->fetchBody( mail );
761} 781}
762 782
763QPopupMenu * MHviewItem::getContextMenu() 783QPopupMenu * MHviewItem::getContextMenu()
764{ 784{
765 QPopupMenu *m = new QPopupMenu(0); 785 QPopupMenu *m = new QPopupMenu(0);
766 if (m) { 786 if (m) {
767 m->insertItem(QObject::tr("Refresh folder list",contextName),0); 787 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
768 m->insertItem(QObject::tr("Create new folder",contextName),1); 788 m->insertItem(QObject::tr("Create new folder",contextName),1);
789 m->insertItem(QObject::tr("Delete all mails",contextName),2);
790 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3);
769 } 791 }
770 return m; 792 return m;
771} 793}
772 794
773void MHviewItem::createFolder() 795void MHviewItem::createFolder()
774{ 796{
775 Newmdirdlg ndirdlg(0,0,true); 797 Newmdirdlg ndirdlg(0,0,true);
776 ndirdlg.showMaximized(); 798 ndirdlg.showMaximized();
777 if (ndirdlg.exec()) { 799 if (ndirdlg.exec()) {
778 QString ndir = ndirdlg.Newdir(); 800 QString ndir = ndirdlg.Newdir();
779 if (wrapper->createMbox(ndir)) { 801 if (wrapper->createMbox(ndir)) {
780 refresh(true); 802 refresh(true);
781 } 803 }
782 } 804 }
783} 805}
784 806
807void MHviewItem::downloadMails()
808{
809 AccountView*bl = accountView();
810 if (!bl) return;
811 bl->downloadMails(folder,getWrapper());
812}
813
785QStringList MHviewItem::subFolders() 814QStringList MHviewItem::subFolders()
786{ 815{
787 QStringList result; 816 QStringList result;
788 QListViewItem *child = firstChild(); 817 QListViewItem *child = firstChild();
818 result.append("/");
789 while ( child ) { 819 while ( child ) {
790 MHfolderItem *tmp = (MHfolderItem*)child; 820 MHfolderItem *tmp = (MHfolderItem*)child;
791 child = child->nextSibling(); 821 child = child->nextSibling();
792 result.append(tmp->getFolder()->getDisplayName()); 822 result.append(tmp->getFolder()->getDisplayName());
793 } 823 }
794 qDebug("Size of result: %i",result.count()); 824 qDebug("Size of result: %i",result.count());
795 return result; 825 return result;
796} 826}
797 827
798void MHviewItem::contextMenuSelected(int which) 828void MHviewItem::contextMenuSelected(int which)
799{ 829{
800 switch (which) { 830 switch (which) {
801 case 0: 831 case 0:
802 refresh(true); 832 refresh(true);
803 break; 833 break;
804 case 1: 834 case 1:
805 createFolder(); 835 createFolder();
806 break; 836 break;
837 case 2:
838 deleteAllMail(getWrapper(),folder);
839 break;
840 case 3:
841 downloadMails();
842 break;
807 default: 843 default:
808 break; 844 break;
809 } 845 }
810} 846}
811 847
812MHfolderItem::~MHfolderItem() 848MHfolderItem::~MHfolderItem()
813{ 849{
814 delete folder; 850 delete folder;
815} 851}
816 852
817MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) 853MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after )
818 : AccountViewItem( parent,after ) 854 : AccountViewItem( parent,after )
819{ 855{
820 folder = folderInit; 856 folder = folderInit;
821 mbox = parent; 857 mbox = parent;
822 if (folder->getDisplayName().lower() == "outgoing") { 858 initName();
859}
860
861MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master)
862 : AccountViewItem( parent,after )
863{
864 folder = folderInit;
865 mbox = master;
866 initName();
867}
868
869void MHfolderItem::initName()
870{
871 QString bName = folder->getDisplayName();
872 if (bName.startsWith("/")&&bName.length()>1) {
873 bName.replace(0,1,"");
874 }
875 if (bName.lower() == "outgoing") {
823 setPixmap( 0, PIXMAP_OUTBOXFOLDER ); 876 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
824 } else if (folder->getDisplayName().lower() == "inbox") { 877 } else if (bName.lower() == "inbox") {
825 setPixmap( 0, PIXMAP_INBOXFOLDER); 878 setPixmap( 0, PIXMAP_INBOXFOLDER);
826 } else { 879 } else {
827 setPixmap( 0, PIXMAP_MBOXFOLDER ); 880 setPixmap( 0, PIXMAP_MBOXFOLDER );
828 } 881 }
829 setText( 0, folder->getDisplayName() ); 882 setText( 0, bName );
830} 883}
831 884
832Folder*MHfolderItem::getFolder() 885Folder*MHfolderItem::getFolder()
833{ 886{
834 return folder; 887 return folder;
835} 888}
836 889
837void MHfolderItem::refresh(QList<RecMail>&target) 890void MHfolderItem::refresh(QList<RecMail>&target)
838{ 891{
839 if (folder->may_select()) 892 if (folder->may_select())
840 mbox->getWrapper()->listMessages( folder->getName(),target ); 893 mbox->getWrapper()->listMessages( folder->getName(),target );
841} 894}
842 895
843RecBody MHfolderItem::fetchBody(const RecMail&aMail) 896RecBody MHfolderItem::fetchBody(const RecMail&aMail)
844{ 897{
845 return mbox->getWrapper()->fetchBody(aMail); 898 return mbox->getWrapper()->fetchBody(aMail);
@@ -860,43 +913,45 @@ void MHfolderItem::deleteFolder()
860 * any member of it after that call!!*/ 913 * any member of it after that call!!*/
861 mbox->refresh(true); 914 mbox->refresh(true);
862 if (v) { 915 if (v) {
863 v->setSelected(box,true); 916 v->setSelected(box,true);
864 } 917 }
865 } 918 }
866 } 919 }
867} 920}
868 921
869QPopupMenu * MHfolderItem::getContextMenu() 922QPopupMenu * MHfolderItem::getContextMenu()
870{ 923{
871 QPopupMenu *m = new QPopupMenu(0); 924 QPopupMenu *m = new QPopupMenu(0);
872 if (m) { 925 if (m) {
873 m->insertItem(QObject::tr("Delete all mails",contextName),0); 926 m->insertItem(QObject::tr("Delete all mails",contextName),0);
874 m->insertItem(QObject::tr("Delete folder",contextName),1); 927 m->insertItem(QObject::tr("Delete folder",contextName),1);
875 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); 928 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
929 m->insertItem(QObject::tr("Create new folder",contextName),3);
876 } 930 }
877 return m; 931 return m;
878} 932}
879 933
880void MHfolderItem::downloadMails() 934void MHfolderItem::downloadMails()
881{ 935{
882 AccountView*bl = mbox->accountView(); 936 AccountView*bl = mbox->accountView();
883 if (!bl) return; 937 if (!bl) return;
884 bl->downloadMails(folder,mbox->getWrapper()); 938 bl->downloadMails(folder,mbox->getWrapper());
885} 939}
886 940
887void MHfolderItem::contextMenuSelected(int which) 941void MHfolderItem::contextMenuSelected(int which)
888{ 942{
889 switch(which) { 943 switch(which) {
890 case 0: 944 case 0:
891 deleteAllMail(mbox->getWrapper(),folder); 945 deleteAllMail(mbox->getWrapper(),folder);
892 break; 946 break;
893 case 1: 947 case 1:
894 deleteFolder(); 948 deleteFolder();
895 break; 949 break;
896 case 2: 950 case 2:
897 downloadMails(); 951 downloadMails();
898 break; 952 break;
899 default: 953 default:
900 break; 954 break;
901 } 955 }
902} 956}
957
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
@@ -121,53 +121,57 @@ protected:
121class MHviewItem : public AccountViewItem 121class MHviewItem : public AccountViewItem
122{ 122{
123 friend class MHfolderItem; 123 friend class MHfolderItem;
124 124
125public: 125public:
126 MHviewItem( const QString&aMboxPath, AccountView *parent ); 126 MHviewItem( const QString&aMboxPath, AccountView *parent );
127 virtual ~MHviewItem(); 127 virtual ~MHviewItem();
128 virtual void refresh( QList<RecMail> &target ); 128 virtual void refresh( QList<RecMail> &target );
129 virtual RecBody fetchBody( const RecMail &mail ); 129 virtual RecBody fetchBody( const RecMail &mail );
130 AbstractMail *getWrapper(); 130 AbstractMail *getWrapper();
131 virtual QPopupMenu * getContextMenu(); 131 virtual QPopupMenu * getContextMenu();
132 virtual void contextMenuSelected(int); 132 virtual void contextMenuSelected(int);
133 QStringList subFolders(); 133 QStringList subFolders();
134 virtual void refresh(bool force=false); 134 virtual void refresh(bool force=false);
135 135
136protected: 136protected:
137 void downloadMails();
138 void removeChilds();
137 virtual void createFolder(); 139 virtual void createFolder();
138 QString m_Path; 140 QString m_Path;
139 AbstractMail *wrapper; 141 AbstractMail *wrapper;
140 142 Folder *folder;
141}; 143};
142 144
143class MHfolderItem : public AccountViewItem 145class MHfolderItem : public AccountViewItem
144{ 146{
145 147
146public: 148public:
147 MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after ); 149 MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after );
150 MHfolderItem( Folder *folder, MHfolderItem *parent, QListViewItem*after, MHviewItem*master);
148 virtual ~MHfolderItem(); 151 virtual ~MHfolderItem();
149 virtual void refresh(QList<RecMail>&); 152 virtual void refresh(QList<RecMail>&);
150 virtual RecBody fetchBody(const RecMail&); 153 virtual RecBody fetchBody(const RecMail&);
151 virtual QPopupMenu * getContextMenu(); 154 virtual QPopupMenu * getContextMenu();
152 virtual void contextMenuSelected(int); 155 virtual void contextMenuSelected(int);
153 virtual Folder*getFolder(); 156 virtual Folder*getFolder();
154 157
155protected: 158protected:
156 void downloadMails(); 159 void downloadMails();
157 virtual void deleteFolder(); 160 virtual void deleteFolder();
161 void initName();
158 Folder *folder; 162 Folder *folder;
159 MHviewItem *mbox; 163 MHviewItem *mbox;
160}; 164};
161 165
162class AccountView : public QListView 166class AccountView : public QListView
163{ 167{
164 Q_OBJECT 168 Q_OBJECT
165 169
166public: 170public:
167 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 ); 171 AccountView( QWidget *parent = 0, const char *name = 0, WFlags flags = 0 );
168 virtual ~AccountView(); 172 virtual ~AccountView();
169 virtual void populate( QList<Account> list ); 173 virtual void populate( QList<Account> list );
170 virtual RecBody fetchBody(const RecMail&aMail); 174 virtual RecBody fetchBody(const RecMail&aMail);
171 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper); 175 virtual void downloadMails(Folder*fromFolder,AbstractMail*fromWrapper);
172 176
173public slots: 177public slots:
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
@@ -318,16 +318,84 @@ void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
318 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, 318 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
319 &target_stat.message_recent,&target_stat.message_unseen); 319 &target_stat.message_recent,&target_stat.message_unseen);
320 if (r != MAIL_NO_ERROR) { 320 if (r != MAIL_NO_ERROR) {
321 Global::statusMessage(tr("Error retrieving status")); 321 Global::statusMessage(tr("Error retrieving status"));
322 } 322 }
323} 323}
324 324
325const QString&MHwrapper::getType()const 325const QString&MHwrapper::getType()const
326{ 326{
327 return wrapperType; 327 return wrapperType;
328} 328}
329 329
330const QString&MHwrapper::getName()const 330const QString&MHwrapper::getName()const
331{ 331{
332 return MHName; 332 return MHName;
333} 333}
334void MHwrapper::mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
335{
336 init_storage();
337 if (!m_storage) {
338 return;
339 }
340 if (targetWrapper != this) {
341 qDebug("Using generic");
342 Genericwrapper::mvcpMail(mail,targetFolder,targetWrapper,moveit);
343 return;
344 }
345 qDebug("Using internal routines for move/copy");
346 QString tf = buildPath(targetFolder);
347 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
348 if (r != MAIL_NO_ERROR) {
349 qDebug("Error selecting source mailbox");
350 return;
351 }
352 if (moveit) {
353 r = mailsession_move_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1());
354 } else {
355 r = mailsession_copy_message(m_storage->sto_session,mail.getNumber(),(char*)tf.latin1());
356 }
357 if (r != MAIL_NO_ERROR) {
358 qDebug("Error copy/moving mail internal (%i)",r);
359 }
360}
361
362void MHwrapper::mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit)
363{
364 init_storage();
365 if (!m_storage) {
366 return;
367 }
368 if (targetWrapper != this) {
369 qDebug("Using generic");
370 Genericwrapper::mvcpAllMails(fromFolder,targetFolder,targetWrapper,moveit);
371 return;
372 }
373 if (!fromFolder) return;
374 int r = mailsession_select_folder(m_storage->sto_session,(char*)fromFolder->getName().latin1());
375 if (r!=MAIL_NO_ERROR) {
376 qDebug("error selecting source folder!");
377 return;
378 }
379 QString tf = buildPath(targetFolder);
380 mailmessage_list*l=0;
381 r = mailsession_get_messages_list(m_storage->sto_session,&l);
382 if (r != MAIL_NO_ERROR) {
383 qDebug("Error message list");
384 }
385 unsigned j = 0;
386 for(unsigned int i = 0 ; l!= 0 && i < carray_count(l->msg_tab) ; ++i) {
387 mailmessage * msg;
388 msg = (mailmessage*)carray_get(l->msg_tab, i);
389 j = msg->msg_index;
390 if (moveit) {
391 r = mailsession_move_message(m_storage->sto_session,j,(char*)tf.latin1());
392 } else {
393 r = mailsession_copy_message(m_storage->sto_session,j,(char*)tf.latin1());
394 }
395 if (r != MAIL_NO_ERROR) {
396 qDebug("Error copy/moving mail internal (%i)",r);
397 break;
398 }
399 }
400 if (l) mailmessage_list_free(l);
401}
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
@@ -9,32 +9,34 @@ class RecBody;
9class encodedString; 9class encodedString;
10struct mailmbox_folder; 10struct mailmbox_folder;
11 11
12class MHwrapper : public Genericwrapper 12class MHwrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15public: 15public:
16 MHwrapper(const QString & dir,const QString&name); 16 MHwrapper(const QString & dir,const QString&name);
17 virtual ~MHwrapper(); 17 virtual ~MHwrapper();
18 18
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target ); 19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders(); 20 virtual QList<Folder>* listFolders();
21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX"); 21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22 22
23 virtual void deleteMail(const RecMail&mail); 23 virtual void deleteMail(const RecMail&mail);
24 virtual void answeredMail(const RecMail&mail); 24 virtual void answeredMail(const RecMail&mail);
25 virtual void mvcpMail(const RecMail&mail,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
26 virtual void mvcpAllMails(Folder*fromFolder,const QString&targetFolder,AbstractMail*targetWrapper,bool moveit);
25 27
26 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false); 28 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
27 virtual int deleteMbox(const Folder*); 29 virtual int deleteMbox(const Folder*);
28 30
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder); 31 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30 32
31 virtual RecBody fetchBody( const RecMail &mail ); 33 virtual RecBody fetchBody( const RecMail &mail );
32 static void mbox_progress( size_t current, size_t maximum ); 34 static void mbox_progress( size_t current, size_t maximum );
33 35
34 virtual encodedString* fetchRawBody(const RecMail&mail); 36 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target); 37 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target);
36 virtual int deleteAllMail(const Folder*); 38 virtual int deleteAllMail(const Folder*);
37 virtual const QString&getType()const; 39 virtual const QString&getType()const;
38 virtual const QString&getName()const; 40 virtual const QString&getName()const;
39 41
40protected: 42protected:
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
@@ -1,33 +1,32 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include "pop3wrapper.h" 2#include "pop3wrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "logindialog.h" 4#include "logindialog.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qpe/global.h> 6#include <qpe/global.h>
7#include <qfile.h> 7#include <qfile.h>
8#include <qstring.h> 8#include <qstring.h>
9 9
10/* we don't fetch messages larger than 5 MB */ 10/* we don't fetch messages larger than 5 MB */
11#define HARD_MSG_SIZE_LIMIT 5242880 11#define HARD_MSG_SIZE_LIMIT 5242880
12 12
13POP3wrapper::POP3wrapper( POP3account *a ) 13POP3wrapper::POP3wrapper( POP3account *a )
14: Genericwrapper() { 14: Genericwrapper() {
15 account = a; 15 account = a;
16 m_pop3 = NULL; 16 m_pop3 = NULL;
17 m_folder = NULL;
18 msgTempName = a->getFileName()+"_msg_cache"; 17 msgTempName = a->getFileName()+"_msg_cache";
19 last_msg_id = 0; 18 last_msg_id = 0;
20} 19}
21 20
22POP3wrapper::~POP3wrapper() { 21POP3wrapper::~POP3wrapper() {
23 logout(); 22 logout();
24 QFile msg_cache(msgTempName); 23 QFile msg_cache(msgTempName);
25 if (msg_cache.exists()) { 24 if (msg_cache.exists()) {
26 msg_cache.remove(); 25 msg_cache.remove();
27 } 26 }
28} 27}
29 28
30void POP3wrapper::pop3_progress( size_t current, size_t maximum ) { 29void POP3wrapper::pop3_progress( size_t current, size_t maximum ) {
31 qDebug( "POP3: %i of %i", current, maximum ); 30 qDebug( "POP3: %i of %i", current, maximum );
32} 31}
33 32
@@ -45,33 +44,33 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) {
45 mailmessage * mailmsg; 44 mailmessage * mailmsg;
46 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) { 45 if (mail.Msgsize()>HARD_MSG_SIZE_LIMIT) {
47 qDebug("Message to large: %i",mail.Msgsize()); 46 qDebug("Message to large: %i",mail.Msgsize());
48 return body; 47 return body;
49 } 48 }
50 49
51 QFile msg_cache(msgTempName); 50 QFile msg_cache(msgTempName);
52 51
53 cleanMimeCache(); 52 cleanMimeCache();
54 53
55 if (mail.getNumber()!=last_msg_id) { 54 if (mail.getNumber()!=last_msg_id) {
56 if (msg_cache.exists()) { 55 if (msg_cache.exists()) {
57 msg_cache.remove(); 56 msg_cache.remove();
58 } 57 }
59 msg_cache.open(IO_ReadWrite|IO_Truncate); 58 msg_cache.open(IO_ReadWrite|IO_Truncate);
60 last_msg_id = mail.getNumber(); 59 last_msg_id = mail.getNumber();
61 err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 60 err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg);
62 err = mailmessage_fetch(mailmsg,&message,&length); 61 err = mailmessage_fetch(mailmsg,&message,&length);
63 msg_cache.writeBlock(message,length); 62 msg_cache.writeBlock(message,length);
64 } else { 63 } else {
65 QString msg=""; 64 QString msg="";
66 msg_cache.open(IO_ReadOnly); 65 msg_cache.open(IO_ReadOnly);
67 message = new char[4096]; 66 message = new char[4096];
68 memset(message,0,4096); 67 memset(message,0,4096);
69 while (msg_cache.readBlock(message,4095)>0) { 68 while (msg_cache.readBlock(message,4095)>0) {
70 msg+=message; 69 msg+=message;
71 memset(message,0,4096); 70 memset(message,0,4096);
72 } 71 }
73 delete message; 72 delete message;
74 message = (char*)malloc(msg.length()+1*sizeof(char)); 73 message = (char*)malloc(msg.length()+1*sizeof(char));
75 memset(message,0,msg.length()+1); 74 memset(message,0,msg.length()+1);
76 memcpy(message,msg.latin1(),msg.length()); 75 memcpy(message,msg.latin1(),msg.length());
77 /* transform to libetpan stuff */ 76 /* transform to libetpan stuff */
@@ -81,43 +80,45 @@ RecBody POP3wrapper::fetchBody( const RecMail &mail ) {
81 msg_data = (generic_message_t *)mailmsg->msg_data; 80 msg_data = (generic_message_t *)mailmsg->msg_data;
82 msg_data->msg_fetched = 1; 81 msg_data->msg_fetched = 1;
83 msg_data->msg_message = message; 82 msg_data->msg_message = message;
84 msg_data->msg_length = strlen(message); 83 msg_data->msg_length = strlen(message);
85 } 84 }
86 body = parseMail(mailmsg); 85 body = parseMail(mailmsg);
87 86
88 /* clean up */ 87 /* clean up */
89 if (mailmsg) 88 if (mailmsg)
90 mailmessage_free(mailmsg); 89 mailmessage_free(mailmsg);
91 if (message) 90 if (message)
92 free(message); 91 free(message);
93 92
94 return body; 93 return body;
95} 94}
96 95
97void POP3wrapper::listMessages(const QString &, QList<RecMail> &target ) { 96void POP3wrapper::listMessages(const QString &, QList<RecMail> &target )
97{
98 login(); 98 login();
99 if (!m_pop3) 99 if (!m_pop3)
100 return; 100 return;
101 uint32_t res_messages,res_recent,res_unseen; 101 uint32_t res_messages,res_recent,res_unseen;
102 mailsession_status_folder(m_folder->fld_session,"INBOX",&res_messages,&res_recent,&res_unseen); 102 mailsession_status_folder(m_pop3->sto_session,"INBOX",&res_messages,&res_recent,&res_unseen);
103 parseList(target,m_folder->fld_session,"INBOX"); 103 parseList(target,m_pop3->sto_session,"INBOX");
104 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages)); 104 Global::statusMessage( tr("Mailbox contains %1 mail(s)").arg(res_messages));
105} 105}
106 106
107void POP3wrapper::login() { 107void POP3wrapper::login()
108{
108 if (account->getOffline()) 109 if (account->getOffline())
109 return; 110 return;
110 /* we'll hold the line */ 111 /* we'll hold the line */
111 if ( m_pop3 != NULL ) 112 if ( m_pop3 != NULL )
112 return; 113 return;
113 114
114 const char *server, *user, *pass; 115 const char *server, *user, *pass;
115 uint16_t port; 116 uint16_t port;
116 int err = MAILPOP3_NO_ERROR; 117 int err = MAILPOP3_NO_ERROR;
117 118
118 server = account->getServer().latin1(); 119 server = account->getServer().latin1();
119 port = account->getPort().toUInt(); 120 port = account->getPort().toUInt();
120 121
121 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) { 122 if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
122 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true ); 123 LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
123 login.show(); 124 login.show();
@@ -144,123 +145,111 @@ void POP3wrapper::login() {
144 if ( conntypeset == 3 ) { 145 if ( conntypeset == 3 ) {
145 conntype = CONNECTION_TYPE_COMMAND; 146 conntype = CONNECTION_TYPE_COMMAND;
146 } else if ( conntypeset == 2 ) { 147 } else if ( conntypeset == 2 ) {
147 conntype = CONNECTION_TYPE_TLS; 148 conntype = CONNECTION_TYPE_TLS;
148 } else if ( conntypeset == 1 ) { 149 } else if ( conntypeset == 1 ) {
149 conntype = CONNECTION_TYPE_STARTTLS; 150 conntype = CONNECTION_TYPE_STARTTLS;
150 } else if ( conntypeset == 0 ) { 151 } else if ( conntypeset == 0 ) {
151 conntype = CONNECTION_TYPE_TRY_STARTTLS; 152 conntype = CONNECTION_TYPE_TRY_STARTTLS;
152 } 153 }
153 154
154 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN); 155 //(ssl?CONNECTION_TYPE_TLS:CONNECTION_TYPE_PLAIN);
155 156
156 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN, 157 pop3_mailstorage_init(m_pop3,(char*)server, port, NULL, conntype, POP3_AUTH_TYPE_PLAIN,
157 (char*)user,(char*)pass,0,0,0); 158 (char*)user,(char*)pass,0,0,0);
158 159
159 160
160 161 err = mailstorage_connect(m_pop3);
161 m_folder = mailfolder_new(m_pop3, NULL, NULL);
162
163 if (m_folder==0) {
164 Global::statusMessage(tr("Error initializing folder"));
165 mailstorage_free(m_pop3);
166 m_pop3 = NULL;
167 return;
168 }
169 err = mailfolder_connect(m_folder);
170 if (err != MAIL_NO_ERROR) { 162 if (err != MAIL_NO_ERROR) {
171 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) ); 163 qDebug( QString( "FEHLERNUMMER %1" ).arg( err ) );
172 Global::statusMessage(tr("Error initializing folder")); 164 Global::statusMessage(tr("Error initializing folder"));
173 mailfolder_free(m_folder);
174 m_folder = 0;
175 mailstorage_free(m_pop3); 165 mailstorage_free(m_pop3);
176 m_pop3 = 0; 166 m_pop3 = 0;
177 } 167 }
178} 168}
179 169
180void POP3wrapper::logout() { 170void POP3wrapper::logout()
171{
181 int err = MAILPOP3_NO_ERROR; 172 int err = MAILPOP3_NO_ERROR;
182 if ( m_pop3 == NULL ) 173 if ( m_pop3 == NULL )
183 return; 174 return;
184 mailfolder_free(m_folder);
185 m_folder = 0;
186 mailstorage_free(m_pop3); 175 mailstorage_free(m_pop3);
187 m_pop3 = 0; 176 m_pop3 = 0;
188} 177}
189 178
190 179
191QList<Folder>* POP3wrapper::listFolders() { 180QList<Folder>* POP3wrapper::listFolders() {
192 QList<Folder> * folders = new QList<Folder>(); 181 QList<Folder> * folders = new QList<Folder>();
193 folders->setAutoDelete( false ); 182 folders->setAutoDelete( false );
194 Folder*inb=new Folder("INBOX","/"); 183 Folder*inb=new Folder("INBOX","/");
195 folders->append(inb); 184 folders->append(inb);
196 return folders; 185 return folders;
197} 186}
198 187
199void POP3wrapper::deleteMail(const RecMail&mail) { 188void POP3wrapper::deleteMail(const RecMail&mail) {
200 login(); 189 login();
201 if (!m_pop3) 190 if (!m_pop3)
202 return; 191 return;
203 int err = mailsession_remove_message(m_folder->fld_session,mail.getNumber()); 192 int err = mailsession_remove_message(m_pop3->sto_session,mail.getNumber());
204 if (err != MAIL_NO_ERROR) { 193 if (err != MAIL_NO_ERROR) {
205 Global::statusMessage(tr("error deleting mail")); 194 Global::statusMessage(tr("error deleting mail"));
206 } 195 }
207} 196}
208 197
209void POP3wrapper::answeredMail(const RecMail&) {} 198void POP3wrapper::answeredMail(const RecMail&) {}
210 199
211int POP3wrapper::deleteAllMail(const Folder*) { 200int POP3wrapper::deleteAllMail(const Folder*) {
212 login(); 201 login();
213 if (!m_pop3) 202 if (!m_pop3)
214 return 0; 203 return 0;
215 int res = 1; 204 int res = 1;
216 205
217 uint32_t result = 0; 206 uint32_t result = 0;
218 int err = mailsession_messages_number(m_folder->fld_session,NULL,&result); 207 int err = mailsession_messages_number(m_pop3->sto_session,NULL,&result);
219 if (err != MAIL_NO_ERROR) { 208 if (err != MAIL_NO_ERROR) {
220 Global::statusMessage(tr("Error getting folder info")); 209 Global::statusMessage(tr("Error getting folder info"));
221 return 0; 210 return 0;
222 } 211 }
223 for (unsigned int i = 0; i < result; ++i) { 212 for (unsigned int i = 0; i < result; ++i) {
224 err = mailsession_remove_message(m_folder->fld_session,i+1); 213 err = mailsession_remove_message(m_pop3->sto_session,i+1);
225 if (err != MAIL_NO_ERROR) { 214 if (err != MAIL_NO_ERROR) {
226 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 215 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
227 res=0; 216 res=0;
228 } 217 }
229 break; 218 break;
230 } 219 }
231 return res; 220 return res;
232} 221}
233 222
234void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) { 223void POP3wrapper::statusFolder(folderStat&target_stat,const QString&) {
235 login(); 224 login();
236 target_stat.message_count = 0; 225 target_stat.message_count = 0;
237 target_stat.message_unseen = 0; 226 target_stat.message_unseen = 0;
238 target_stat.message_recent = 0; 227 target_stat.message_recent = 0;
239 if (!m_pop3) 228 if (!m_pop3)
240 return; 229 return;
241 int r = mailsession_status_folder(m_folder->fld_session,0,&target_stat.message_count, 230 int r = mailsession_status_folder(m_pop3->sto_session,0,&target_stat.message_count,
242 &target_stat.message_recent,&target_stat.message_unseen); 231 &target_stat.message_recent,&target_stat.message_unseen);
243} 232}
244 233
245encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) { 234encodedString* POP3wrapper::fetchRawBody(const RecMail&mail) {
246 char*target=0; 235 char*target=0;
247 size_t length=0; 236 size_t length=0;
248 encodedString*res = 0; 237 encodedString*res = 0;
249 mailmessage * mailmsg = 0; 238 mailmessage * mailmsg = 0;
250 int err = mailsession_get_message(m_folder->fld_session, mail.getNumber(), &mailmsg); 239 int err = mailsession_get_message(m_pop3->sto_session, mail.getNumber(), &mailmsg);
251 err = mailmessage_fetch(mailmsg,&target,&length); 240 err = mailmessage_fetch(mailmsg,&target,&length);
252 if (mailmsg) 241 if (mailmsg)
253 mailmessage_free(mailmsg); 242 mailmessage_free(mailmsg);
254 if (target) { 243 if (target) {
255 res = new encodedString(target,length); 244 res = new encodedString(target,length);
256 } 245 }
257 return res; 246 return res;
258} 247}
259 248
260const QString&POP3wrapper::getType()const { 249const QString&POP3wrapper::getType()const {
261 return account->getType(); 250 return account->getType();
262} 251}
263 252
264const QString&POP3wrapper::getName()const { 253const QString&POP3wrapper::getName()const{
265 return account->getAccountName(); 254 return account->getAccountName();
266} 255}
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
@@ -24,20 +24,19 @@ public:
24 24
25 virtual void deleteMail(const RecMail&mail); 25 virtual void deleteMail(const RecMail&mail);
26 virtual void answeredMail(const RecMail&mail); 26 virtual void answeredMail(const RecMail&mail);
27 virtual int deleteAllMail(const Folder*); 27 virtual int deleteAllMail(const Folder*);
28 28
29 virtual RecBody fetchBody( const RecMail &mail ); 29 virtual RecBody fetchBody( const RecMail &mail );
30 virtual encodedString* fetchRawBody(const RecMail&mail); 30 virtual encodedString* fetchRawBody(const RecMail&mail);
31 virtual void logout(); 31 virtual void logout();
32 virtual const QString&getType()const; 32 virtual const QString&getType()const;
33 virtual const QString&getName()const; 33 virtual const QString&getName()const;
34 static void pop3_progress( size_t current, size_t maximum ); 34 static void pop3_progress( size_t current, size_t maximum );
35 35
36protected: 36protected:
37 void login(); 37 void login();
38 POP3account *account; 38 POP3account *account;
39 mailstorage*m_pop3; 39 mailstorage*m_pop3;
40 mailfolder*m_folder;
41}; 40};
42 41
43#endif 42#endif