Diffstat (limited to 'kmicromail/libmailwrapper/mboxwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/mboxwrapper.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/mboxwrapper.cpp b/kmicromail/libmailwrapper/mboxwrapper.cpp index 87f8c8a..888cae2 100644 --- a/kmicromail/libmailwrapper/mboxwrapper.cpp +++ b/kmicromail/libmailwrapper/mboxwrapper.cpp | |||
@@ -1,85 +1,87 @@ | |||
1 | #include "mboxwrapper.h" | 1 | #include "mboxwrapper.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 | //Added by qt3to4: | ||
7 | #include <Q3ValueList> | ||
6 | #include <stdlib.h> | 8 | #include <stdlib.h> |
7 | #include <klocale.h> | 9 | #include <klocale.h> |
8 | 10 | ||
9 | 11 | ||
10 | #include <qpe/global.h> | 12 | #include <qpe/global.h> |
11 | 13 | ||
12 | using namespace Opie::Core; | 14 | using namespace Opie::Core; |
13 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) | 15 | MBOXwrapper::MBOXwrapper(const QString & mbox_dir,const QString&mbox_name) |
14 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) | 16 | : Genericwrapper(),MBOXPath(mbox_dir),MBOXName(mbox_name) |
15 | { | 17 | { |
16 | QDir dir(MBOXPath); | 18 | QDir dir(MBOXPath); |
17 | if (!dir.exists()) { | 19 | if (!dir.exists()) { |
18 | dir.mkdir(MBOXPath); | 20 | dir.mkdir(MBOXPath); |
19 | } | 21 | } |
20 | } | 22 | } |
21 | 23 | ||
22 | MBOXwrapper::~MBOXwrapper() | 24 | MBOXwrapper::~MBOXwrapper() |
23 | { | 25 | { |
24 | } | 26 | } |
25 | 27 | ||
26 | void MBOXwrapper::listMessages(const QString & mailbox, QValueList<RecMailP> &target ) | 28 | void MBOXwrapper::listMessages(const QString & mailbox, Q3ValueList<RecMailP> &target ) |
27 | { | 29 | { |
28 | mailstorage*storage = mailstorage_new(NULL); | 30 | mailstorage*storage = mailstorage_new(NULL); |
29 | QString p = MBOXPath+"/"; | 31 | QString p = MBOXPath+"/"; |
30 | p+=mailbox; | 32 | p+=mailbox; |
31 | 33 | ||
32 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 34 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
33 | mailfolder*folder; | 35 | mailfolder*folder; |
34 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 36 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
35 | r = mailfolder_connect(folder); | 37 | r = mailfolder_connect(folder); |
36 | if (r != MAIL_NO_ERROR) { | 38 | if (r != MAIL_NO_ERROR) { |
37 | //odebug << "Error initializing mbox" << oendl; | 39 | //odebug << "Error initializing mbox" << oendl; |
38 | mailfolder_free(folder); | 40 | mailfolder_free(folder); |
39 | mailstorage_free(storage); | 41 | mailstorage_free(storage); |
40 | return; | 42 | return; |
41 | } | 43 | } |
42 | 44 | ||
43 | parseList(target,folder->fld_session,mailbox); | 45 | parseList(target,folder->fld_session,mailbox); |
44 | 46 | ||
45 | mailfolder_disconnect(folder); | 47 | mailfolder_disconnect(folder); |
46 | mailfolder_free(folder); | 48 | mailfolder_free(folder); |
47 | mailstorage_free(storage); | 49 | mailstorage_free(storage); |
48 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); | 50 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); |
49 | } | 51 | } |
50 | 52 | ||
51 | QValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() | 53 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* MBOXwrapper::listFolders() |
52 | { | 54 | { |
53 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 55 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >(); |
54 | QDir dir(MBOXPath); | 56 | QDir dir(MBOXPath); |
55 | if (!dir.exists()) return folders; | 57 | if (!dir.exists()) return folders; |
56 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); | 58 | dir.setFilter(QDir::Files|QDir::Writable|QDir::Readable); |
57 | QStringList entries = dir.entryList(); | 59 | QStringList entries = dir.entryList(); |
58 | QStringList::ConstIterator it = entries.begin(); | 60 | QStringList::ConstIterator it = entries.begin(); |
59 | for (;it!=entries.end();++it) { | 61 | for (;it!=entries.end();++it) { |
60 | FolderP inb=new Folder(*it,"/"); | 62 | FolderP inb=new Folder(*it,"/"); |
61 | folders->append(inb); | 63 | folders->append(inb); |
62 | } | 64 | } |
63 | return folders; | 65 | return folders; |
64 | } | 66 | } |
65 | 67 | ||
66 | void MBOXwrapper::deleteMail(const RecMailP & mail) | 68 | void MBOXwrapper::deleteMail(const RecMailP & mail) |
67 | { | 69 | { |
68 | mailstorage*storage = mailstorage_new(NULL); | 70 | mailstorage*storage = mailstorage_new(NULL); |
69 | QString p = MBOXPath+"/"; | 71 | QString p = MBOXPath+"/"; |
70 | p+=mail->getMbox(); | 72 | p+=mail->getMbox(); |
71 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 73 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
72 | mailfolder*folder; | 74 | mailfolder*folder; |
73 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 75 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
74 | r = mailfolder_connect(folder); | 76 | r = mailfolder_connect(folder); |
75 | if (r != MAIL_NO_ERROR) { | 77 | if (r != MAIL_NO_ERROR) { |
76 | ; // << "Error initializing mbox" << oendl; | 78 | ; // << "Error initializing mbox" << oendl; |
77 | mailfolder_free(folder); | 79 | mailfolder_free(folder); |
78 | mailstorage_free(storage); | 80 | mailstorage_free(storage); |
79 | return; | 81 | return; |
80 | } | 82 | } |
81 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); | 83 | r = mailsession_remove_message(folder->fld_session,mail->getNumber()); |
82 | if (r != MAIL_NO_ERROR) { | 84 | if (r != MAIL_NO_ERROR) { |
83 | ; // << "error deleting mail" << oendl; | 85 | ; // << "error deleting mail" << oendl; |
84 | } | 86 | } |
85 | mailfolder_free(folder); | 87 | mailfolder_free(folder); |
@@ -188,83 +190,83 @@ encodedString* MBOXwrapper::fetchRawBody(const RecMailP&mail) | |||
188 | mailfolder*folder; | 190 | mailfolder*folder; |
189 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 191 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
190 | r = mailfolder_connect(folder); | 192 | r = mailfolder_connect(folder); |
191 | if (r != MAIL_NO_ERROR) { | 193 | if (r != MAIL_NO_ERROR) { |
192 | Global::statusMessage(i18n("Error initializing mbox")); | 194 | Global::statusMessage(i18n("Error initializing mbox")); |
193 | mailfolder_free(folder); | 195 | mailfolder_free(folder); |
194 | mailstorage_free(storage); | 196 | mailstorage_free(storage); |
195 | return 0; | 197 | return 0; |
196 | } | 198 | } |
197 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); | 199 | r = mailsession_get_message(folder->fld_session, mail->getNumber(), &msg); |
198 | if (r != MAIL_NO_ERROR) { | 200 | if (r != MAIL_NO_ERROR) { |
199 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 201 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
200 | mailfolder_free(folder); | 202 | mailfolder_free(folder); |
201 | mailstorage_free(storage); | 203 | mailstorage_free(storage); |
202 | return 0; | 204 | return 0; |
203 | } | 205 | } |
204 | r = mailmessage_fetch(msg,&data,&size); | 206 | r = mailmessage_fetch(msg,&data,&size); |
205 | if (r != MAIL_NO_ERROR) { | 207 | if (r != MAIL_NO_ERROR) { |
206 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 208 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
207 | mailfolder_free(folder); | 209 | mailfolder_free(folder); |
208 | mailstorage_free(storage); | 210 | mailstorage_free(storage); |
209 | mailmessage_free(msg); | 211 | mailmessage_free(msg); |
210 | return 0; | 212 | return 0; |
211 | } | 213 | } |
212 | encodedString*result = new encodedString(data,size); | 214 | encodedString*result = new encodedString(data,size); |
213 | 215 | ||
214 | mailfolder_free(folder); | 216 | mailfolder_free(folder); |
215 | mailstorage_free(storage); | 217 | mailstorage_free(storage); |
216 | mailmessage_free(msg); | 218 | mailmessage_free(msg); |
217 | return result; | 219 | return result; |
218 | } | 220 | } |
219 | 221 | ||
220 | void MBOXwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 222 | void MBOXwrapper::deleteMails(const QString & mailbox,const Q3ValueList<RecMailP> &target) |
221 | { | 223 | { |
222 | QString p = MBOXPath+"/"; | 224 | QString p = MBOXPath+"/"; |
223 | p+=mailbox; | 225 | p+=mailbox; |
224 | mailmbox_folder*f = 0; | 226 | mailmbox_folder*f = 0; |
225 | int r = mailmbox_init(p.latin1(),0,1,0,&f); | 227 | int r = mailmbox_init(p.latin1(),0,1,0,&f); |
226 | if (r != MAIL_NO_ERROR) { | 228 | if (r != MAIL_NO_ERROR) { |
227 | ; // << "Error init folder" << oendl; | 229 | ; // << "Error init folder" << oendl; |
228 | return; | 230 | return; |
229 | } | 231 | } |
230 | deleteMails(f,target); | 232 | deleteMails(f,target); |
231 | mailmbox_done(f); | 233 | mailmbox_done(f); |
232 | } | 234 | } |
233 | 235 | ||
234 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const QValueList<RecMailP> &target) | 236 | void MBOXwrapper::deleteMails(mailmbox_folder*f,const Q3ValueList<RecMailP> &target) |
235 | { | 237 | { |
236 | if (!f) return; | 238 | if (!f) return; |
237 | int r; | 239 | int r; |
238 | QValueList<RecMailP>::ConstIterator it; | 240 | Q3ValueList<RecMailP>::ConstIterator it; |
239 | for (it=target.begin(); it != target.end();++it) { | 241 | for (it=target.begin(); it != target.end();++it) { |
240 | r = mailmbox_delete_msg(f,(*it)->getNumber()); | 242 | r = mailmbox_delete_msg(f,(*it)->getNumber()); |
241 | if (r!=MAILMBOX_NO_ERROR) { | 243 | if (r!=MAILMBOX_NO_ERROR) { |
242 | ; // << "error delete mail" << oendl; | 244 | ; // << "error delete mail" << oendl; |
243 | } | 245 | } |
244 | } | 246 | } |
245 | r = mailmbox_expunge(f); | 247 | r = mailmbox_expunge(f); |
246 | if (r != MAILMBOX_NO_ERROR) { | 248 | if (r != MAILMBOX_NO_ERROR) { |
247 | ; // << "error expunge mailbox" << oendl; | 249 | ; // << "error expunge mailbox" << oendl; |
248 | } | 250 | } |
249 | } | 251 | } |
250 | 252 | ||
251 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) | 253 | int MBOXwrapper::deleteAllMail(const FolderP&tfolder) |
252 | { | 254 | { |
253 | if (!tfolder) return 0; | 255 | if (!tfolder) return 0; |
254 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); | 256 | QString p = MBOXPath+"/"+tfolder->getDisplayName(); |
255 | int res = 1; | 257 | int res = 1; |
256 | 258 | ||
257 | mailfolder*folder = 0; | 259 | mailfolder*folder = 0; |
258 | mailmessage_list*l=0; | 260 | mailmessage_list*l=0; |
259 | mailstorage*storage = mailstorage_new(NULL); | 261 | mailstorage*storage = mailstorage_new(NULL); |
260 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); | 262 | int r = mbox_mailstorage_init(storage,(char*)p.latin1(),0,0,0); |
261 | if (r != MAIL_NO_ERROR) { | 263 | if (r != MAIL_NO_ERROR) { |
262 | Global::statusMessage(i18n("Error initializing mbox")); | 264 | Global::statusMessage(i18n("Error initializing mbox")); |
263 | res = 0; | 265 | res = 0; |
264 | } | 266 | } |
265 | if (res) { | 267 | if (res) { |
266 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); | 268 | folder = mailfolder_new( storage,(char*)p.latin1(),NULL); |
267 | r = mailfolder_connect(folder); | 269 | r = mailfolder_connect(folder); |
268 | if (r != MAIL_NO_ERROR) { | 270 | if (r != MAIL_NO_ERROR) { |
269 | Global::statusMessage(i18n("Error initializing mbox")); | 271 | Global::statusMessage(i18n("Error initializing mbox")); |
270 | res = 0; | 272 | res = 0; |