-rw-r--r-- | noncore/net/mail/libmailwrapper/mhwrapper.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/noncore/net/mail/libmailwrapper/mhwrapper.cpp b/noncore/net/mail/libmailwrapper/mhwrapper.cpp index 21e24a0..5eae31f 100644 --- a/noncore/net/mail/libmailwrapper/mhwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mhwrapper.cpp | |||
@@ -1,61 +1,59 @@ | |||
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 <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <qpe/global.h> | 8 | #include <qpe/global.h> |
9 | #include <opie2/oprocess.h> | 9 | #include <opie2/oprocess.h> |
10 | 10 | ||
11 | using namespace Opie::Core; | 11 | using namespace Opie::Core; |
12 | using namespace Opie::Core; | ||
13 | using namespace Opie::Core; | ||
14 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) | 12 | MHwrapper::MHwrapper(const QString & mbox_dir,const QString&mbox_name) |
15 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) | 13 | : Genericwrapper(),MHPath(mbox_dir),MHName(mbox_name) |
16 | { | 14 | { |
17 | if (MHPath.length()>0) { | 15 | if (MHPath.length()>0) { |
18 | if (MHPath[MHPath.length()-1]=='/') { | 16 | if (MHPath[MHPath.length()-1]=='/') { |
19 | MHPath=MHPath.left(MHPath.length()-1); | 17 | MHPath=MHPath.left(MHPath.length()-1); |
20 | } | 18 | } |
21 | qDebug(MHPath); | 19 | qDebug(MHPath); |
22 | QDir dir(MHPath); | 20 | QDir dir(MHPath); |
23 | if (!dir.exists()) { | 21 | if (!dir.exists()) { |
24 | dir.mkdir(MHPath); | 22 | dir.mkdir(MHPath); |
25 | } | 23 | } |
26 | init_storage(); | 24 | init_storage(); |
27 | } | 25 | } |
28 | } | 26 | } |
29 | 27 | ||
30 | void MHwrapper::init_storage() | 28 | void MHwrapper::init_storage() |
31 | { | 29 | { |
32 | int r; | 30 | int r; |
33 | QString pre = MHPath; | 31 | QString pre = MHPath; |
34 | if (!m_storage) { | 32 | if (!m_storage) { |
35 | m_storage = mailstorage_new(NULL); | 33 | m_storage = mailstorage_new(NULL); |
36 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); | 34 | r = mh_mailstorage_init(m_storage,(char*)pre.latin1(),0,0,0); |
37 | if (r != MAIL_NO_ERROR) { | 35 | if (r != MAIL_NO_ERROR) { |
38 | qDebug("error initializing storage"); | 36 | qDebug("error initializing storage"); |
39 | mailstorage_free(m_storage); | 37 | mailstorage_free(m_storage); |
40 | m_storage = 0; | 38 | m_storage = 0; |
41 | return; | 39 | return; |
42 | } | 40 | } |
43 | } | 41 | } |
44 | r = mailstorage_connect(m_storage); | 42 | r = mailstorage_connect(m_storage); |
45 | if (r!=MAIL_NO_ERROR) { | 43 | if (r!=MAIL_NO_ERROR) { |
46 | qDebug("error connecting storage"); | 44 | qDebug("error connecting storage"); |
47 | mailstorage_free(m_storage); | 45 | mailstorage_free(m_storage); |
48 | m_storage = 0; | 46 | m_storage = 0; |
49 | } | 47 | } |
50 | } | 48 | } |
51 | 49 | ||
52 | void MHwrapper::clean_storage() | 50 | void MHwrapper::clean_storage() |
53 | { | 51 | { |
54 | if (m_storage) { | 52 | if (m_storage) { |
55 | mailstorage_disconnect(m_storage); | 53 | mailstorage_disconnect(m_storage); |
56 | mailstorage_free(m_storage); | 54 | mailstorage_free(m_storage); |
57 | m_storage = 0; | 55 | m_storage = 0; |
58 | } | 56 | } |
59 | } | 57 | } |
60 | 58 | ||
61 | MHwrapper::~MHwrapper() | 59 | MHwrapper::~MHwrapper() |
@@ -276,99 +274,99 @@ int MHwrapper::deleteAllMail(const FolderP&tfolder) | |||
276 | qDebug("error selecting folder!"); | 274 | qDebug("error selecting folder!"); |
277 | return 0; | 275 | return 0; |
278 | } | 276 | } |
279 | mailmessage_list*l=0; | 277 | mailmessage_list*l=0; |
280 | r = mailsession_get_messages_list(m_storage->sto_session,&l); | 278 | r = mailsession_get_messages_list(m_storage->sto_session,&l); |
281 | if (r != MAIL_NO_ERROR) { | 279 | if (r != MAIL_NO_ERROR) { |
282 | qDebug("Error message list"); | 280 | qDebug("Error message list"); |
283 | res = 0; | 281 | res = 0; |
284 | } | 282 | } |
285 | unsigned j = 0; | 283 | unsigned j = 0; |
286 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { | 284 | for(unsigned int i = 0 ; l!= 0 && res==1 && i < carray_count(l->msg_tab) ; ++i) { |
287 | mailmessage * msg; | 285 | mailmessage * msg; |
288 | msg = (mailmessage*)carray_get(l->msg_tab, i); | 286 | msg = (mailmessage*)carray_get(l->msg_tab, i); |
289 | j = msg->msg_index; | 287 | j = msg->msg_index; |
290 | r = mailsession_remove_message(m_storage->sto_session,j); | 288 | r = mailsession_remove_message(m_storage->sto_session,j); |
291 | if (r != MAIL_NO_ERROR) { | 289 | if (r != MAIL_NO_ERROR) { |
292 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); | 290 | Global::statusMessage(tr("Error deleting mail %1").arg(i+1)); |
293 | res = 0; | 291 | res = 0; |
294 | break; | 292 | break; |
295 | } | 293 | } |
296 | } | 294 | } |
297 | if (l) mailmessage_list_free(l); | 295 | if (l) mailmessage_list_free(l); |
298 | return res; | 296 | return res; |
299 | } | 297 | } |
300 | 298 | ||
301 | int MHwrapper::deleteMbox(const FolderP&tfolder) | 299 | int MHwrapper::deleteMbox(const FolderP&tfolder) |
302 | { | 300 | { |
303 | init_storage(); | 301 | init_storage(); |
304 | if (!m_storage) { | 302 | if (!m_storage) { |
305 | return 0; | 303 | return 0; |
306 | } | 304 | } |
307 | if (!tfolder) return 0; | 305 | if (!tfolder) return 0; |
308 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; | 306 | if (tfolder->getName()=="/" || tfolder->getName().isEmpty()) return 0; |
309 | 307 | ||
310 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); | 308 | int r = mailsession_delete_folder(m_storage->sto_session,(char*)tfolder->getName().latin1()); |
311 | 309 | ||
312 | if (r != MAIL_NO_ERROR) { | 310 | if (r != MAIL_NO_ERROR) { |
313 | qDebug("error deleting mail box"); | 311 | qDebug("error deleting mail box"); |
314 | return 0; | 312 | return 0; |
315 | } | 313 | } |
316 | QString cmd = "rm -rf "+tfolder->getName(); | 314 | QString cmd = "rm -rf "+tfolder->getName(); |
317 | QStringList command; | 315 | QStringList command; |
318 | command << "/bin/sh"; | 316 | command << "/bin/sh"; |
319 | command << "-c"; | 317 | command << "-c"; |
320 | command << cmd.latin1(); | 318 | command << cmd.latin1(); |
321 | OProcess *process = new OProcess(); | 319 | OProcess *process = new OProcess(); |
322 | 320 | ||
323 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), | 321 | connect(process, SIGNAL(processExited(Opie::Core::OProcess*)), |
324 | this, SLOT( processEnded(OProcess*))); | 322 | this, SLOT( processEnded(Opie::Core::OProcess*))); |
325 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), | 323 | connect(process, SIGNAL( receivedStderr(Opie::Core::OProcess*,char*,int)), |
326 | this, SLOT( oprocessStderr(OProcess*,char*,int))); | 324 | this, SLOT( oprocessStderr(Opie::Core::OProcess*,char*,int))); |
327 | 325 | ||
328 | *process << command; | 326 | *process << command; |
329 | removeMboxfailed = false; | 327 | removeMboxfailed = false; |
330 | if(!process->start(OProcess::Block, OProcess::All) ) { | 328 | if(!process->start(OProcess::Block, OProcess::All) ) { |
331 | qDebug("could not start process"); | 329 | qDebug("could not start process"); |
332 | return 0; | 330 | return 0; |
333 | } | 331 | } |
334 | qDebug("mail box deleted"); | 332 | qDebug("mail box deleted"); |
335 | return 1; | 333 | return 1; |
336 | } | 334 | } |
337 | 335 | ||
338 | void MHwrapper::processEnded(OProcess *p) | 336 | void MHwrapper::processEnded(OProcess *p) |
339 | { | 337 | { |
340 | if (p) delete p; | 338 | if (p) delete p; |
341 | } | 339 | } |
342 | 340 | ||
343 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) | 341 | void MHwrapper::oprocessStderr(OProcess*, char *buffer, int ) |
344 | { | 342 | { |
345 | QString lineStr = buffer; | 343 | QString lineStr = buffer; |
346 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); | 344 | QMessageBox::warning( 0, tr("Error"), lineStr ,tr("Ok") ); |
347 | removeMboxfailed = true; | 345 | removeMboxfailed = true; |
348 | } | 346 | } |
349 | 347 | ||
350 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) | 348 | void MHwrapper::statusFolder(folderStat&target_stat,const QString & mailbox) |
351 | { | 349 | { |
352 | init_storage(); | 350 | init_storage(); |
353 | if (!m_storage) { | 351 | if (!m_storage) { |
354 | return; | 352 | return; |
355 | } | 353 | } |
356 | target_stat.message_count = 0; | 354 | target_stat.message_count = 0; |
357 | target_stat.message_unseen = 0; | 355 | target_stat.message_unseen = 0; |
358 | target_stat.message_recent = 0; | 356 | target_stat.message_recent = 0; |
359 | QString f = buildPath(mailbox); | 357 | QString f = buildPath(mailbox); |
360 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, | 358 | int r = mailsession_status_folder(m_storage->sto_session,(char*)f.latin1(),&target_stat.message_count, |
361 | &target_stat.message_recent,&target_stat.message_unseen); | 359 | &target_stat.message_recent,&target_stat.message_unseen); |
362 | if (r != MAIL_NO_ERROR) { | 360 | if (r != MAIL_NO_ERROR) { |
363 | Global::statusMessage(tr("Error retrieving status")); | 361 | Global::statusMessage(tr("Error retrieving status")); |
364 | } | 362 | } |
365 | } | 363 | } |
366 | 364 | ||
367 | MAILLIB::ATYPE MHwrapper::getType()const | 365 | MAILLIB::ATYPE MHwrapper::getType()const |
368 | { | 366 | { |
369 | return MAILLIB::A_MH; | 367 | return MAILLIB::A_MH; |
370 | } | 368 | } |
371 | 369 | ||
372 | const QString&MHwrapper::getName()const | 370 | const QString&MHwrapper::getName()const |
373 | { | 371 | { |
374 | return MHName; | 372 | return MHName; |