Diffstat (limited to 'kmicromail/libmailwrapper/smtpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index dee1477..eb07ef1 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,66 +1,71 @@ | |||
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 | #include <qpe/config.h> | 13 | #ifndef DESKTOP_VERSION |
14 | //#include <qpe/config.h> | ||
14 | #include <qpe/qcopenvelope_qws.h> | 15 | #include <qpe/qcopenvelope_qws.h> |
15 | 16 | #endif | |
16 | #include <libetpan/libetpan.h> | 17 | #include <libetpan/libetpan.h> |
17 | #include <klocale.h> | 18 | #include <klocale.h> |
19 | #include <kglobal.h> | ||
20 | #include <kconfig.h> | ||
18 | 21 | ||
19 | 22 | ||
20 | using namespace Opie::Core; | 23 | using namespace Opie::Core; |
21 | progressMailSend*SMTPwrapper::sendProgress = 0; | 24 | progressMailSend*SMTPwrapper::sendProgress = 0; |
22 | 25 | ||
23 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
24 | : Generatemail() | 27 | : Generatemail() |
25 | { | 28 | { |
26 | m_SmtpAccount = aSmtp; | 29 | m_SmtpAccount = aSmtp; |
27 | Config cfg( "mail" ); | 30 | KConfig cfg( locateLocal("config", "kopiemail" ) ); |
28 | cfg.setGroup( "Status" ); | 31 | cfg.setGroup( "Status" ); |
29 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
30 | emit queuedMails( m_queuedMail ); | 33 | emit queuedMails( m_queuedMail ); |
31 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
32 | m_smtp = 0; | 35 | m_smtp = 0; |
33 | } | 36 | } |
34 | 37 | ||
35 | SMTPwrapper::~SMTPwrapper() | 38 | SMTPwrapper::~SMTPwrapper() |
36 | { | 39 | { |
37 | disc_server(); | 40 | disc_server(); |
38 | } | 41 | } |
39 | 42 | ||
40 | void SMTPwrapper::emitQCop( int queued ) { | 43 | void SMTPwrapper::emitQCop( int queued ) { |
44 | #ifndef DESKTOP_VERSION | ||
41 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 45 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
42 | env << queued; | 46 | env << queued; |
47 | #endif | ||
43 | } | 48 | } |
44 | 49 | ||
45 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 50 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
46 | switch ( errnum ) { | 51 | switch ( errnum ) { |
47 | case MAILSMTP_NO_ERROR: | 52 | case MAILSMTP_NO_ERROR: |
48 | return i18n( "No error" ); | 53 | return i18n( "No error" ); |
49 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 54 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
50 | return i18n( "Unexpected error code" ); | 55 | return i18n( "Unexpected error code" ); |
51 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 56 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
52 | return i18n( "Service not available" ); | 57 | return i18n( "Service not available" ); |
53 | case MAILSMTP_ERROR_STREAM: | 58 | case MAILSMTP_ERROR_STREAM: |
54 | return i18n( "Stream error" ); | 59 | return i18n( "Stream error" ); |
55 | case MAILSMTP_ERROR_HOSTNAME: | 60 | case MAILSMTP_ERROR_HOSTNAME: |
56 | return i18n( "gethostname() failed" ); | 61 | return i18n( "gethostname() failed" ); |
57 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 62 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
58 | return i18n( "Not implemented" ); | 63 | return i18n( "Not implemented" ); |
59 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 64 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
60 | return i18n( "Error, action not taken" ); | 65 | return i18n( "Error, action not taken" ); |
61 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 66 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
62 | return i18n( "Data exceeds storage allocation" ); | 67 | return i18n( "Data exceeds storage allocation" ); |
63 | case MAILSMTP_ERROR_IN_PROCESSING: | 68 | case MAILSMTP_ERROR_IN_PROCESSING: |
64 | return i18n( "Error in processing" ); | 69 | return i18n( "Error in processing" ); |
65 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 70 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
66 | return i18n( "Starttls not supported" ); | 71 | return i18n( "Starttls not supported" ); |
@@ -106,49 +111,49 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | |||
106 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 111 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
107 | clist *rcpts = 0; | 112 | clist *rcpts = 0; |
108 | char *from, *data; | 113 | char *from, *data; |
109 | size_t size; | 114 | size_t size; |
110 | 115 | ||
111 | from = data = 0; | 116 | from = data = 0; |
112 | 117 | ||
113 | mailmessage * msg = 0; | 118 | mailmessage * msg = 0; |
114 | msg = mime_message_init(mail); | 119 | msg = mime_message_init(mail); |
115 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 120 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
116 | int r = mailmessage_fetch(msg,&data,&size); | 121 | int r = mailmessage_fetch(msg,&data,&size); |
117 | mime_message_detach_mime(msg); | 122 | mime_message_detach_mime(msg); |
118 | mailmessage_free(msg); | 123 | mailmessage_free(msg); |
119 | if (r != MAIL_NO_ERROR || !data) { | 124 | if (r != MAIL_NO_ERROR || !data) { |
120 | if (data) | 125 | if (data) |
121 | free(data); | 126 | free(data); |
122 | qDebug("Error fetching mime... "); | 127 | qDebug("Error fetching mime... "); |
123 | return false; | 128 | return false; |
124 | } | 129 | } |
125 | msg = 0; | 130 | msg = 0; |
126 | if (later) { | 131 | if (later) { |
127 | storeMail(data,size,"Outgoing"); | 132 | storeMail(data,size,"Outgoing"); |
128 | if (data) | 133 | if (data) |
129 | free( data ); | 134 | free( data ); |
130 | Config cfg( "mail" ); | 135 | KConfig cfg( locateLocal("config", "kopiemail" ) ); |
131 | cfg.setGroup( "Status" ); | 136 | cfg.setGroup( "Status" ); |
132 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 137 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
133 | emit queuedMails( m_queuedMail ); | 138 | emit queuedMails( m_queuedMail ); |
134 | return true; | 139 | return true; |
135 | } | 140 | } |
136 | from = getFrom( mail ); | 141 | from = getFrom( mail ); |
137 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 142 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
138 | bool result = smtpSend(from,rcpts,data,size); | 143 | bool result = smtpSend(from,rcpts,data,size); |
139 | if (data) { | 144 | if (data) { |
140 | free(data); | 145 | free(data); |
141 | } | 146 | } |
142 | if (from) { | 147 | if (from) { |
143 | free(from); | 148 | free(from); |
144 | } | 149 | } |
145 | if (rcpts) | 150 | if (rcpts) |
146 | smtp_address_list_free( rcpts ); | 151 | smtp_address_list_free( rcpts ); |
147 | return result; | 152 | return result; |
148 | } | 153 | } |
149 | 154 | ||
150 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 155 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
151 | { | 156 | { |
152 | if (data) { | 157 | if (data) { |
153 | storeMail(data,size,"Sendfailed"); | 158 | storeMail(data,size,"Sendfailed"); |
154 | } | 159 | } |
@@ -426,36 +431,36 @@ bool SMTPwrapper::flushOutbox() { | |||
426 | return true; | 431 | return true; |
427 | } | 432 | } |
428 | } | 433 | } |
429 | 434 | ||
430 | 435 | ||
431 | sendProgress = new progressMailSend(); | 436 | sendProgress = new progressMailSend(); |
432 | sendProgress->show(); | 437 | sendProgress->show(); |
433 | sendProgress->setMaxMails(mailsToSend.count()); | 438 | sendProgress->setMaxMails(mailsToSend.count()); |
434 | 439 | ||
435 | while (mailsToSend.count()>0) { | 440 | while (mailsToSend.count()>0) { |
436 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | 441 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { |
437 | QMessageBox::critical(0,i18n("Error sending mail"), | 442 | QMessageBox::critical(0,i18n("Error sending mail"), |
438 | i18n("Error sending queued mail - breaking")); | 443 | i18n("Error sending queued mail - breaking")); |
439 | returnValue = false; | 444 | returnValue = false; |
440 | break; | 445 | break; |
441 | } | 446 | } |
442 | mailsToRemove.append((*mailsToSend.begin())); | 447 | mailsToRemove.append((*mailsToSend.begin())); |
443 | mailsToSend.remove(mailsToSend.begin()); | 448 | mailsToSend.remove(mailsToSend.begin()); |
444 | sendProgress->setCurrentMails(mailsToRemove.count()); | 449 | sendProgress->setCurrentMails(mailsToRemove.count()); |
445 | } | 450 | } |
446 | if (reset_user_value) { | 451 | if (reset_user_value) { |
447 | m_SmtpAccount->setUser(oldUser); | 452 | m_SmtpAccount->setUser(oldUser); |
448 | m_SmtpAccount->setPassword(oldPw); | 453 | m_SmtpAccount->setPassword(oldPw); |
449 | } | 454 | } |
450 | Config cfg( "mail" ); | 455 | KConfig cfg( locateLocal("config", "kopiemail" ) ); |
451 | cfg.setGroup( "Status" ); | 456 | cfg.setGroup( "Status" ); |
452 | m_queuedMail = 0; | 457 | m_queuedMail = 0; |
453 | cfg.writeEntry( "outgoing", m_queuedMail ); | 458 | cfg.writeEntry( "outgoing", m_queuedMail ); |
454 | emit queuedMails( m_queuedMail ); | 459 | emit queuedMails( m_queuedMail ); |
455 | sendProgress->hide(); | 460 | sendProgress->hide(); |
456 | delete sendProgress; | 461 | delete sendProgress; |
457 | sendProgress = 0; | 462 | sendProgress = 0; |
458 | wrap->deleteMails(mbox,mailsToRemove); | 463 | wrap->deleteMails(mbox,mailsToRemove); |
459 | delete wrap; | 464 | delete wrap; |
460 | return returnValue; | 465 | return returnValue; |
461 | } | 466 | } |