author | alwin <alwin> | 2003-12-28 02:45:07 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-28 02:45:07 (UTC) |
commit | d1a7eb08cad465c5fc0de53f75aaecf7803f0945 (patch) (unidiff) | |
tree | 422b73af760cdd44e4fbbc96bd6876a15939ff19 /noncore/net/mail/mboxwrapper.cpp | |
parent | e889485e945d8fa9564566f286114be10d2a1ce5 (diff) | |
download | opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.zip opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.tar.gz opie-d1a7eb08cad465c5fc0de53f75aaecf7803f0945.tar.bz2 |
- dir handling for mbox accounts (delete, new, delete all mail)
- fixed memory leaks in mbox account class
- reduced count of used string constants while using "tr" with context string
- mbox displays messages into global status bar
- fixed a possible raise condition when deleting a mail directory
Diffstat (limited to 'noncore/net/mail/mboxwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 126 |
1 files changed, 100 insertions, 26 deletions
diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 6d69263..162a0c9 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp | |||
@@ -3,7 +3,7 @@ | |||
3 | #include "mailwrapper.h" | 3 | #include "mailwrapper.h" |
4 | #include <libetpan/libetpan.h> | 4 | #include <libetpan/libetpan.h> |
5 | #include <libetpan/mailstorage.h> | ||
6 | #include <qdir.h> | 5 | #include <qdir.h> |
7 | #include <stdlib.h> | 6 | #include <stdlib.h> |
7 | #include <qpe/global.h> | ||
8 | 8 | ||
9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) | 9 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir) |
@@ -25,11 +25,8 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
25 | QString p = MBOXPath+"/"; | 25 | QString p = MBOXPath+"/"; |
26 | p+=mailbox; | 26 | p+=mailbox; |
27 | char*fname = 0; | 27 | |
28 | 28 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | |
29 | fname = strdup(p.latin1()); | ||
30 | |||
31 | int r = mbox_mailstorage_init(storage,fname,0,0,0); | ||
32 | mailfolder*folder; | 29 | mailfolder*folder; |
33 | folder = mailfolder_new( storage,fname,NULL); | 30 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
34 | r = mailfolder_connect(folder); | 31 | r = mailfolder_connect(folder); |
35 | if (r != MAIL_NO_ERROR) { | 32 | if (r != MAIL_NO_ERROR) { |
@@ -37,5 +34,4 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
37 | mailfolder_free(folder); | 34 | mailfolder_free(folder); |
38 | mailstorage_free(storage); | 35 | mailstorage_free(storage); |
39 | free(fname); | ||
40 | return; | 36 | return; |
41 | } | 37 | } |
@@ -46,5 +42,4 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
46 | mailfolder_free(folder); | 42 | mailfolder_free(folder); |
47 | mailstorage_free(storage); | 43 | mailstorage_free(storage); |
48 | free(fname); | ||
49 | return; | 44 | return; |
50 | } | 45 | } |
@@ -57,10 +52,10 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
57 | mailfolder_free(folder); | 52 | mailfolder_free(folder); |
58 | mailstorage_free(storage); | 53 | mailstorage_free(storage); |
59 | free(fname); | ||
60 | return; | 54 | return; |
61 | } | 55 | } |
62 | mailimf_references * refs; | 56 | mailimf_references * refs; |
63 | 57 | ||
64 | for(int i = 0 ; i < carray_count(env_list->msg_tab) ; ++i) { | 58 | uint32_t i = 0; |
59 | for(; i < carray_count(env_list->msg_tab) ; ++i) { | ||
65 | mailmessage * msg; | 60 | mailmessage * msg; |
66 | QBitArray mFlags(7); | 61 | QBitArray mFlags(7); |
@@ -111,5 +106,5 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) | |||
111 | mailfolder_free(folder); | 106 | mailfolder_free(folder); |
112 | mailstorage_free(storage); | 107 | mailstorage_free(storage); |
113 | free(fname); | 108 | Global::statusMessage(tr("Mailbox has %1 mail(s)").arg(i)); |
114 | } | 109 | } |
115 | 110 | ||
@@ -135,8 +130,7 @@ void MBOXwrapper::deleteMail(const RecMail&mail) | |||
135 | QString p = MBOXPath+"/"; | 130 | QString p = MBOXPath+"/"; |
136 | p+=mail.getMbox(); | 131 | p+=mail.getMbox(); |
137 | mailmessage * msg; | 132 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
138 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | ||
139 | mailfolder*folder; | 133 | mailfolder*folder; |
140 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 134 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
141 | r = mailfolder_connect(folder); | 135 | r = mailfolder_connect(folder); |
142 | if (r != MAIL_NO_ERROR) { | 136 | if (r != MAIL_NO_ERROR) { |
@@ -168,7 +162,7 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail ) | |||
168 | size_t size; | 162 | size_t size; |
169 | 163 | ||
170 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 164 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
171 | mailfolder*folder; | 165 | mailfolder*folder; |
172 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 166 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
173 | r = mailfolder_connect(folder); | 167 | r = mailfolder_connect(folder); |
174 | if (r != MAIL_NO_ERROR) { | 168 | if (r != MAIL_NO_ERROR) { |
@@ -206,6 +200,20 @@ void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) | |||
206 | } | 200 | } |
207 | 201 | ||
208 | void MBOXwrapper::createFolder(const QString&) | 202 | int MBOXwrapper::createMbox(const QString&folder,const Folder*,const QString&,bool ) |
209 | { | 203 | { |
204 | QString p = MBOXPath+"/"; | ||
205 | p+=folder; | ||
206 | QFileInfo fi(p); | ||
207 | if (fi.exists()) { | ||
208 | Global::statusMessage(tr("Mailbox exists.")); | ||
209 | return 0; | ||
210 | } | ||
211 | mailmbox_folder*f = 0; | ||
212 | if (mailmbox_init(p.latin1(),0,1,0,&f) != MAIL_NO_ERROR) { | ||
213 | Global::statusMessage(tr("Error init folder")); | ||
214 | return 0; | ||
215 | } | ||
216 | if (f) mailmbox_done(f); | ||
217 | return 1; | ||
210 | } | 218 | } |
211 | 219 | ||
@@ -217,10 +225,10 @@ void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folde | |||
217 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 225 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
218 | if (r != MAIL_NO_ERROR) { | 226 | if (r != MAIL_NO_ERROR) { |
219 | qDebug("Error init folder"); | 227 | Global::statusMessage(tr("Error init folder")); |
220 | return; | 228 | return; |
221 | } | 229 | } |
222 | r = mailmbox_append_message(f,msg,length); | 230 | r = mailmbox_append_message(f,msg,length); |
223 | if (r != MAIL_NO_ERROR) { | 231 | if (r != MAIL_NO_ERROR) { |
224 | qDebug("Error writing message folder"); | 232 | Global::statusMessage(tr("Error writing to message folder")); |
225 | } | 233 | } |
226 | mailmbox_done(f); | 234 | mailmbox_done(f); |
@@ -237,10 +245,10 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | |||
237 | size_t size; | 245 | size_t size; |
238 | 246 | ||
239 | int r = mbox_mailstorage_init(storage,strdup(p.latin1()),0,0,0); | 247 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
240 | mailfolder*folder; | 248 | mailfolder*folder; |
241 | folder = mailfolder_new( storage,strdup(p.latin1()),NULL); | 249 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
242 | r = mailfolder_connect(folder); | 250 | r = mailfolder_connect(folder); |
243 | if (r != MAIL_NO_ERROR) { | 251 | if (r != MAIL_NO_ERROR) { |
244 | qDebug("Error initializing mbox"); | 252 | Global::statusMessage(tr("Error initializing mbox")); |
245 | mailfolder_free(folder); | 253 | mailfolder_free(folder); |
246 | mailstorage_free(storage); | 254 | mailstorage_free(storage); |
@@ -249,5 +257,5 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | |||
249 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); | 257 | r = mailsession_get_message(folder->fld_session, mail.getNumber(), &msg); |
250 | if (r != MAIL_NO_ERROR) { | 258 | if (r != MAIL_NO_ERROR) { |
251 | qDebug("Error fetching mail %i",mail.getNumber()); | 259 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
252 | mailfolder_free(folder); | 260 | mailfolder_free(folder); |
253 | mailstorage_free(storage); | 261 | mailstorage_free(storage); |
@@ -256,5 +264,5 @@ void MBOXwrapper::fetchRawBody(const RecMail&mail,char**target,size_t*length) | |||
256 | r = mailmessage_fetch(msg,&data,&size); | 264 | r = mailmessage_fetch(msg,&data,&size); |
257 | if (r != MAIL_NO_ERROR) { | 265 | if (r != MAIL_NO_ERROR) { |
258 | qDebug("Error fetching mail %i",mail.getNumber()); | 266 | Global::statusMessage(tr("Error fetching mail %i").arg(mail.getNumber())); |
259 | mailfolder_free(folder); | 267 | mailfolder_free(folder); |
260 | mailstorage_free(storage); | 268 | mailstorage_free(storage); |
@@ -279,4 +287,12 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | |||
279 | return; | 287 | return; |
280 | } | 288 | } |
289 | deleteMails(f,target); | ||
290 | mailmbox_done(f); | ||
291 | } | ||
292 | |||
293 | void MBOXwrapper::deleteMails(mailmbox_folder*f,QList<RecMail> &target) | ||
294 | { | ||
295 | if (!f) return; | ||
296 | int r; | ||
281 | for (unsigned int i=0; i < target.count();++i) { | 297 | for (unsigned int i=0; i < target.count();++i) { |
282 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); | 298 | r = mailmbox_delete_msg(f,target.at(i)->getNumber()); |
@@ -289,5 +305,63 @@ void MBOXwrapper::deleteMails(const QString & mailbox,QList<RecMail> &target) | |||
289 | qDebug("error expunge mailbox"); | 305 | qDebug("error expunge mailbox"); |
290 | } | 306 | } |
291 | mailmbox_done(f); | 307 | } |
308 | |||
309 | int MBOXwrapper::deleteAllMail(const Folder*tfolder) | ||
310 | { | ||
311 | if (!tfolder) return 0; | ||
312 | QString p = MBOXPath+tfolder->getDisplayName(); | ||
313 | int res = 1; | ||
314 | |||
315 | mailfolder*folder = 0; | ||
316 | mailmessage_list*l=0; | ||
317 | mailstorage*storage = mailstorage_new(NULL); | ||
318 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | ||
319 | if (r != MAIL_NO_ERROR) { | ||
320 | Global::statusMessage(tr("Error initializing mbox")); | ||
321 | res = 0; | ||
322 | } | ||
323 | if (res) { | ||
324 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | ||
325 | r = mailfolder_connect(folder); | ||
326 | if (r != MAIL_NO_ERROR) { | ||
327 | Global::statusMessage(tr("Error initializing mbox")); | ||
328 | res = 0; | ||
329 | } | ||
330 | } | ||
331 | if (res) { | ||
332 | r = mailsession_get_messages_list(folder->fld_session,&l); | ||
333 | if (r != MAIL_NO_ERROR) { | ||
334 | qDebug("Error message list"); | ||
335 | res=0; | ||
336 | } | ||
337 | } | ||
338 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | ||
339 | r = mailsession_remove_message(folder->fld_session,i+1); | ||
340 | if (r != MAIL_NO_ERROR) { | ||
341 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | ||
342 | res = 0; | ||
343 | break; | ||
344 | } | ||
345 | } | ||
346 | if (l) mailmessage_list_free(l); | ||
347 | if (folder) mailfolder_free(folder); | ||
348 | if (storage) mailstorage_free(storage); | ||
349 | return res; | ||
350 | } | ||
351 | |||
352 | int MBOXwrapper::deleteMbox(const Folder*tfolder) | ||
353 | { | ||
354 | if (!tfolder) return 0; | ||
355 | QString p = MBOXPath+tfolder->getDisplayName(); | ||
356 | QFile fi(p); | ||
357 | if (!fi.exists()) { | ||
358 | Global::statusMessage(tr("Mailbox doesn't exist.")); | ||
359 | return 0; | ||
360 | } | ||
361 | if (!fi.remove()) { | ||
362 | Global::statusMessage(tr("Error deleting Mailbox.")); | ||
363 | return 0; | ||
364 | } | ||
365 | return 1; | ||
292 | } | 366 | } |
293 | 367 | ||