author | zautrix <zautrix> | 2005-02-28 15:30:47 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-02-28 15:30:47 (UTC) |
commit | 16575cca67c9047de72530080dfeb5793a66c935 (patch) (unidiff) | |
tree | fec5ada5eee13fad9c73ec04cd066ccaf2619d4a /kmicromail/libmailwrapper | |
parent | b1f912cbb6a9daf050e94d337de0e0e73417284a (diff) | |
download | kdepimpi-16575cca67c9047de72530080dfeb5793a66c935.zip kdepimpi-16575cca67c9047de72530080dfeb5793a66c935.tar.gz kdepimpi-16575cca67c9047de72530080dfeb5793a66c935.tar.bz2 |
mail fix
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 24f4786..5096f67 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,110 +1,111 @@ | |||
1 | #include "smtpwrapper.h" | 1 | #include "smtpwrapper.h" |
2 | #include "mailwrapper.h" | 2 | #include "mailwrapper.h" |
3 | #include "abstractmail.h" | 3 | #include "abstractmail.h" |
4 | #include "logindialog.h" | 4 | #include "logindialog.h" |
5 | #include "mailtypes.h" | 5 | #include "mailtypes.h" |
6 | #include "sendmailprogress.h" | 6 | #include "sendmailprogress.h" |
7 | 7 | ||
8 | //#include <opie2/odebug.h> | 8 | //#include <opie2/odebug.h> |
9 | //#include <qt.h> | 9 | //#include <qt.h> |
10 | #include <qapplication.h> | 10 | #include <qapplication.h> |
11 | #include <qmessagebox.h> | 11 | #include <qmessagebox.h> |
12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
13 | #ifndef DESKTOP_VERSION | 13 | #ifndef DESKTOP_VERSION |
14 | //#include <qpe/config.h> | 14 | //#include <qpe/config.h> |
15 | #include <qpe/qcopenvelope_qws.h> | 15 | #include <qpe/qcopenvelope_qws.h> |
16 | #endif | 16 | #endif |
17 | #include <libetpan/libetpan.h> | 17 | #include <libetpan/libetpan.h> |
18 | #include <klocale.h> | 18 | #include <klocale.h> |
19 | #include <kglobal.h> | 19 | #include <kglobal.h> |
20 | #include <kconfig.h> | 20 | #include <kconfig.h> |
21 | 21 | ||
22 | 22 | ||
23 | using namespace Opie::Core; | 23 | using namespace Opie::Core; |
24 | progressMailSend*SMTPwrapper::sendProgress = 0; | 24 | progressMailSend*SMTPwrapper::sendProgress = 0; |
25 | 25 | ||
26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
27 | : Generatemail() | 27 | : Generatemail() |
28 | { | 28 | { |
29 | m_SmtpAccount = aSmtp; | 29 | m_SmtpAccount = aSmtp; |
30 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 30 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
31 | cfg.setGroup( "Status" ); | 31 | cfg.setGroup( "Status" ); |
32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
33 | emit queuedMails( m_queuedMail ); | 33 | emit queuedMails( m_queuedMail ); |
34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
35 | m_smtp = 0; | 35 | m_smtp = 0; |
36 | } | 36 | } |
37 | 37 | ||
38 | SMTPwrapper::~SMTPwrapper() | 38 | SMTPwrapper::~SMTPwrapper() |
39 | { | 39 | { |
40 | disc_server(); | 40 | disc_server(); |
41 | } | 41 | } |
42 | 42 | ||
43 | void SMTPwrapper::emitQCop( int queued ) { | 43 | void SMTPwrapper::emitQCop( int queued ) { |
44 | #ifndef DESKTOP_VERSION | 44 | #ifndef DESKTOP_VERSION |
45 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 45 | // LR : not used in kde-pim |
46 | env << queued; | 46 | //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
47 | //env << queued; | ||
47 | #endif | 48 | #endif |
48 | } | 49 | } |
49 | 50 | ||
50 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 51 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
51 | switch ( errnum ) { | 52 | switch ( errnum ) { |
52 | case MAILSMTP_NO_ERROR: | 53 | case MAILSMTP_NO_ERROR: |
53 | return i18n( "No error" ); | 54 | return i18n( "No error" ); |
54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 55 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
55 | return i18n( "Unexpected error code" ); | 56 | return i18n( "Unexpected error code" ); |
56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 57 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
57 | return i18n( "Service not available" ); | 58 | return i18n( "Service not available" ); |
58 | case MAILSMTP_ERROR_STREAM: | 59 | case MAILSMTP_ERROR_STREAM: |
59 | return i18n( "Stream error" ); | 60 | return i18n( "Stream error" ); |
60 | case MAILSMTP_ERROR_HOSTNAME: | 61 | case MAILSMTP_ERROR_HOSTNAME: |
61 | return i18n( "gethostname() failed" ); | 62 | return i18n( "gethostname() failed" ); |
62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 63 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
63 | return i18n( "Not implemented" ); | 64 | return i18n( "Not implemented" ); |
64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 65 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
65 | return i18n( "Error, action not taken" ); | 66 | return i18n( "Error, action not taken" ); |
66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 67 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
67 | return i18n( "Data exceeds storage allocation" ); | 68 | return i18n( "Data exceeds storage allocation" ); |
68 | case MAILSMTP_ERROR_IN_PROCESSING: | 69 | case MAILSMTP_ERROR_IN_PROCESSING: |
69 | return i18n( "Error in processing" ); | 70 | return i18n( "Error in processing" ); |
70 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 71 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
71 | return i18n( "Starttls not supported" ); | 72 | return i18n( "Starttls not supported" ); |
72 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 73 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
73 | // return i18n( "Insufficient system storage" ); | 74 | // return i18n( "Insufficient system storage" ); |
74 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 75 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
75 | return i18n( "Mailbox unavailable" ); | 76 | return i18n( "Mailbox unavailable" ); |
76 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 77 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
77 | return i18n( "Mailbox name not allowed" ); | 78 | return i18n( "Mailbox name not allowed" ); |
78 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 79 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
79 | return i18n( "Bad command sequence" ); | 80 | return i18n( "Bad command sequence" ); |
80 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 81 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
81 | return i18n( "User not local" ); | 82 | return i18n( "User not local" ); |
82 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 83 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
83 | return i18n( "Transaction failed" ); | 84 | return i18n( "Transaction failed" ); |
84 | case MAILSMTP_ERROR_MEMORY: | 85 | case MAILSMTP_ERROR_MEMORY: |
85 | return i18n( "Memory error" ); | 86 | return i18n( "Memory error" ); |
86 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 87 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
87 | return i18n( "Connection refused" ); | 88 | return i18n( "Connection refused" ); |
88 | default: | 89 | default: |
89 | return i18n( "Unknown error code" ); | 90 | return i18n( "Unknown error code" ); |
90 | } | 91 | } |
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
94 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 95 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
95 | if (SMTPwrapper::sendProgress) { | 96 | if (SMTPwrapper::sendProgress) { |
96 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 97 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
97 | qApp->processEvents(); | 98 | qApp->processEvents(); |
98 | } | 99 | } |
99 | } | 100 | } |
100 | 101 | ||
101 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 102 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
102 | if (!mail) | 103 | if (!mail) |
103 | return; | 104 | return; |
104 | QString localfolders = AbstractMail::defaultLocalfolder(); | 105 | QString localfolders = AbstractMail::defaultLocalfolder(); |
105 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 106 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
106 | wrap->createMbox(box); | 107 | wrap->createMbox(box); |
107 | wrap->storeMessage(mail,length,box); | 108 | wrap->storeMessage(mail,length,box); |
108 | delete wrap; | 109 | delete wrap; |
109 | } | 110 | } |
110 | 111 | ||
@@ -380,91 +381,90 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | |||
380 | if (data) { | 381 | if (data) { |
381 | delete data; | 382 | delete data; |
382 | } | 383 | } |
383 | if (from) { | 384 | if (from) { |
384 | free(from); | 385 | free(from); |
385 | } | 386 | } |
386 | if (rcpts) { | 387 | if (rcpts) { |
387 | smtp_address_list_free( rcpts ); | 388 | smtp_address_list_free( rcpts ); |
388 | } | 389 | } |
389 | return res; | 390 | return res; |
390 | } | 391 | } |
391 | 392 | ||
392 | /* this is a special fun */ | 393 | /* this is a special fun */ |
393 | bool SMTPwrapper::flushOutbox() { | 394 | bool SMTPwrapper::flushOutbox() { |
394 | bool returnValue = true; | 395 | bool returnValue = true; |
395 | 396 | ||
396 | ; // odebug << "Sending the queue" << oendl; | 397 | ; // odebug << "Sending the queue" << oendl; |
397 | if (!m_SmtpAccount) { | 398 | if (!m_SmtpAccount) { |
398 | ; // odebug << "No smtp account given" << oendl; | 399 | ; // odebug << "No smtp account given" << oendl; |
399 | return false; | 400 | return false; |
400 | } | 401 | } |
401 | 402 | ||
402 | bool reset_user_value = false; | 403 | bool reset_user_value = false; |
403 | QString localfolders = AbstractMail::defaultLocalfolder(); | 404 | QString localfolders = AbstractMail::defaultLocalfolder(); |
404 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 405 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
405 | if (!wrap) { | 406 | if (!wrap) { |
406 | ; // odebug << "memory error" << oendl; | 407 | ; // odebug << "memory error" << oendl; |
407 | return false; | 408 | return false; |
408 | } | 409 | } |
409 | QString oldPw, oldUser; | 410 | QString oldPw, oldUser; |
410 | QValueList<RecMailP> mailsToSend; | 411 | QValueList<RecMailP> mailsToSend; |
411 | QValueList<RecMailP> mailsToRemove; | 412 | QValueList<RecMailP> mailsToRemove; |
412 | QString mbox("Outgoing"); | 413 | QString mbox("Outgoing"); |
413 | wrap->listMessages(mbox,mailsToSend); | 414 | wrap->listMessages(mbox,mailsToSend); |
414 | if (mailsToSend.count()==0) { | 415 | if (mailsToSend.count()==0) { |
415 | delete wrap; | 416 | delete wrap; |
416 | ; // odebug << "No mails to send" << oendl; | 417 | ; // odebug << "No mails to send" << oendl; |
417 | return false; | 418 | return false; |
418 | } | 419 | } |
419 | 420 | ||
420 | oldPw = m_SmtpAccount->getPassword(); | 421 | oldPw = m_SmtpAccount->getPassword(); |
421 | oldUser = m_SmtpAccount->getUser(); | 422 | oldUser = m_SmtpAccount->getUser(); |
422 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 423 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
423 | // get'em | 424 | // get'em |
424 | QString user,pass; | 425 | QString user,pass; |
425 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 426 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
426 | login.show(); | 427 | login.show(); |
427 | if ( QDialog::Accepted == login.exec() ) { | 428 | if ( QDialog::Accepted == login.exec() ) { |
428 | // ok | 429 | // ok |
429 | user = login.getUser().latin1(); | 430 | user = login.getUser().latin1(); |
430 | pass = login.getPassword().latin1(); | 431 | pass = login.getPassword().latin1(); |
431 | reset_user_value = true; | 432 | reset_user_value = true; |
432 | m_SmtpAccount->setUser(user); | 433 | m_SmtpAccount->setUser(user); |
433 | m_SmtpAccount->setPassword(pass); | 434 | m_SmtpAccount->setPassword(pass); |
434 | } else { | 435 | } else { |
435 | return true; | 436 | return true; |
436 | } | 437 | } |
437 | } | 438 | } |
438 | 439 | ||
439 | 440 | ||
440 | sendProgress = new progressMailSend(); | 441 | sendProgress = new progressMailSend(); |
441 | sendProgress->show(); | 442 | sendProgress->show(); |
442 | sendProgress->setMaxMails(mailsToSend.count()); | 443 | sendProgress->setMaxMails(mailsToSend.count()); |
443 | 444 | ||
444 | while (mailsToSend.count()>0) { | 445 | while (returnValue && mailsToSend.count()>0) { |
445 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | 446 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { |
446 | QMessageBox::critical(0,i18n("Error sending mail"), | 447 | QMessageBox::critical(0,i18n("Error sending mail"), |
447 | i18n("Error sending queued mail - breaking")); | 448 | i18n("Error sending queued mail.\nBreaking.")); |
448 | returnValue = false; | 449 | returnValue = false; |
449 | break; | ||
450 | } | 450 | } |
451 | mailsToRemove.append((*mailsToSend.begin())); | 451 | mailsToRemove.append((*mailsToSend.begin())); |
452 | mailsToSend.remove(mailsToSend.begin()); | 452 | mailsToSend.remove(mailsToSend.begin()); |
453 | sendProgress->setCurrentMails(mailsToRemove.count()); | 453 | sendProgress->setCurrentMails(mailsToRemove.count()); |
454 | } | 454 | } |
455 | if (reset_user_value) { | 455 | if (reset_user_value) { |
456 | m_SmtpAccount->setUser(oldUser); | 456 | m_SmtpAccount->setUser(oldUser); |
457 | m_SmtpAccount->setPassword(oldPw); | 457 | m_SmtpAccount->setPassword(oldPw); |
458 | } | 458 | } |
459 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 459 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
460 | cfg.setGroup( "Status" ); | 460 | cfg.setGroup( "Status" ); |
461 | m_queuedMail = 0; | 461 | m_queuedMail = mailsToSend.count(); |
462 | cfg.writeEntry( "outgoing", m_queuedMail ); | 462 | cfg.writeEntry( "outgoing", m_queuedMail ); |
463 | emit queuedMails( m_queuedMail ); | 463 | emit queuedMails( m_queuedMail ); |
464 | sendProgress->hide(); | 464 | sendProgress->hide(); |
465 | delete sendProgress; | 465 | delete sendProgress; |
466 | sendProgress = 0; | 466 | sendProgress = 0; |
467 | wrap->deleteMails(mbox,mailsToRemove); | 467 | wrap->deleteMails(mbox,mailsToRemove); |
468 | delete wrap; | 468 | delete wrap; |
469 | return returnValue; | 469 | return returnValue; |
470 | } | 470 | } |