summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/mhwrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/mhwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/mhwrapper.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp
index cbc52d9..962dac0 100644
--- a/kmicromail/libmailwrapper/mhwrapper.cpp
+++ b/kmicromail/libmailwrapper/mhwrapper.cpp
@@ -1,163 +1,164 @@
1// CHANGED 2004-09-31 Lutz Rogowski 1// CHANGED 2004-09-31 Lutz Rogowski
2#include "mhwrapper.h" 2#include "mhwrapper.h"
3#include "mailtypes.h" 3#include "mailtypes.h"
4#include "mailwrapper.h" 4#include "mailwrapper.h"
5#include <libetpan/libetpan.h> 5#include <libetpan/libetpan.h>
6#include <qdir.h> 6#include <qdir.h>
7#include <qmessagebox.h> 7#include <qmessagebox.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <qpe/global.h> 9#include <qpe/global.h>
10#include <oprocess.h> 10#include <oprocess.h>
11//#include <opie2/odebug.h> 11//#include <opie2/odebug.h>
12 12
13using namespace Opie::Core; 13using namespace Opie::Core;
14MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 14MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
15 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 15 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
16{ 16{
17 if (MHPath.length()>0) { 17 if (MHPath.length()>0) {
18 if (MHPath[MHPath.length()-1]=='/') { 18 if (MHPath[MHPath.length()-1]=='/') {
19 MHPath=MHPath.left(MHPath.length()-1); 19 MHPath=MHPath.left(MHPath.length()-1);
20 } 20 }
21 //odebug << MHPath << oendl; 21 //odebug << MHPath << oendl;
22 QDir dir(MHPath); 22 QDir dir(MHPath);
23 if (!dir.exists()) { 23 if (!dir.exists()) {
24 dir.mkdir(MHPath); 24 dir.mkdir(MHPath);
25 } 25 }
26 init_storage(); 26 init_storage();
27 } 27 }
28} 28}
29 29
30void MHwrapper::init_storage() 30void MHwrapper::init_storage()
31{ 31{
32 int r; 32 int r;
33 QString pre = MHPath; 33 QString pre = MHPath;
34 if (!m_storage) { 34 if (!m_storage) {
35 m_storage = mailstorage_new(NULL); 35 m_storage = mailstorage_new(NULL);
36 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 36 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
37 if (r != MAIL_NO_ERROR) { 37 if (r != MAIL_NO_ERROR) {
38 qDebug(" error init storage "); 38 qDebug(" error init storage ");
39 mailstorage_free(m_storage); 39 mailstorage_free(m_storage);
40 m_storage = 0; 40 m_storage = 0;
41 return; 41 return;
42 } 42 }
43 } 43 }
44 r = mailstorage_connect(m_storage); 44 r = mailstorage_connect(m_storage);
45 if (r!=MAIL_NO_ERROR) { 45 if (r!=MAIL_NO_ERROR) {
46 qDebug("error connecting storage "); 46 qDebug("error connecting storage ");
47 mailstorage_free(m_storage); 47 mailstorage_free(m_storage);
48 m_storage = 0; 48 m_storage = 0;
49 } 49 }
50} 50}
51 51
52void MHwrapper::clean_storage() 52void MHwrapper::clean_storage()
53{ 53{
54 if (m_storage) { 54 if (m_storage) {
55 mailstorage_disconnect(m_storage); 55 mailstorage_disconnect(m_storage);
56 mailstorage_free(m_storage); 56 mailstorage_free(m_storage);
57 m_storage = 0; 57 m_storage = 0;
58 } 58 }
59} 59}
60 60
61MHwrapper::~MHwrapper() 61MHwrapper::~MHwrapper()
62{ 62{
63 clean_storage(); 63 clean_storage();
64} 64}
65 65
66void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) 66void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb )
67{ 67{
68 qDebug("MHwrapper::listMessages ");
68 init_storage(); 69 init_storage();
69 if (!m_storage) { 70 if (!m_storage) {
70 return; 71 return;
71 } 72 }
72 QString f = buildPath(mailbox); 73 QString f = buildPath(mailbox);
73 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 74 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
74 if (r!=MAIL_NO_ERROR) { 75 if (r!=MAIL_NO_ERROR) {
75 qDebug("listMessages: error selecting folder! "); 76 qDebug("listMessages: error selecting folder! ");
76 return; 77 return;
77 } 78 }
78 parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); 79 parseList(target,m_storage->sto_session,f, false, maxSizeInKb );
79 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 80 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
80} 81}
81 82
82QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() 83QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders()
83{ 84{
84 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); 85 QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >();
85 /* this is needed! */ 86 /* this is needed! */
86 if (m_storage) mailstorage_disconnect(m_storage); 87 if (m_storage) mailstorage_disconnect(m_storage);
87 init_storage(); 88 init_storage();
88 if (!m_storage) { 89 if (!m_storage) {
89 return folders; 90 return folders;
90 } 91 }
91 mail_list*flist = 0; 92 mail_list*flist = 0;
92 clistcell*current=0; 93 clistcell*current=0;
93 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 94 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
94 if (r != MAIL_NO_ERROR || !flist) { 95 if (r != MAIL_NO_ERROR || !flist) {
95 qDebug("error getting folder list "); 96 qDebug("error getting folder list ");
96 return folders; 97 return folders;
97 } 98 }
98 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 99 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
99 QString t = (char*)current->data; 100 QString t = (char*)current->data;
100 t.replace(0,MHPath.length(),""); 101 t.replace(0,MHPath.length(),"");
101 folders->append(new MHFolder(t,MHPath)); 102 folders->append(new MHFolder(t,MHPath));
102 } 103 }
103 mail_list_free(flist); 104 mail_list_free(flist);
104 return folders; 105 return folders;
105} 106}
106 107
107void MHwrapper::deleteMail(const RecMailP&mail) 108void MHwrapper::deleteMail(const RecMailP&mail)
108{ 109{
109 init_storage(); 110 init_storage();
110 if (!m_storage) { 111 if (!m_storage) {
111 return; 112 return;
112 } 113 }
113 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 114 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
114 if (r!=MAIL_NO_ERROR) { 115 if (r!=MAIL_NO_ERROR) {
115 qDebug("error selecting folder! "); 116 qDebug("error selecting folder! ");
116 return; 117 return;
117 } 118 }
118 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber()); 119 r = mailsession_remove_message(m_storage->sto_session,mail->getNumber());
119 if (r != MAIL_NO_ERROR) { 120 if (r != MAIL_NO_ERROR) {
120 qDebug("error deleting mail "); 121 qDebug("error deleting mail ");
121 } 122 }
122} 123}
123 124
124void MHwrapper::answeredMail(const RecMailP&) 125void MHwrapper::answeredMail(const RecMailP&)
125{ 126{
126} 127}
127 128
128RecBodyP MHwrapper::fetchBody( const RecMailP &mail ) 129RecBodyP MHwrapper::fetchBody( const RecMailP &mail )
129{ 130{
130 RecBodyP body = new RecBody(); 131 RecBodyP body = new RecBody();
131 init_storage(); 132 init_storage();
132 if (!m_storage) { 133 if (!m_storage) {
133 return body; 134 return body;
134 } 135 }
135 mailmessage * msg; 136 mailmessage * msg;
136 char*data=0; 137 char*data=0;
137 138
138 /* mail should hold the complete path! */ 139 /* mail should hold the complete path! */
139 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); 140 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1());
140 if (r != MAIL_NO_ERROR) { 141 if (r != MAIL_NO_ERROR) {
141 return body; 142 return body;
142 } 143 }
143 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); 144 r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg);
144 if (r != MAIL_NO_ERROR) { 145 if (r != MAIL_NO_ERROR) {
145 qDebug("Error fetching mail "); 146 qDebug("Error fetching mail ");
146 147
147 return body; 148 return body;
148 } 149 }
149 body = parseMail(msg); 150 body = parseMail(msg);
150 mailmessage_fetch_result_free(msg,data); 151 mailmessage_fetch_result_free(msg,data);
151 return body; 152 return body;
152} 153}
153 154
154void MHwrapper::mbox_progress( size_t current, size_t maximum ) 155void MHwrapper::mbox_progress( size_t current, size_t maximum )
155{ 156{
156 qDebug("MBox Progress %d of %d",current,maximum ); 157 qDebug("MBox Progress %d of %d",current,maximum );
157 //odebug << "MH " << current << " von " << maximum << "" << oendl; 158 //odebug << "MH " << current << " von " << maximum << "" << oendl;
158} 159}
159 160
160QString MHwrapper::buildPath(const QString&p) 161QString MHwrapper::buildPath(const QString&p)
161{ 162{
162 QString f=""; 163 QString f="";
163 if (p.length()==0||p=="/") 164 if (p.length()==0||p=="/")