summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-08 19:15:10 (UTC)
committer alwin <alwin>2004-01-08 19:15:10 (UTC)
commit6287f011db0a566d17ae1614d8129f421125d934 (patch) (unidiff)
tree8c449974e9b577fe8dcc5348c4d109e82659b218
parent44443aec5d4b8f974b30b1e9b4ea920d6582add1 (diff)
downloadopie-6287f011db0a566d17ae1614d8129f421125d934.zip
opie-6287f011db0a566d17ae1614d8129f421125d934.tar.gz
opie-6287f011db0a566d17ae1614d8129f421125d934.tar.bz2
MH storage implemented
local folders will be type of MH not MBOX
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/accountview.cpp64
-rw-r--r--noncore/net/mail/accountview.h18
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp3
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp8
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro6
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.cpp18
-rw-r--r--noncore/net/mail/libmailwrapper/mailwrapper.h11
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h1
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp330
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.h50
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp3
12 files changed, 468 insertions, 48 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp
index 9f4f358..62cbf62 100644
--- a/noncore/net/mail/accountview.cpp
+++ b/noncore/net/mail/accountview.cpp
@@ -578,5 +578,5 @@ AccountView::~AccountView()
578{ 578{
579 imapAccounts.clear(); 579 imapAccounts.clear();
580 mboxAccounts.clear(); 580 mhAccounts.clear();
581} 581}
582 582
@@ -606,7 +606,7 @@ void AccountView::populate( QList<Account> list )
606 606
607 imapAccounts.clear(); 607 imapAccounts.clear();
608 mboxAccounts.clear(); 608 mhAccounts.clear();
609 609
610 mboxAccounts.append(new MBOXviewItem(AbstractMail::defaultLocalfolder(),this)); 610 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
611 611
612 Account *it; 612 Account *it;
@@ -667,8 +667,8 @@ void AccountView::setupFolderselect(Selectstore*sels)
667 QStringList sFolders; 667 QStringList sFolders;
668 unsigned int i = 0; 668 unsigned int i = 0;
669 for (i=0; i < mboxAccounts.count();++i) { 669 for (i=0; i < mhAccounts.count();++i) {
670 mboxAccounts[i]->refresh(false); 670 mhAccounts[i]->refresh(false);
671 sFolders = mboxAccounts[i]->subFolders(); 671 sFolders = mhAccounts[i]->subFolders();
672 sels->addAccounts(mboxAccounts[i]->getWrapper(),sFolders); 672 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
673 } 673 }
674 for (i=0; i < imapAccounts.count();++i) { 674 for (i=0; i < imapAccounts.count();++i) {
@@ -705,8 +705,8 @@ void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper)
705 705
706/** 706/**
707 * MBOX Account stuff 707 * MH Account stuff
708 */ 708 */
709 709
710MBOXviewItem::MBOXviewItem( const QString&aPath, AccountView *parent ) 710MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
711 : AccountViewItem( parent ) 711 : AccountViewItem( parent )
712{ 712{
@@ -719,20 +719,20 @@ MBOXviewItem::MBOXviewItem( const QString&aPath, AccountView *parent )
719} 719}
720 720
721MBOXviewItem::~MBOXviewItem() 721MHviewItem::~MHviewItem()
722{ 722{
723 delete wrapper; 723 delete wrapper;
724} 724}
725 725
726AbstractMail *MBOXviewItem::getWrapper() 726AbstractMail *MHviewItem::getWrapper()
727{ 727{
728 return wrapper; 728 return wrapper;
729} 729}
730 730
731void MBOXviewItem::refresh( QList<RecMail> & ) 731void MHviewItem::refresh( QList<RecMail> & )
732{ 732{
733 refresh(false); 733 refresh(false);
734} 734}
735 735
736void MBOXviewItem::refresh(bool force) 736void MHviewItem::refresh(bool force)
737{ 737{
738 if (childCount()>0 && force==false) return; 738 if (childCount()>0 && force==false) return;
@@ -747,5 +747,5 @@ void MBOXviewItem::refresh(bool force)
747 QListViewItem*item = 0; 747 QListViewItem*item = 0;
748 for ( it = folders->first(); it; it = folders->next() ) { 748 for ( it = folders->first(); it; it = folders->next() ) {
749 item = new MBOXfolderItem( it, this , item ); 749 item = new MHfolderItem( it, this , item );
750 item->setSelectable(it->may_select()); 750 item->setSelectable(it->may_select());
751 } 751 }
@@ -755,11 +755,11 @@ void MBOXviewItem::refresh(bool force)
755} 755}
756 756
757RecBody MBOXviewItem::fetchBody( const RecMail &mail ) 757RecBody MHviewItem::fetchBody( const RecMail &mail )
758{ 758{
759 qDebug( "MBOX fetchBody" ); 759 qDebug( "MH fetchBody" );
760 return wrapper->fetchBody( mail ); 760 return wrapper->fetchBody( mail );
761} 761}
762 762
763QPopupMenu * MBOXviewItem::getContextMenu() 763QPopupMenu * MHviewItem::getContextMenu()
764{ 764{
765 QPopupMenu *m = new QPopupMenu(0); 765 QPopupMenu *m = new QPopupMenu(0);
@@ -771,5 +771,5 @@ QPopupMenu * MBOXviewItem::getContextMenu()
771} 771}
772 772
773void MBOXviewItem::createFolder() 773void MHviewItem::createFolder()
774{ 774{
775 Newmdirdlg ndirdlg(0,0,true); 775 Newmdirdlg ndirdlg(0,0,true);
@@ -783,12 +783,12 @@ void MBOXviewItem::createFolder()
783} 783}
784 784
785QStringList MBOXviewItem::subFolders() 785QStringList MHviewItem::subFolders()
786{ 786{
787 QStringList result; 787 QStringList result;
788 QListViewItem *child = firstChild(); 788 QListViewItem *child = firstChild();
789 while ( child ) { 789 while ( child ) {
790 MBOXfolderItem *tmp = (MBOXfolderItem*)child; 790 MHfolderItem *tmp = (MHfolderItem*)child;
791 child = child->nextSibling(); 791 child = child->nextSibling();
792 result.append(tmp->getFolder()->getName()); 792 result.append(tmp->getFolder()->getDisplayName());
793 } 793 }
794 qDebug("Size of result: %i",result.count()); 794 qDebug("Size of result: %i",result.count());
@@ -796,5 +796,5 @@ QStringList MBOXviewItem::subFolders()
796} 796}
797 797
798void MBOXviewItem::contextMenuSelected(int which) 798void MHviewItem::contextMenuSelected(int which)
799{ 799{
800 switch (which) { 800 switch (which) {
@@ -810,10 +810,10 @@ void MBOXviewItem::contextMenuSelected(int which)
810} 810}
811 811
812MBOXfolderItem::~MBOXfolderItem() 812MHfolderItem::~MHfolderItem()
813{ 813{
814 delete folder; 814 delete folder;
815} 815}
816 816
817MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QListViewItem*after ) 817MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after )
818 : AccountViewItem( parent,after ) 818 : AccountViewItem( parent,after )
819{ 819{
@@ -830,10 +830,10 @@ MBOXfolderItem::MBOXfolderItem( Folder *folderInit, MBOXviewItem *parent , QList
830} 830}
831 831
832Folder*MBOXfolderItem::getFolder() 832Folder*MHfolderItem::getFolder()
833{ 833{
834 return folder; 834 return folder;
835} 835}
836 836
837void MBOXfolderItem::refresh(QList<RecMail>&target) 837void MHfolderItem::refresh(QList<RecMail>&target)
838{ 838{
839 if (folder->may_select()) 839 if (folder->may_select())
@@ -841,10 +841,10 @@ void MBOXfolderItem::refresh(QList<RecMail>&target)
841} 841}
842 842
843RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) 843RecBody MHfolderItem::fetchBody(const RecMail&aMail)
844{ 844{
845 return mbox->getWrapper()->fetchBody(aMail); 845 return mbox->getWrapper()->fetchBody(aMail);
846} 846}
847 847
848void MBOXfolderItem::deleteFolder() 848void MHfolderItem::deleteFolder()
849{ 849{
850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), 850 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
@@ -856,5 +856,5 @@ void MBOXfolderItem::deleteFolder()
856 if (mbox->getWrapper()->deleteMbox(folder)) { 856 if (mbox->getWrapper()->deleteMbox(folder)) {
857 QListView*v=listView(); 857 QListView*v=listView();
858 MBOXviewItem * box = mbox; 858 MHviewItem * box = mbox;
859 /* be carefull - after that this object is destroyd so don't use 859 /* be carefull - after that this object is destroyd so don't use
860 * any member of it after that call!!*/ 860 * any member of it after that call!!*/
@@ -867,5 +867,5 @@ void MBOXfolderItem::deleteFolder()
867} 867}
868 868
869QPopupMenu * MBOXfolderItem::getContextMenu() 869QPopupMenu * MHfolderItem::getContextMenu()
870{ 870{
871 QPopupMenu *m = new QPopupMenu(0); 871 QPopupMenu *m = new QPopupMenu(0);
@@ -878,5 +878,5 @@ QPopupMenu * MBOXfolderItem::getContextMenu()
878} 878}
879 879
880void MBOXfolderItem::downloadMails() 880void MHfolderItem::downloadMails()
881{ 881{
882 AccountView*bl = mbox->accountView(); 882 AccountView*bl = mbox->accountView();
@@ -885,5 +885,5 @@ void MBOXfolderItem::downloadMails()
885} 885}
886 886
887void MBOXfolderItem::contextMenuSelected(int which) 887void MHfolderItem::contextMenuSelected(int which)
888{ 888{
889 switch(which) { 889 switch(which) {
diff --git a/noncore/net/mail/accountview.h b/noncore/net/mail/accountview.h
index d9b5558..f5a2973 100644
--- a/noncore/net/mail/accountview.h
+++ b/noncore/net/mail/accountview.h
@@ -119,11 +119,11 @@ protected:
119}; 119};
120 120
121class MBOXviewItem : public AccountViewItem 121class MHviewItem : public AccountViewItem
122{ 122{
123 friend class MBOXfolderItem; 123 friend class MHfolderItem;
124 124
125public: 125public:
126 MBOXviewItem( const QString&aMboxPath, AccountView *parent ); 126 MHviewItem( const QString&aMboxPath, AccountView *parent );
127 virtual ~MBOXviewItem(); 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 );
@@ -141,10 +141,10 @@ protected:
141}; 141};
142 142
143class MBOXfolderItem : public AccountViewItem 143class MHfolderItem : public AccountViewItem
144{ 144{
145 145
146public: 146public:
147 MBOXfolderItem( Folder *folder, MBOXviewItem *parent , QListViewItem*after ); 147 MHfolderItem( Folder *folder, MHviewItem *parent , QListViewItem*after );
148 virtual ~MBOXfolderItem(); 148 virtual ~MHfolderItem();
149 virtual void refresh(QList<RecMail>&); 149 virtual void refresh(QList<RecMail>&);
150 virtual RecBody fetchBody(const RecMail&); 150 virtual RecBody fetchBody(const RecMail&);
@@ -157,5 +157,5 @@ protected:
157 virtual void deleteFolder(); 157 virtual void deleteFolder();
158 Folder *folder; 158 Folder *folder;
159 MBOXviewItem *mbox; 159 MHviewItem *mbox;
160}; 160};
161 161
@@ -185,5 +185,5 @@ protected:
185 QListViewItem* m_currentItem; 185 QListViewItem* m_currentItem;
186 QValueList<IMAPviewItem*> imapAccounts; 186 QValueList<IMAPviewItem*> imapAccounts;
187 QValueList<MBOXviewItem*> mboxAccounts; 187 QValueList<MHviewItem*> mhAccounts;
188}; 188};
189 189
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 0280803..592cd5e 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -2,4 +2,5 @@
2#include "imapwrapper.h" 2#include "imapwrapper.h"
3#include "pop3wrapper.h" 3#include "pop3wrapper.h"
4#include "mhwrapper.h"
4#include "mboxwrapper.h" 5#include "mboxwrapper.h"
5#include "mailtypes.h" 6#include "mailtypes.h"
@@ -24,5 +25,5 @@ AbstractMail* AbstractMail::getWrapper(POP3account *a)
24AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name) 25AbstractMail* AbstractMail::getWrapper(const QString&a,const QString&name)
25{ 26{
26 return new MBOXwrapper(a,name); 27 return new MHwrapper(a,name);
27} 28}
28 29
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index 2d1596d..b1e4459 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -7,8 +7,16 @@ Genericwrapper::Genericwrapper()
7{ 7{
8 bodyCache.clear(); 8 bodyCache.clear();
9 m_storage = 0;
10 m_folder = 0;
9} 11}
10 12
11Genericwrapper::~Genericwrapper() 13Genericwrapper::~Genericwrapper()
12{ 14{
15 if (m_folder) {
16 mailfolder_free(m_folder);
17 }
18 if (m_storage) {
19 mailstorage_free(m_storage);
20 }
13 cleanMimeCache(); 21 cleanMimeCache();
14} 22}
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 1d65c0a..e471dc8 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -20,4 +20,6 @@ struct mailimf_group;
20struct mailimf_address_list; 20struct mailimf_address_list;
21struct mailsession; 21struct mailsession;
22struct mailstorage;
23struct mailfolder;
22 24
23/* this class hold just the funs shared between 25/* this class hold just the funs shared between
@@ -58,4 +60,6 @@ protected:
58 unsigned int last_msg_id; 60 unsigned int last_msg_id;
59 QMap<QString,encodedString*> bodyCache; 61 QMap<QString,encodedString*> bodyCache;
62 mailstorage * m_storage;
63 mailfolder*m_folder;
60}; 64};
61 65
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
index 18583bb..71f6cca 100644
--- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro
+++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
@@ -13,5 +13,6 @@ HEADERS = mailwrapper.h \
13 logindialog.h \ 13 logindialog.h \
14 sendmailprogress.h \ 14 sendmailprogress.h \
15 statusmail.h 15 statusmail.h \
16 mhwrapper.h
16 17
17SOURCES = imapwrapper.cpp \ 18SOURCES = imapwrapper.cpp \
@@ -26,5 +27,6 @@ SOURCES = imapwrapper.cpp \
26 logindialog.cpp \ 27 logindialog.cpp \
27 sendmailprogress.cpp \ 28 sendmailprogress.cpp \
28 statusmail.cpp 29 statusmail.cpp \
30 mhwrapper.cpp
29 31
30 INTERFACES = logindialogui.ui \ 32 INTERFACES = logindialogui.ui \
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.cpp b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
index 75b9343..ebdbf4b 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.cpp
@@ -33,4 +33,5 @@ Folder::Folder(const QString&tmp_name, const QString&sep )
33 nameDisplay = name; 33 nameDisplay = name;
34 separator = sep; 34 separator = sep;
35 prefix = "";
35} 36}
36 37
@@ -40,5 +41,5 @@ const QString& Folder::Separator()const
40} 41}
41 42
42IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&prefix ) 43IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no_inf, const QString&aprefix )
43 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf) 44 : Folder( name,sep ),m_MaySelect(select),m_NoInferior(no_inf)
44{ 45{
@@ -46,4 +47,5 @@ IMAPFolder::IMAPFolder(const QString&name,const QString&sep, bool select,bool no
46 nameDisplay = IMAPFolder::decodeFolderName( name ); 47 nameDisplay = IMAPFolder::decodeFolderName( name );
47 qDebug( "folder " + name + " - displayed as " + nameDisplay ); 48 qDebug( "folder " + name + " - displayed as " + nameDisplay );
49 prefix = aprefix;
48 50
49 if (prefix.length()>0) { 51 if (prefix.length()>0) {
@@ -147,2 +149,16 @@ Mail::Mail()
147{ 149{
148} 150}
151
152MHFolder::MHFolder(const QString&disp_name,const QString&mbox)
153 : Folder( disp_name,"/" )
154{
155 separator = "/";
156 name = mbox;
157 if (!disp_name.startsWith("/") && disp_name.length()>0)
158 name+="/";
159 name+=disp_name;
160 if (disp_name.length()==0) {
161 nameDisplay = separator;
162 }
163 prefix = mbox;
164}
diff --git a/noncore/net/mail/libmailwrapper/mailwrapper.h b/noncore/net/mail/libmailwrapper/mailwrapper.h
index a60777d..caaa3a2 100644
--- a/noncore/net/mail/libmailwrapper/mailwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mailwrapper.h
@@ -70,4 +70,5 @@ public:
70 const QString&getDisplayName()const { return nameDisplay; } 70 const QString&getDisplayName()const { return nameDisplay; }
71 const QString&getName()const { return name; } 71 const QString&getName()const { return name; }
72 const QString&getPrefix()const{return prefix; }
72 virtual bool may_select()const{return true;} 73 virtual bool may_select()const{return true;}
73 virtual bool no_inferior()const{return true;} 74 virtual bool no_inferior()const{return true;}
@@ -75,6 +76,12 @@ public:
75 76
76protected: 77protected:
77 QString nameDisplay, name, separator; 78 QString nameDisplay, name, separator,prefix;
78 79};
80
81class MHFolder : public Folder
82{
83 Q_OBJECT
84public:
85 MHFolder(const QString&disp_name,const QString&mbox);
79}; 86};
80 87
diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h
index 194ff86..a579a3d 100644
--- a/noncore/net/mail/libmailwrapper/mboxwrapper.h
+++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h
@@ -13,4 +13,5 @@ class MBOXwrapper : public Genericwrapper
13{ 13{
14 Q_OBJECT 14 Q_OBJECT
15
15public: 16public:
16 MBOXwrapper(const QString & dir,const QString&name); 17 MBOXwrapper(const QString & dir,const QString&name);
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
new file mode 100644
index 0000000..85f9cf0
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
@@ -0,0 +1,330 @@
1#include "mhwrapper.h"
2#include "mailtypes.h"
3#include "mailwrapper.h"
4#include <libetpan/libetpan.h>
5#include <qdir.h>
6#include <stdlib.h>
7#include <qpe/global.h>
8
9const QString MHwrapper::wrapperType="MH";
10
11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
13{
14 if (MHPath.length()>0) {
15 if (MHPath[MHPath.length()-1]=='/') {
16 MHPath=MHPath.left(MHPath.length()-1);
17 }
18 qDebug(MHPath);
19 QDir dir(MHPath);
20 if (!dir.exists()) {
21 dir.mkdir(MHPath);
22 }
23 init_storage();
24 }
25}
26
27void MHwrapper::init_storage()
28{
29 int r;
30 QString pre = MHPath;
31 if (!m_storage) {
32 m_storage = mailstorage_new(NULL);
33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
34 if (r != MAIL_NO_ERROR) {
35 qDebug("error initializing storage");
36 mailstorage_free(m_storage);
37 m_storage = 0;
38 return;
39 }
40 }
41 r = mailstorage_connect(m_storage);
42 if (r!=MAIL_NO_ERROR) {
43 qDebug("error connecting storage");
44 mailstorage_free(m_storage);
45 m_storage = 0;
46 }
47}
48
49void MHwrapper::clean_storage()
50{
51 if (m_storage) {
52 mailstorage_disconnect(m_storage);
53 mailstorage_free(m_storage);
54 m_storage = 0;
55 }
56}
57
58MHwrapper::~MHwrapper()
59{
60 clean_storage();
61}
62
63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
64{
65 init_storage();
66 if (!m_storage) {
67 return;
68 }
69 QString f = buildPath(mailbox);
70 int r = mailsession_select_folder(m_storage->sto_session,(char*)mailbox.latin1());
71 if (r!=MAIL_NO_ERROR) {
72 qDebug("error selecting folder!");
73 return;
74 }
75 parseList(target,m_storage->sto_session,f);
76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
77}
78
79QList<Folder>* MHwrapper::listFolders()
80{
81 QList<Folder> * folders = new QList<Folder>();
82 folders->setAutoDelete( false );
83 init_storage();
84 if (!m_storage) {
85 return folders;
86 }
87 mail_list*flist = 0;
88 clistcell*current=0;
89 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
90 if (r != MAIL_NO_ERROR || !flist) {
91 qDebug("error getting folder list");
92 return folders;
93 }
94 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
95 QString t = (char*)current->data;
96 t.replace(0,MHPath.length(),"");
97 folders->append(new MHFolder(t,MHPath));
98 }
99 mail_list_free(flist);
100 return folders;
101}
102
103void MHwrapper::deleteMail(const RecMail&mail)
104{
105 init_storage();
106 if (!m_storage) {
107 return;
108 }
109 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
110 if (r!=MAIL_NO_ERROR) {
111 qDebug("error selecting folder!");
112 return;
113 }
114 r = mailsession_remove_message(m_storage->sto_session,mail.getNumber());
115 if (r != MAIL_NO_ERROR) {
116 qDebug("error deleting mail");
117 }
118}
119
120void MHwrapper::answeredMail(const RecMail&)
121{
122}
123
124RecBody MHwrapper::fetchBody( const RecMail &mail )
125{
126 RecBody body;
127 init_storage();
128 if (!m_storage) {
129 return body;
130 }
131 mailmessage * msg;
132 char*data=0;
133 size_t size;
134
135 /* mail should hold the complete path! */
136 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
137 if (r != MAIL_NO_ERROR) {
138 return body;
139 }
140 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
141 if (r != MAIL_NO_ERROR) {
142 qDebug("Error fetching mail %i",mail.getNumber());
143 return body;
144 }
145 body = parseMail(msg);
146 mailmessage_fetch_result_free(msg,data);
147 return body;
148}
149
150void MHwrapper::mbox_progress( size_t current, size_t maximum )
151{
152 qDebug("MH %i von %i",current,maximum);
153}
154
155QString MHwrapper::buildPath(const QString&p)
156{
157 QString f="";
158 if (p.length()==0||p=="/")
159 return MHPath;
160 if (!p.startsWith(MHPath)) {
161 f+=MHPath;
162 }
163 if (!p.startsWith("/")) {
164 f+="/";
165 }
166 f+=p;
167 return f;
168}
169
170int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
171{
172 init_storage();
173 if (!m_storage) {
174 return 0;
175 }
176 QString f = buildPath(folder);
177 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
178 if (r != MAIL_NO_ERROR) {
179 qDebug("error creating folder");
180 return 0;
181 }
182 qDebug("Folder created");
183 mailstorage_disconnect(m_storage);
184 return 1;
185}
186
187void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
188{
189 init_storage();
190 if (!m_storage) {
191 return;
192 }
193 QString f = buildPath(Folder);
194 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
195 if (r!=MAIL_NO_ERROR) {
196 qDebug("error selecting folder!");
197 return;
198 }
199 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
200 if (r!=MAIL_NO_ERROR) {
201 qDebug("error storing mail");
202 }
203 return;
204}
205
206encodedString* MHwrapper::fetchRawBody(const RecMail&mail)
207{
208 encodedString*result = 0;
209 init_storage();
210 if (!m_storage) {
211 return result;
212 }
213 mailmessage * msg = 0;
214 char*data=0;
215 size_t size;
216 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
217 if (r!=MAIL_NO_ERROR) {
218 qDebug("error selecting folder!");
219 return result;
220 }
221 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
222 if (r != MAIL_NO_ERROR) {
223 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
224 return 0;
225 }
226 r = mailmessage_fetch(msg,&data,&size);
227 if (r != MAIL_NO_ERROR) {
228 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
229 if (msg) mailmessage_free(msg);
230 return 0;
231 }
232 result = new encodedString(data,size);
233 if (msg) mailmessage_free(msg);
234 return result;
235}
236
237void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
238{
239#if 0
240 QString p = MHPath+"/";
241 p+=mailbox;
242 mailmbox_folder*f = 0;
243 int r = mailmbox_init(p.latin1(),0,1,0,&f);
244 if (r != MAIL_NO_ERROR) {
245 qDebug("Error init folder");
246 return;
247 }
248 deleteMails(f,target);
249 mailmbox_done(f);
250#endif
251}
252
253int MHwrapper::deleteAllMail(const Folder*tfolder)
254{
255 init_storage();
256 if (!m_storage) {
257 return 0;
258 }
259 int res = 1;
260 if (!tfolder) return 0;
261 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
262 if (r!=MAIL_NO_ERROR) {
263 qDebug("error selecting folder!");
264 return 0;
265 }
266 mailmessage_list*l=0;
267 r = mailsession_get_messages_list(m_storage->sto_session,&l);
268 if (r != MAIL_NO_ERROR) {
269 qDebug("Error message list");
270 res = 0;
271 }
272 unsigned j = 0;
273 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
274 mailmessage * msg;
275 msg = (mailmessage*)carray_get(l->msg_tab, i);
276 j = msg->msg_index;
277 r = mailsession_remove_message(m_storage->sto_session,j);
278 if (r != MAIL_NO_ERROR) {
279 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
280 res = 0;
281 break;
282 }
283 }
284 if (l) mailmessage_list_free(l);
285 return res;
286}
287
288int MHwrapper::deleteMbox(const Folder*tfolder)
289{
290 init_storage();
291 if (!m_storage) {
292 return 0;
293 }
294 if (!tfolder) return 0;
295 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
296 if (r != MAIL_NO_ERROR) {
297 qDebug("error deleting mail box");
298 return 0;
299 }
300 qDebug("mail box deleted");
301 mailstorage_disconnect(m_storage);
302 return 1;
303}
304
305void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
306{
307 init_storage();
308 if (!m_storage) {
309 return;
310 }
311 target_stat.message_count = 0;
312 target_stat.message_unseen = 0;
313 target_stat.message_recent = 0;
314 QString f = buildPath(mailbox);
315 int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count,
316 &target_stat.message_recent,&target_stat.message_unseen);
317 if (r != MAIL_NO_ERROR) {
318 Global::statusMessage(tr("Error retrieving status"));
319 }
320}
321
322const QString&MHwrapper::getType()const
323{
324 return wrapperType;
325}
326
327const QString&MHwrapper::getName()const
328{
329 return MHName;
330}
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.h b/noncore/net/mail/libmailwrapper/mhwrapper.h
new file mode 100644
index 0000000..7f028b4
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.h
@@ -0,0 +1,50 @@
1#ifndef __MH_WRAPPER_H
2#define __MH_WRAPPER_H
3
4#include "genericwrapper.h"
5#include <qstring.h>
6
7class RecMail;
8class RecBody;
9class encodedString;
10struct mailmbox_folder;
11
12class MHwrapper : public Genericwrapper
13{
14 Q_OBJECT
15public:
16 MHwrapper(const QString & dir,const QString&name);
17 virtual ~MHwrapper();
18
19 virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
20 virtual QList<Folder>* listFolders();
21 virtual void statusFolder(folderStat&target_stat,const QString & mailbox="INBOX");
22
23 virtual void deleteMail(const RecMail&mail);
24 virtual void answeredMail(const RecMail&mail);
25
26 virtual int createMbox(const QString&folder,const Folder*f=0,const QString&d="",bool s=false);
27 virtual int deleteMbox(const Folder*);
28
29 virtual void storeMessage(const char*msg,size_t length, const QString&folder);
30
31 virtual RecBody fetchBody( const RecMail &mail );
32 static void mbox_progress( size_t current, size_t maximum );
33
34 virtual encodedString* fetchRawBody(const RecMail&mail);
35 virtual void deleteMails(const QString & FolderName,QList<RecMail> &target);
36 virtual int deleteAllMail(const Folder*);
37 virtual const QString&getType()const;
38 virtual const QString&getName()const;
39
40protected:
41 QString buildPath(const QString&p);
42 QString MHPath;
43 QString MHName;
44 static const QString wrapperType;
45
46 void init_storage();
47 void clean_storage();
48};
49
50#endif
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 281b88e..08f6bb7 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -15,5 +15,5 @@
15#include "smtpwrapper.h" 15#include "smtpwrapper.h"
16#include "mailwrapper.h" 16#include "mailwrapper.h"
17#include "mboxwrapper.h" 17#include "abstractmail.h"
18#include "logindialog.h" 18#include "logindialog.h"
19#include "mailtypes.h" 19#include "mailtypes.h"
@@ -491,4 +491,5 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box)
491 QString localfolders = AbstractMail::defaultLocalfolder(); 491 QString localfolders = AbstractMail::defaultLocalfolder();
492 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 492 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
493 wrap->createMbox(box);
493 wrap->storeMessage(mail,length,box); 494 wrap->storeMessage(mail,length,box);
494 delete wrap; 495 delete wrap;