Diffstat (limited to 'kmicromail/libmailwrapper/mhwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/mhwrapper.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/mhwrapper.cpp b/kmicromail/libmailwrapper/mhwrapper.cpp index 787e85d..4cd7a94 100644 --- a/kmicromail/libmailwrapper/mhwrapper.cpp +++ b/kmicromail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,117 +1,119 @@ | |||
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 | //Added by qt3to4: | ||
9 | #include <Q3ValueList> | ||
8 | #include <stdlib.h> | 10 | #include <stdlib.h> |
9 | #include <qpe/global.h> | 11 | #include <qpe/global.h> |
10 | #include <klocale.h> | 12 | #include <klocale.h> |
11 | #include <kglobal.h> | 13 | #include <kglobal.h> |
12 | //#include <opie2/odebug.h> | 14 | //#include <opie2/odebug.h> |
13 | 15 | ||
14 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
15 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 17 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
16 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 18 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
17 | { | 19 | { |
18 | if (MHPath.length()>0) { | 20 | if (MHPath.length()>0) { |
19 | if (MHPath[MHPath.length()-1]=='/') { | 21 | if (MHPath[MHPath.length()-1]=='/') { |
20 | MHPath=MHPath.left(MHPath.length()-1); | 22 | MHPath=MHPath.left(MHPath.length()-1); |
21 | } | 23 | } |
22 | //odebug << MHPath << oendl; | 24 | //odebug << MHPath << oendl; |
23 | QDir dir(MHPath); | 25 | QDir dir(MHPath); |
24 | if (!dir.exists()) { | 26 | if (!dir.exists()) { |
25 | dir.mkdir(MHPath); | 27 | dir.mkdir(MHPath); |
26 | } | 28 | } |
27 | init_storage(); | 29 | init_storage(); |
28 | } | 30 | } |
29 | } | 31 | } |
30 | 32 | ||
31 | void MHwrapper::init_storage() | 33 | void MHwrapper::init_storage() |
32 | { | 34 | { |
33 | int r; | 35 | int r; |
34 | QString pre = MHPath; | 36 | QString pre = MHPath; |
35 | if (!m_storage) { | 37 | if (!m_storage) { |
36 | m_storage = mailstorage_new(NULL); | 38 | m_storage = mailstorage_new(NULL); |
37 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 39 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
38 | if (r != MAIL_NO_ERROR) { | 40 | if (r != MAIL_NO_ERROR) { |
39 | qDebug(" error init storage "); | 41 | qDebug(" error init storage "); |
40 | mailstorage_free(m_storage); | 42 | mailstorage_free(m_storage); |
41 | m_storage = 0; | 43 | m_storage = 0; |
42 | return; | 44 | return; |
43 | } | 45 | } |
44 | } | 46 | } |
45 | r = mailstorage_connect(m_storage); | 47 | r = mailstorage_connect(m_storage); |
46 | if (r!=MAIL_NO_ERROR) { | 48 | if (r!=MAIL_NO_ERROR) { |
47 | qDebug("error connecting storage "); | 49 | qDebug("error connecting storage "); |
48 | mailstorage_free(m_storage); | 50 | mailstorage_free(m_storage); |
49 | m_storage = 0; | 51 | m_storage = 0; |
50 | } | 52 | } |
51 | } | 53 | } |
52 | 54 | ||
53 | void MHwrapper::clean_storage() | 55 | void MHwrapper::clean_storage() |
54 | { | 56 | { |
55 | if (m_storage) { | 57 | if (m_storage) { |
56 | mailstorage_disconnect(m_storage); | 58 | mailstorage_disconnect(m_storage); |
57 | mailstorage_free(m_storage); | 59 | mailstorage_free(m_storage); |
58 | m_storage = 0; | 60 | m_storage = 0; |
59 | } | 61 | } |
60 | } | 62 | } |
61 | 63 | ||
62 | MHwrapper::~MHwrapper() | 64 | MHwrapper::~MHwrapper() |
63 | { | 65 | { |
64 | clean_storage(); | 66 | clean_storage(); |
65 | } | 67 | } |
66 | 68 | ||
67 | void MHwrapper::listMessages(const QString & mailbox, QValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) | 69 | void MHwrapper::listMessages(const QString & mailbox, Q3ValueList<Opie::Core::OSmartPointer<RecMail> > &target, int maxSizeInKb ) |
68 | { | 70 | { |
69 | init_storage(); | 71 | init_storage(); |
70 | if (!m_storage) { | 72 | if (!m_storage) { |
71 | return; | 73 | return; |
72 | } | 74 | } |
73 | QString f = buildPath(mailbox); | 75 | QString f = buildPath(mailbox); |
74 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 76 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
75 | if (r!=MAIL_NO_ERROR) { | 77 | if (r!=MAIL_NO_ERROR) { |
76 | qDebug("listMessages: error selecting folder! "); | 78 | qDebug("listMessages: error selecting folder! "); |
77 | return; | 79 | return; |
78 | } | 80 | } |
79 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); | 81 | parseList(target,m_storage->sto_session,f, false, maxSizeInKb ); |
80 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); | 82 | Global::statusMessage(i18n("Mailbox has %1 mail(s)").arg(target.count())); |
81 | } | 83 | } |
82 | 84 | ||
83 | QValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() | 85 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* MHwrapper::listFolders() |
84 | { | 86 | { |
85 | QValueList<Opie::Core::OSmartPointer<Folder> >* folders = new QValueList<Opie::Core::OSmartPointer<Folder> >(); | 87 | Q3ValueList<Opie::Core::OSmartPointer<Folder> >* folders = new Q3ValueList<Opie::Core::OSmartPointer<Folder> >(); |
86 | /* this is needed! */ | 88 | /* this is needed! */ |
87 | if (m_storage) mailstorage_disconnect(m_storage); | 89 | if (m_storage) mailstorage_disconnect(m_storage); |
88 | init_storage(); | 90 | init_storage(); |
89 | if (!m_storage) { | 91 | if (!m_storage) { |
90 | return folders; | 92 | return folders; |
91 | } | 93 | } |
92 | mail_list*flist = 0; | 94 | mail_list*flist = 0; |
93 | clistcell*current=0; | 95 | clistcell*current=0; |
94 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); | 96 | int r = mailsession_list_folders(m_storage->sto_session,NULL,&flist); |
95 | if (r != MAIL_NO_ERROR || !flist) { | 97 | if (r != MAIL_NO_ERROR || !flist) { |
96 | qDebug("error getting folder list "); | 98 | qDebug("error getting folder list "); |
97 | return folders; | 99 | return folders; |
98 | } | 100 | } |
99 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { | 101 | for (current=clist_begin(flist->mb_list);current!=0;current=clist_next(current)) { |
100 | QString t = (char*)current->data; | 102 | QString t = (char*)current->data; |
101 | t.replace(0,MHPath.length(),""); | 103 | t.replace(0,MHPath.length(),""); |
102 | folders->append(new MHFolder(t,MHPath)); | 104 | folders->append(new MHFolder(t,MHPath)); |
103 | } | 105 | } |
104 | mail_list_free(flist); | 106 | mail_list_free(flist); |
105 | return folders; | 107 | return folders; |
106 | } | 108 | } |
107 | 109 | ||
108 | void MHwrapper::deleteMail(const RecMailP&mail) | 110 | void MHwrapper::deleteMail(const RecMailP&mail) |
109 | { | 111 | { |
110 | init_storage(); | 112 | init_storage(); |
111 | if (!m_storage) { | 113 | if (!m_storage) { |
112 | return; | 114 | return; |
113 | } | 115 | } |
114 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 116 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
115 | if (r!=MAIL_NO_ERROR) { | 117 | if (r!=MAIL_NO_ERROR) { |
116 | qDebug("error selecting folder! "); | 118 | qDebug("error selecting folder! "); |
117 | return; | 119 | return; |
@@ -226,73 +228,73 @@ void MHwrapper::storeMessage(const char*msg,size_t length, const QString&Folder) | |||
226 | 228 | ||
227 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) | 229 | encodedString* MHwrapper::fetchRawBody(const RecMailP&mail) |
228 | { | 230 | { |
229 | encodedString*result = 0; | 231 | encodedString*result = 0; |
230 | init_storage(); | 232 | init_storage(); |
231 | if (!m_storage) { | 233 | if (!m_storage) { |
232 | return result; | 234 | return result; |
233 | } | 235 | } |
234 | mailmessage * msg = 0; | 236 | mailmessage * msg = 0; |
235 | char*data=0; | 237 | char*data=0; |
236 | size_t size; | 238 | size_t size; |
237 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); | 239 | int r = mailsession_select_folder(m_storage->sto_session,(char*)mail->getMbox().latin1()); |
238 | if (r!=MAIL_NO_ERROR) { | 240 | if (r!=MAIL_NO_ERROR) { |
239 | qDebug("error selecting folder! "); | 241 | qDebug("error selecting folder! "); |
240 | return result; | 242 | return result; |
241 | } | 243 | } |
242 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); | 244 | r = mailsession_get_message(m_storage->sto_session, mail->getNumber(), &msg); |
243 | if (r != MAIL_NO_ERROR) { | 245 | if (r != MAIL_NO_ERROR) { |
244 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 246 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
245 | return 0; | 247 | return 0; |
246 | } | 248 | } |
247 | r = mailmessage_fetch(msg,&data,&size); | 249 | r = mailmessage_fetch(msg,&data,&size); |
248 | if (r != MAIL_NO_ERROR) { | 250 | if (r != MAIL_NO_ERROR) { |
249 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); | 251 | Global::statusMessage(i18n("Error fetching mail %i").arg(mail->getNumber())); |
250 | if (msg) mailmessage_free(msg); | 252 | if (msg) mailmessage_free(msg); |
251 | return 0; | 253 | return 0; |
252 | } | 254 | } |
253 | result = new encodedString(data,size); | 255 | result = new encodedString(data,size); |
254 | if (msg) mailmessage_free(msg); | 256 | if (msg) mailmessage_free(msg); |
255 | return result; | 257 | return result; |
256 | } | 258 | } |
257 | 259 | ||
258 | void MHwrapper::deleteMails(const QString & mailbox,const QValueList<RecMailP> &target) | 260 | void MHwrapper::deleteMails(const QString & mailbox,const Q3ValueList<RecMailP> &target) |
259 | { | 261 | { |
260 | QString f = buildPath(mailbox); | 262 | QString f = buildPath(mailbox); |
261 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); | 263 | int r = mailsession_select_folder(m_storage->sto_session,(char*)f.latin1()); |
262 | if (r!=MAIL_NO_ERROR) { | 264 | if (r!=MAIL_NO_ERROR) { |
263 | qDebug("deleteMails: error selecting folder! "); | 265 | qDebug("deleteMails: error selecting folder! "); |
264 | return; | 266 | return; |
265 | } | 267 | } |
266 | QValueList<RecMailP>::ConstIterator it; | 268 | Q3ValueList<RecMailP>::ConstIterator it; |
267 | for (it=target.begin(); it!=target.end();++it) { | 269 | for (it=target.begin(); it!=target.end();++it) { |
268 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); | 270 | r = mailsession_remove_message(m_storage->sto_session,(*it)->getNumber()); |
269 | if (r != MAIL_NO_ERROR) { | 271 | if (r != MAIL_NO_ERROR) { |
270 | qDebug("error deleting mail "); | 272 | qDebug("error deleting mail "); |
271 | break; | 273 | break; |
272 | } | 274 | } |
273 | } | 275 | } |
274 | } | 276 | } |
275 | 277 | ||
276 | int MHwrapper::deleteAllMail(const FolderP&tfolder) | 278 | int MHwrapper::deleteAllMail(const FolderP&tfolder) |
277 | { | 279 | { |
278 | init_storage(); | 280 | init_storage(); |
279 | if (!m_storage) { | 281 | if (!m_storage) { |
280 | return 0; | 282 | return 0; |
281 | } | 283 | } |
282 | int res = 1; | 284 | int res = 1; |
283 | if (!tfolder) return 0; | 285 | if (!tfolder) return 0; |
284 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 286 | int r = mailsession_select_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
285 | if (r!=MAIL_NO_ERROR) { | 287 | if (r!=MAIL_NO_ERROR) { |
286 | qDebug("error selecting folder! "); | 288 | qDebug("error selecting folder! "); |
287 | return 0; | 289 | return 0; |
288 | } | 290 | } |
289 | mailmessage_list*l=0; | 291 | mailmessage_list*l=0; |
290 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 292 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
291 | if (r != MAIL_NO_ERROR) { | 293 | if (r != MAIL_NO_ERROR) { |
292 | qDebug("Error message list "); | 294 | qDebug("Error message list "); |
293 | res = 0; | 295 | res = 0; |
294 | } | 296 | } |
295 | unsigned j = 0; | 297 | unsigned j = 0; |
296 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 298 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
297 | mailmessage * msg; | 299 | mailmessage * msg; |
298 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 300 | msg = (mailmessage*)carray_get(l->msg_tab, i); |