summaryrefslogtreecommitdiff
authoralwin <alwin>2004-01-08 21:51:32 (UTC)
committer alwin <alwin>2004-01-08 21:51:32 (UTC)
commitfb30e3e116d8616cb05b3765ae1aed5f7e96c74e (patch) (unidiff)
tree393ebb7b913c01697146ac804d980f8b8713f81a
parentb672058ac470a1b9534296fa8bc4b8725ab7913b (diff)
downloadopie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.zip
opie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.tar.gz
opie-fb30e3e116d8616cb05b3765ae1aed5f7e96c74e.tar.bz2
- last functions re-implemented
- small bugfix TODO: remove twice code within pop3/mh/mbox wrapper
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/mhwrapper.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
index 85f9cf0..5adba55 100644
--- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp
@@ -1,330 +1,333 @@
1#include "mhwrapper.h" 1#include "mhwrapper.h"
2#include "mailtypes.h" 2#include "mailtypes.h"
3#include "mailwrapper.h" 3#include "mailwrapper.h"
4#include <libetpan/libetpan.h> 4#include <libetpan/libetpan.h>
5#include <qdir.h> 5#include <qdir.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <qpe/global.h> 7#include <qpe/global.h>
8 8
9const QString MHwrapper::wrapperType="MH"; 9const QString MHwrapper::wrapperType="MH";
10 10
11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) 11MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name)
12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) 12 : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name)
13{ 13{
14 if (MHPath.length()>0) { 14 if (MHPath.length()>0) {
15 if (MHPath[MHPath.length()-1]=='/') { 15 if (MHPath[MHPath.length()-1]=='/') {
16 MHPath=MHPath.left(MHPath.length()-1); 16 MHPath=MHPath.left(MHPath.length()-1);
17 } 17 }
18 qDebug(MHPath); 18 qDebug(MHPath);
19 QDir dir(MHPath); 19 QDir dir(MHPath);
20 if (!dir.exists()) { 20 if (!dir.exists()) {
21 dir.mkdir(MHPath); 21 dir.mkdir(MHPath);
22 } 22 }
23 init_storage(); 23 init_storage();
24 } 24 }
25} 25}
26 26
27void MHwrapper::init_storage() 27void MHwrapper::init_storage()
28{ 28{
29 int r; 29 int r;
30 QString pre = MHPath; 30 QString pre = MHPath;
31 if (!m_storage) { 31 if (!m_storage) {
32 m_storage = mailstorage_new(NULL); 32 m_storage = mailstorage_new(NULL);
33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); 33 r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0);
34 if (r != MAIL_NO_ERROR) { 34 if (r != MAIL_NO_ERROR) {
35 qDebug("error initializing storage"); 35 qDebug("error initializing storage");
36 mailstorage_free(m_storage); 36 mailstorage_free(m_storage);
37 m_storage = 0; 37 m_storage = 0;
38 return; 38 return;
39 } 39 }
40 } 40 }
41 r = mailstorage_connect(m_storage); 41 r = mailstorage_connect(m_storage);
42 if (r!=MAIL_NO_ERROR) { 42 if (r!=MAIL_NO_ERROR) {
43 qDebug("error connecting storage"); 43 qDebug("error connecting storage");
44 mailstorage_free(m_storage); 44 mailstorage_free(m_storage);
45 m_storage = 0; 45 m_storage = 0;
46 } 46 }
47} 47}
48 48
49void MHwrapper::clean_storage() 49void MHwrapper::clean_storage()
50{ 50{
51 if (m_storage) { 51 if (m_storage) {
52 mailstorage_disconnect(m_storage); 52 mailstorage_disconnect(m_storage);
53 mailstorage_free(m_storage); 53 mailstorage_free(m_storage);
54 m_storage = 0; 54 m_storage = 0;
55 } 55 }
56} 56}
57 57
58MHwrapper::~MHwrapper() 58MHwrapper::~MHwrapper()
59{ 59{
60 clean_storage(); 60 clean_storage();
61} 61}
62 62
63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) 63void MHwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
64{ 64{
65 init_storage(); 65 init_storage();
66 if (!m_storage) { 66 if (!m_storage) {
67 return; 67 return;
68 } 68 }
69 QString f = buildPath(mailbox); 69 QString f = buildPath(mailbox);
70 int r = mailsession_select_folder(m_storage->sto_session,(char*)mailbox.latin1()); 70 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
71 if (r!=MAIL_NO_ERROR) { 71 if (r!=MAIL_NO_ERROR) {
72 qDebug("error selecting folder!"); 72 qDebug("listMessages: error selecting folder!");
73 return; 73 return;
74 } 74 }
75 parseList(target,m_storage->sto_session,f); 75 parseList(target,m_storage->sto_session,f);
76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count())); 76 Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(target.count()));
77} 77}
78 78
79QList<Folder>* MHwrapper::listFolders() 79QList<Folder>* MHwrapper::listFolders()
80{ 80{
81 QList<Folder> * folders = new QList<Folder>(); 81 QList<Folder> * folders = new QList<Folder>();
82 folders->setAutoDelete( false ); 82 folders->setAutoDelete( false );
83 init_storage(); 83 init_storage();
84 if (!m_storage) { 84 if (!m_storage) {
85 return folders; 85 return folders;
86 } 86 }
87 mail_list*flist = 0; 87 mail_list*flist = 0;
88 clistcell*current=0; 88 clistcell*current=0;
89 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); 89 int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist);
90 if (r != MAIL_NO_ERROR || !flist) { 90 if (r != MAIL_NO_ERROR || !flist) {
91 qDebug("error getting folder list"); 91 qDebug("error getting folder list");
92 return folders; 92 return folders;
93 } 93 }
94 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { 94 for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) {
95 QString t = (char*)current->data; 95 QString t = (char*)current->data;
96 t.replace(0,MHPath.length(),""); 96 t.replace(0,MHPath.length(),"");
97 folders->append(new MHFolder(t,MHPath)); 97 folders->append(new MHFolder(t,MHPath));
98 } 98 }
99 mail_list_free(flist); 99 mail_list_free(flist);
100 return folders; 100 return folders;
101} 101}
102 102
103void MHwrapper::deleteMail(const RecMail&mail) 103void MHwrapper::deleteMail(const RecMail&mail)
104{ 104{
105 init_storage(); 105 init_storage();
106 if (!m_storage) { 106 if (!m_storage) {
107 return; 107 return;
108 } 108 }
109 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 109 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
110 if (r!=MAIL_NO_ERROR) { 110 if (r!=MAIL_NO_ERROR) {
111 qDebug("error selecting folder!"); 111 qDebug("error selecting folder!");
112 return; 112 return;
113 } 113 }
114 r = mailsession_remove_message(m_storage->sto_session,mail.getNumber()); 114 r = mailsession_remove_message(m_storage->sto_session,mail.getNumber());
115 if (r != MAIL_NO_ERROR) { 115 if (r != MAIL_NO_ERROR) {
116 qDebug("error deleting mail"); 116 qDebug("error deleting mail");
117 } 117 }
118} 118}
119 119
120void MHwrapper::answeredMail(const RecMail&) 120void MHwrapper::answeredMail(const RecMail&)
121{ 121{
122} 122}
123 123
124RecBody MHwrapper::fetchBody( const RecMail &mail ) 124RecBody MHwrapper::fetchBody( const RecMail &mail )
125{ 125{
126 RecBody body; 126 RecBody body;
127 init_storage(); 127 init_storage();
128 if (!m_storage) { 128 if (!m_storage) {
129 return body; 129 return body;
130 } 130 }
131 mailmessage * msg; 131 mailmessage * msg;
132 char*data=0; 132 char*data=0;
133 size_t size; 133 size_t size;
134 134
135 /* mail should hold the complete path! */ 135 /* mail should hold the complete path! */
136 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 136 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
137 if (r != MAIL_NO_ERROR) { 137 if (r != MAIL_NO_ERROR) {
138 return body; 138 return body;
139 } 139 }
140 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); 140 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
141 if (r != MAIL_NO_ERROR) { 141 if (r != MAIL_NO_ERROR) {
142 qDebug("Error fetching mail %i",mail.getNumber()); 142 qDebug("Error fetching mail %i",mail.getNumber());
143 return body; 143 return body;
144 } 144 }
145 body = parseMail(msg); 145 body = parseMail(msg);
146 mailmessage_fetch_result_free(msg,data); 146 mailmessage_fetch_result_free(msg,data);
147 return body; 147 return body;
148} 148}
149 149
150void MHwrapper::mbox_progress( size_t current, size_t maximum ) 150void MHwrapper::mbox_progress( size_t current, size_t maximum )
151{ 151{
152 qDebug("MH %i von %i",current,maximum); 152 qDebug("MH %i von %i",current,maximum);
153} 153}
154 154
155QString MHwrapper::buildPath(const QString&p) 155QString MHwrapper::buildPath(const QString&p)
156{ 156{
157 QString f=""; 157 QString f="";
158 if (p.length()==0||p=="/") 158 if (p.length()==0||p=="/")
159 return MHPath; 159 return MHPath;
160 if (!p.startsWith(MHPath)) { 160 if (!p.startsWith(MHPath)) {
161 f+=MHPath; 161 f+=MHPath;
162 } 162 }
163 if (!p.startsWith("/")) { 163 if (!p.startsWith("/")) {
164 f+="/"; 164 f+="/";
165 } 165 }
166 f+=p; 166 f+=p;
167 return f; 167 return f;
168} 168}
169 169
170int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) 170int MHwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool )
171{ 171{
172 init_storage(); 172 init_storage();
173 if (!m_storage) { 173 if (!m_storage) {
174 return 0; 174 return 0;
175 } 175 }
176 QString f = buildPath(folder); 176 QString f = buildPath(folder);
177 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1()); 177 int r = mailsession_create_folder(m_storage->sto_session,(char*)f.latin1());
178 if (r != MAIL_NO_ERROR) { 178 if (r != MAIL_NO_ERROR) {
179 qDebug("error creating folder"); 179 qDebug("error creating folder");
180 return 0; 180 return 0;
181 } 181 }
182 qDebug("Folder created"); 182 qDebug("Folder created");
183 mailstorage_disconnect(m_storage); 183 mailstorage_disconnect(m_storage);
184 return 1; 184 return 1;
185} 185}
186 186
187void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) 187void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder)
188{ 188{
189 init_storage(); 189 init_storage();
190 if (!m_storage) { 190 if (!m_storage) {
191 return; 191 return;
192 } 192 }
193 QString f = buildPath(Folder); 193 QString f = buildPath(Folder);
194 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); 194 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
195 if (r!=MAIL_NO_ERROR) { 195 if (r!=MAIL_NO_ERROR) {
196 qDebug("error selecting folder!"); 196 qDebug("error selecting folder!");
197 return; 197 return;
198 } 198 }
199 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length); 199 r = mailsession_append_message(m_storage->sto_session,(char*)msg,length);
200 if (r!=MAIL_NO_ERROR) { 200 if (r!=MAIL_NO_ERROR) {
201 qDebug("error storing mail"); 201 qDebug("error storing mail");
202 } 202 }
203 return; 203 return;
204} 204}
205 205
206encodedString* MHwrapper::fetchRawBody(const RecMail&mail) 206encodedString* MHwrapper::fetchRawBody(const RecMail&mail)
207{ 207{
208 encodedString*result = 0; 208 encodedString*result = 0;
209 init_storage(); 209 init_storage();
210 if (!m_storage) { 210 if (!m_storage) {
211 return result; 211 return result;
212 } 212 }
213 mailmessage * msg = 0; 213 mailmessage * msg = 0;
214 char*data=0; 214 char*data=0;
215 size_t size; 215 size_t size;
216 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1()); 216 int r = mailsession_select_folder(m_storage->sto_session,(char*)mail.getMbox().latin1());
217 if (r!=MAIL_NO_ERROR) { 217 if (r!=MAIL_NO_ERROR) {
218 qDebug("error selecting folder!"); 218 qDebug("error selecting folder!");
219 return result; 219 return result;
220 } 220 }
221 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg); 221 r = mailsession_get_message(m_storage->sto_session, mail.getNumber(), &msg);
222 if (r != MAIL_NO_ERROR) { 222 if (r != MAIL_NO_ERROR) {
223 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 223 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
224 return 0; 224 return 0;
225 } 225 }
226 r = mailmessage_fetch(msg,&data,&size); 226 r = mailmessage_fetch(msg,&data,&size);
227 if (r != MAIL_NO_ERROR) { 227 if (r != MAIL_NO_ERROR) {
228 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); 228 Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber()));
229 if (msg) mailmessage_free(msg); 229 if (msg) mailmessage_free(msg);
230 return 0; 230 return 0;
231 } 231 }
232 result = new encodedString(data,size); 232 result = new encodedString(data,size);
233 if (msg) mailmessage_free(msg); 233 if (msg) mailmessage_free(msg);
234 return result; 234 return result;
235} 235}
236 236
237void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) 237void MHwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target)
238{ 238{
239#if 0 239 QString f = buildPath(mailbox);
240 QString p = MHPath+"/"; 240 int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1());
241 p+=mailbox; 241 if (r!=MAIL_NO_ERROR) {
242 mailmbox_folder*f = 0; 242 qDebug("deleteMails: error selecting folder!");
243 int r = mailmbox_init(p.latin1(),0,1,0,&f);
244 if (r != MAIL_NO_ERROR) {
245 qDebug("Error init folder");
246 return; 243 return;
247 } 244 }
248 deleteMails(f,target); 245 RecMail*c = 0;
249 mailmbox_done(f); 246 for (unsigned int i=0; i < target.count();++i) {
250#endif 247 c = target.at(i);
248 r = mailsession_remove_message(m_storage->sto_session,c->getNumber());
249 if (r != MAIL_NO_ERROR) {
250 qDebug("error deleting mail");
251 break;
252 }
253 }
251} 254}
252 255
253int MHwrapper::deleteAllMail(const Folder*tfolder) 256int MHwrapper::deleteAllMail(const Folder*tfolder)
254{ 257{
255 init_storage(); 258 init_storage();
256 if (!m_storage) { 259 if (!m_storage) {
257 return 0; 260 return 0;
258 } 261 }
259 int res = 1; 262 int res = 1;
260 if (!tfolder) return 0; 263 if (!tfolder) return 0;
261 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 264 int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
262 if (r!=MAIL_NO_ERROR) { 265 if (r!=MAIL_NO_ERROR) {
263 qDebug("error selecting folder!"); 266 qDebug("error selecting folder!");
264 return 0; 267 return 0;
265 } 268 }
266 mailmessage_list*l=0; 269 mailmessage_list*l=0;
267 r = mailsession_get_messages_list(m_storage->sto_session,&l); 270 r = mailsession_get_messages_list(m_storage->sto_session,&l);
268 if (r != MAIL_NO_ERROR) { 271 if (r != MAIL_NO_ERROR) {
269 qDebug("Error message list"); 272 qDebug("Error message list");
270 res = 0; 273 res = 0;
271 } 274 }
272 unsigned j = 0; 275 unsigned j = 0;
273 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { 276 for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) {
274 mailmessage * msg; 277 mailmessage * msg;
275 msg = (mailmessage*)carray_get(l->msg_tab, i); 278 msg = (mailmessage*)carray_get(l->msg_tab, i);
276 j = msg->msg_index; 279 j = msg->msg_index;
277 r = mailsession_remove_message(m_storage->sto_session,j); 280 r = mailsession_remove_message(m_storage->sto_session,j);
278 if (r != MAIL_NO_ERROR) { 281 if (r != MAIL_NO_ERROR) {
279 Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); 282 Global::statusMessage(tr("Error deleting mail %1").arg(i+1));
280 res = 0; 283 res = 0;
281 break; 284 break;
282 } 285 }
283 } 286 }
284 if (l) mailmessage_list_free(l); 287 if (l) mailmessage_list_free(l);
285 return res; 288 return res;
286} 289}
287 290
288int MHwrapper::deleteMbox(const Folder*tfolder) 291int MHwrapper::deleteMbox(const Folder*tfolder)
289{ 292{
290 init_storage(); 293 init_storage();
291 if (!m_storage) { 294 if (!m_storage) {
292 return 0; 295 return 0;
293 } 296 }
294 if (!tfolder) return 0; 297 if (!tfolder) return 0;
295 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); 298 int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1());
296 if (r != MAIL_NO_ERROR) { 299 if (r != MAIL_NO_ERROR) {
297 qDebug("error deleting mail box"); 300 qDebug("error deleting mail box");
298 return 0; 301 return 0;
299 } 302 }
300 qDebug("mail box deleted"); 303 qDebug("mail box deleted");
301 mailstorage_disconnect(m_storage); 304 mailstorage_disconnect(m_storage);
302 return 1; 305 return 1;
303} 306}
304 307
305void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) 308void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox)
306{ 309{
307 init_storage(); 310 init_storage();
308 if (!m_storage) { 311 if (!m_storage) {
309 return; 312 return;
310 } 313 }
311 target_stat.message_count = 0; 314 target_stat.message_count = 0;
312 target_stat.message_unseen = 0; 315 target_stat.message_unseen = 0;
313 target_stat.message_recent = 0; 316 target_stat.message_recent = 0;
314 QString f = buildPath(mailbox); 317 QString f = buildPath(mailbox);
315 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,
316 &target_stat.message_recent,&target_stat.message_unseen); 319 &target_stat.message_recent,&target_stat.message_unseen);
317 if (r != MAIL_NO_ERROR) { 320 if (r != MAIL_NO_ERROR) {
318 Global::statusMessage(tr("Error retrieving status")); 321 Global::statusMessage(tr("Error retrieving status"));
319 } 322 }
320} 323}
321 324
322const QString&MHwrapper::getType()const 325const QString&MHwrapper::getType()const
323{ 326{
324 return wrapperType; 327 return wrapperType;
325} 328}
326 329
327const QString&MHwrapper::getName()const 330const QString&MHwrapper::getName()const
328{ 331{
329 return MHName; 332 return MHName;
330} 333}