Diffstat (limited to 'kmicromail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index d5a528c..dee1477 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,351 +1,352 @@ | |||
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 | #include <qpe/config.h> |
14 | #include <qpe/qcopenvelope_qws.h> | 14 | #include <qpe/qcopenvelope_qws.h> |
15 | 15 | ||
16 | #include <libetpan/libetpan.h> | 16 | #include <libetpan/libetpan.h> |
17 | #include <klocale.h> | ||
17 | 18 | ||
18 | 19 | ||
19 | using namespace Opie::Core; | 20 | using namespace Opie::Core; |
20 | progressMailSend*SMTPwrapper::sendProgress = 0; | 21 | progressMailSend*SMTPwrapper::sendProgress = 0; |
21 | 22 | ||
22 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 23 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
23 | : Generatemail() | 24 | : Generatemail() |
24 | { | 25 | { |
25 | m_SmtpAccount = aSmtp; | 26 | m_SmtpAccount = aSmtp; |
26 | Config cfg( "mail" ); | 27 | Config cfg( "mail" ); |
27 | cfg.setGroup( "Status" ); | 28 | cfg.setGroup( "Status" ); |
28 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 29 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
29 | emit queuedMails( m_queuedMail ); | 30 | emit queuedMails( m_queuedMail ); |
30 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 31 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
31 | m_smtp = 0; | 32 | m_smtp = 0; |
32 | } | 33 | } |
33 | 34 | ||
34 | SMTPwrapper::~SMTPwrapper() | 35 | SMTPwrapper::~SMTPwrapper() |
35 | { | 36 | { |
36 | disc_server(); | 37 | disc_server(); |
37 | } | 38 | } |
38 | 39 | ||
39 | void SMTPwrapper::emitQCop( int queued ) { | 40 | void SMTPwrapper::emitQCop( int queued ) { |
40 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 41 | QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
41 | env << queued; | 42 | env << queued; |
42 | } | 43 | } |
43 | 44 | ||
44 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 45 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
45 | switch ( errnum ) { | 46 | switch ( errnum ) { |
46 | case MAILSMTP_NO_ERROR: | 47 | case MAILSMTP_NO_ERROR: |
47 | return tr( "No error" ); | 48 | return i18n( "No error" ); |
48 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 49 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
49 | return tr( "Unexpected error code" ); | 50 | return i18n( "Unexpected error code" ); |
50 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 51 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
51 | return tr( "Service not available" ); | 52 | return i18n( "Service not available" ); |
52 | case MAILSMTP_ERROR_STREAM: | 53 | case MAILSMTP_ERROR_STREAM: |
53 | return tr( "Stream error" ); | 54 | return i18n( "Stream error" ); |
54 | case MAILSMTP_ERROR_HOSTNAME: | 55 | case MAILSMTP_ERROR_HOSTNAME: |
55 | return tr( "gethostname() failed" ); | 56 | return i18n( "gethostname() failed" ); |
56 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 57 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
57 | return tr( "Not implemented" ); | 58 | return i18n( "Not implemented" ); |
58 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 59 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
59 | return tr( "Error, action not taken" ); | 60 | return i18n( "Error, action not taken" ); |
60 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 61 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
61 | return tr( "Data exceeds storage allocation" ); | 62 | return i18n( "Data exceeds storage allocation" ); |
62 | case MAILSMTP_ERROR_IN_PROCESSING: | 63 | case MAILSMTP_ERROR_IN_PROCESSING: |
63 | return tr( "Error in processing" ); | 64 | return i18n( "Error in processing" ); |
64 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 65 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
65 | return tr( "Starttls not supported" ); | 66 | return i18n( "Starttls not supported" ); |
66 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 67 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
67 | // return tr( "Insufficient system storage" ); | 68 | // return i18n( "Insufficient system storage" ); |
68 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 69 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
69 | return tr( "Mailbox unavailable" ); | 70 | return i18n( "Mailbox unavailable" ); |
70 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 71 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
71 | return tr( "Mailbox name not allowed" ); | 72 | return i18n( "Mailbox name not allowed" ); |
72 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 73 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
73 | return tr( "Bad command sequence" ); | 74 | return i18n( "Bad command sequence" ); |
74 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 75 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
75 | return tr( "User not local" ); | 76 | return i18n( "User not local" ); |
76 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 77 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
77 | return tr( "Transaction failed" ); | 78 | return i18n( "Transaction failed" ); |
78 | case MAILSMTP_ERROR_MEMORY: | 79 | case MAILSMTP_ERROR_MEMORY: |
79 | return tr( "Memory error" ); | 80 | return i18n( "Memory error" ); |
80 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 81 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
81 | return tr( "Connection refused" ); | 82 | return i18n( "Connection refused" ); |
82 | default: | 83 | default: |
83 | return tr( "Unknown error code" ); | 84 | return i18n( "Unknown error code" ); |
84 | } | 85 | } |
85 | } | 86 | } |
86 | 87 | ||
87 | 88 | ||
88 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 89 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
89 | if (SMTPwrapper::sendProgress) { | 90 | if (SMTPwrapper::sendProgress) { |
90 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 91 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
91 | qApp->processEvents(); | 92 | qApp->processEvents(); |
92 | } | 93 | } |
93 | } | 94 | } |
94 | 95 | ||
95 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 96 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
96 | if (!mail) | 97 | if (!mail) |
97 | return; | 98 | return; |
98 | QString localfolders = AbstractMail::defaultLocalfolder(); | 99 | QString localfolders = AbstractMail::defaultLocalfolder(); |
99 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 100 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
100 | wrap->createMbox(box); | 101 | wrap->createMbox(box); |
101 | wrap->storeMessage(mail,length,box); | 102 | wrap->storeMessage(mail,length,box); |
102 | delete wrap; | 103 | delete wrap; |
103 | } | 104 | } |
104 | 105 | ||
105 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { | 106 | bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { |
106 | clist *rcpts = 0; | 107 | clist *rcpts = 0; |
107 | char *from, *data; | 108 | char *from, *data; |
108 | size_t size; | 109 | size_t size; |
109 | 110 | ||
110 | from = data = 0; | 111 | from = data = 0; |
111 | 112 | ||
112 | mailmessage * msg = 0; | 113 | mailmessage * msg = 0; |
113 | msg = mime_message_init(mail); | 114 | msg = mime_message_init(mail); |
114 | mime_message_set_tmpdir(msg,getenv( "HOME" )); | 115 | mime_message_set_tmpdir(msg,getenv( "HOME" )); |
115 | int r = mailmessage_fetch(msg,&data,&size); | 116 | int r = mailmessage_fetch(msg,&data,&size); |
116 | mime_message_detach_mime(msg); | 117 | mime_message_detach_mime(msg); |
117 | mailmessage_free(msg); | 118 | mailmessage_free(msg); |
118 | if (r != MAIL_NO_ERROR || !data) { | 119 | if (r != MAIL_NO_ERROR || !data) { |
119 | if (data) | 120 | if (data) |
120 | free(data); | 121 | free(data); |
121 | qDebug("Error fetching mime... "); | 122 | qDebug("Error fetching mime... "); |
122 | return false; | 123 | return false; |
123 | } | 124 | } |
124 | msg = 0; | 125 | msg = 0; |
125 | if (later) { | 126 | if (later) { |
126 | storeMail(data,size,"Outgoing"); | 127 | storeMail(data,size,"Outgoing"); |
127 | if (data) | 128 | if (data) |
128 | free( data ); | 129 | free( data ); |
129 | Config cfg( "mail" ); | 130 | Config cfg( "mail" ); |
130 | cfg.setGroup( "Status" ); | 131 | cfg.setGroup( "Status" ); |
131 | cfg.writeEntry( "outgoing", ++m_queuedMail ); | 132 | cfg.writeEntry( "outgoing", ++m_queuedMail ); |
132 | emit queuedMails( m_queuedMail ); | 133 | emit queuedMails( m_queuedMail ); |
133 | return true; | 134 | return true; |
134 | } | 135 | } |
135 | from = getFrom( mail ); | 136 | from = getFrom( mail ); |
136 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); | 137 | rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); |
137 | bool result = smtpSend(from,rcpts,data,size); | 138 | bool result = smtpSend(from,rcpts,data,size); |
138 | if (data) { | 139 | if (data) { |
139 | free(data); | 140 | free(data); |
140 | } | 141 | } |
141 | if (from) { | 142 | if (from) { |
142 | free(from); | 143 | free(from); |
143 | } | 144 | } |
144 | if (rcpts) | 145 | if (rcpts) |
145 | smtp_address_list_free( rcpts ); | 146 | smtp_address_list_free( rcpts ); |
146 | return result; | 147 | return result; |
147 | } | 148 | } |
148 | 149 | ||
149 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) | 150 | void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) |
150 | { | 151 | { |
151 | if (data) { | 152 | if (data) { |
152 | storeMail(data,size,"Sendfailed"); | 153 | storeMail(data,size,"Sendfailed"); |
153 | } | 154 | } |
154 | if (failuremessage) { | 155 | if (failuremessage) { |
155 | QMessageBox::critical(0,tr("Error sending mail"), | 156 | QMessageBox::critical(0,i18n("Error sending mail"), |
156 | tr("<center>%1</center>").arg(failuremessage)); | 157 | i18n("<center>%1</center>").arg(failuremessage)); |
157 | } | 158 | } |
158 | } | 159 | } |
159 | 160 | ||
160 | int SMTPwrapper::start_smtp_tls() | 161 | int SMTPwrapper::start_smtp_tls() |
161 | { | 162 | { |
162 | if (!m_smtp) { | 163 | if (!m_smtp) { |
163 | return MAILSMTP_ERROR_IN_PROCESSING; | 164 | return MAILSMTP_ERROR_IN_PROCESSING; |
164 | } | 165 | } |
165 | int err = mailesmtp_starttls(m_smtp); | 166 | int err = mailesmtp_starttls(m_smtp); |
166 | if (err != MAILSMTP_NO_ERROR) return err; | 167 | if (err != MAILSMTP_NO_ERROR) return err; |
167 | mailstream_low * low; | 168 | mailstream_low * low; |
168 | mailstream_low * new_low; | 169 | mailstream_low * new_low; |
169 | low = mailstream_get_low(m_smtp->stream); | 170 | low = mailstream_get_low(m_smtp->stream); |
170 | if (!low) { | 171 | if (!low) { |
171 | return MAILSMTP_ERROR_IN_PROCESSING; | 172 | return MAILSMTP_ERROR_IN_PROCESSING; |
172 | } | 173 | } |
173 | int fd = mailstream_low_get_fd(low); | 174 | int fd = mailstream_low_get_fd(low); |
174 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { | 175 | if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { |
175 | mailstream_low_free(low); | 176 | mailstream_low_free(low); |
176 | mailstream_set_low(m_smtp->stream, new_low); | 177 | mailstream_set_low(m_smtp->stream, new_low); |
177 | } else { | 178 | } else { |
178 | return MAILSMTP_ERROR_IN_PROCESSING; | 179 | return MAILSMTP_ERROR_IN_PROCESSING; |
179 | } | 180 | } |
180 | return err; | 181 | return err; |
181 | } | 182 | } |
182 | 183 | ||
183 | void SMTPwrapper::connect_server() | 184 | void SMTPwrapper::connect_server() |
184 | { | 185 | { |
185 | QString server, user, pass; | 186 | QString server, user, pass; |
186 | bool ssl; | 187 | bool ssl; |
187 | uint16_t port; | 188 | uint16_t port; |
188 | ssl = false; | 189 | ssl = false; |
189 | bool try_tls = true; | 190 | bool try_tls = true; |
190 | bool force_tls=false; | 191 | bool force_tls=false; |
191 | QString failuretext = ""; | 192 | QString failuretext = ""; |
192 | 193 | ||
193 | if (m_smtp || !m_SmtpAccount) { | 194 | if (m_smtp || !m_SmtpAccount) { |
194 | return; | 195 | return; |
195 | } | 196 | } |
196 | server = m_SmtpAccount->getServer(); | 197 | server = m_SmtpAccount->getServer(); |
197 | if ( m_SmtpAccount->ConnectionType() == 2 ) { | 198 | if ( m_SmtpAccount->ConnectionType() == 2 ) { |
198 | ssl = true; | 199 | ssl = true; |
199 | try_tls = false; | 200 | try_tls = false; |
200 | } else if (m_SmtpAccount->ConnectionType() == 1) { | 201 | } else if (m_SmtpAccount->ConnectionType() == 1) { |
201 | force_tls = true; | 202 | force_tls = true; |
202 | } | 203 | } |
203 | int result = 1; | 204 | int result = 1; |
204 | port = m_SmtpAccount->getPort().toUInt(); | 205 | port = m_SmtpAccount->getPort().toUInt(); |
205 | 206 | ||
206 | m_smtp = mailsmtp_new( 20, &progress ); | 207 | m_smtp = mailsmtp_new( 20, &progress ); |
207 | if ( m_smtp == NULL ) { | 208 | if ( m_smtp == NULL ) { |
208 | /* no failure message cause this happens when problems with memory - than we | 209 | /* no failure message cause this happens when problems with memory - than we |
209 | we can not display any messagebox */ | 210 | we can not display any messagebox */ |
210 | return; | 211 | return; |
211 | } | 212 | } |
212 | 213 | ||
213 | int err = MAILSMTP_NO_ERROR; | 214 | int err = MAILSMTP_NO_ERROR; |
214 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; | 215 | ; // odebug << "Servername " << server << " at port " << port << "" << oendl; |
215 | if ( ssl ) { | 216 | if ( ssl ) { |
216 | ; // odebug << "SSL session" << oendl; | 217 | ; // odebug << "SSL session" << oendl; |
217 | err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); | 218 | err = mailsmtp_ssl_connect( m_smtp, server.latin1(), port ); |
218 | } else { | 219 | } else { |
219 | ; // odebug << "No SSL session" << oendl; | 220 | ; // odebug << "No SSL session" << oendl; |
220 | err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); | 221 | err = mailsmtp_socket_connect( m_smtp, server.latin1(), port ); |
221 | } | 222 | } |
222 | if ( err != MAILSMTP_NO_ERROR ) { | 223 | if ( err != MAILSMTP_NO_ERROR ) { |
223 | ; // odebug << "Error init connection" << oendl; | 224 | ; // odebug << "Error init connection" << oendl; |
224 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 225 | failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
225 | result = 0; | 226 | result = 0; |
226 | } | 227 | } |
227 | 228 | ||
228 | /* switch to tls after init 'cause there it will send the ehlo */ | 229 | /* switch to tls after init 'cause there it will send the ehlo */ |
229 | if (result) { | 230 | if (result) { |
230 | err = mailsmtp_init( m_smtp ); | 231 | err = mailsmtp_init( m_smtp ); |
231 | if (err != MAILSMTP_NO_ERROR) { | 232 | if (err != MAILSMTP_NO_ERROR) { |
232 | result = 0; | 233 | result = 0; |
233 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); | 234 | failuretext = i18n("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
234 | } | 235 | } |
235 | } | 236 | } |
236 | 237 | ||
237 | if (try_tls) { | 238 | if (try_tls) { |
238 | err = start_smtp_tls(); | 239 | err = start_smtp_tls(); |
239 | if (err != MAILSMTP_NO_ERROR) { | 240 | if (err != MAILSMTP_NO_ERROR) { |
240 | try_tls = false; | 241 | try_tls = false; |
241 | } else { | 242 | } else { |
242 | err = mailesmtp_ehlo(m_smtp); | 243 | err = mailesmtp_ehlo(m_smtp); |
243 | } | 244 | } |
244 | } | 245 | } |
245 | 246 | ||
246 | if (!try_tls && force_tls) { | 247 | if (!try_tls && force_tls) { |
247 | result = 0; | 248 | result = 0; |
248 | failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); | 249 | failuretext = i18n("Error init SMTP tls: %1").arg(mailsmtpError(err)); |
249 | } | 250 | } |
250 | 251 | ||
251 | if (result==1 && m_SmtpAccount->getLogin() ) { | 252 | if (result==1 && m_SmtpAccount->getLogin() ) { |
252 | ; // odebug << "smtp with auth" << oendl; | 253 | ; // odebug << "smtp with auth" << oendl; |
253 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { | 254 | if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { |
254 | // get'em | 255 | // get'em |
255 | LoginDialog login( m_SmtpAccount->getUser(), | 256 | LoginDialog login( m_SmtpAccount->getUser(), |
256 | m_SmtpAccount->getPassword(), NULL, 0, true ); | 257 | m_SmtpAccount->getPassword(), NULL, 0, true ); |
257 | login.show(); | 258 | login.show(); |
258 | if ( QDialog::Accepted == login.exec() ) { | 259 | if ( QDialog::Accepted == login.exec() ) { |
259 | // ok | 260 | // ok |
260 | user = login.getUser(); | 261 | user = login.getUser(); |
261 | pass = login.getPassword(); | 262 | pass = login.getPassword(); |
262 | } else { | 263 | } else { |
263 | result = 0; | 264 | result = 0; |
264 | failuretext=tr("Login aborted - storing mail to localfolder"); | 265 | failuretext=i18n("Login aborted - storing mail to localfolder"); |
265 | } | 266 | } |
266 | } else { | 267 | } else { |
267 | user = m_SmtpAccount->getUser(); | 268 | user = m_SmtpAccount->getUser(); |
268 | pass = m_SmtpAccount->getPassword(); | 269 | pass = m_SmtpAccount->getPassword(); |
269 | } | 270 | } |
270 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; | 271 | ; // odebug << "session->auth: " << m_smtp->auth << "" << oendl; |
271 | if (result) { | 272 | if (result) { |
272 | err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); | 273 | err = mailsmtp_auth( m_smtp, (char*)user.latin1(), (char*)pass.latin1() ); |
273 | if ( err == MAILSMTP_NO_ERROR ) { | 274 | if ( err == MAILSMTP_NO_ERROR ) { |
274 | ; // odebug << "auth ok" << oendl; | 275 | ; // odebug << "auth ok" << oendl; |
275 | } else { | 276 | } else { |
276 | failuretext = tr("Authentification failed"); | 277 | failuretext = i18n("Authentification failed"); |
277 | result = 0; | 278 | result = 0; |
278 | } | 279 | } |
279 | } | 280 | } |
280 | } | 281 | } |
281 | } | 282 | } |
282 | 283 | ||
283 | void SMTPwrapper::disc_server() | 284 | void SMTPwrapper::disc_server() |
284 | { | 285 | { |
285 | if (m_smtp) { | 286 | if (m_smtp) { |
286 | mailsmtp_quit( m_smtp ); | 287 | mailsmtp_quit( m_smtp ); |
287 | mailsmtp_free( m_smtp ); | 288 | mailsmtp_free( m_smtp ); |
288 | m_smtp = 0; | 289 | m_smtp = 0; |
289 | } | 290 | } |
290 | } | 291 | } |
291 | 292 | ||
292 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | 293 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) |
293 | { | 294 | { |
294 | int err,result; | 295 | int err,result; |
295 | QString failuretext = ""; | 296 | QString failuretext = ""; |
296 | 297 | ||
297 | connect_server(); | 298 | connect_server(); |
298 | 299 | ||
299 | result = 1; | 300 | result = 1; |
300 | if (m_smtp) { | 301 | if (m_smtp) { |
301 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); | 302 | err = mailsmtp_send( m_smtp, from, rcpts, data, size ); |
302 | if ( err != MAILSMTP_NO_ERROR ) { | 303 | if ( err != MAILSMTP_NO_ERROR ) { |
303 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); | 304 | failuretext=i18n("Error sending mail: %1").arg(mailsmtpError(err)); |
304 | result = 0; | 305 | result = 0; |
305 | } | 306 | } |
306 | } else { | 307 | } else { |
307 | result = 0; | 308 | result = 0; |
308 | } | 309 | } |
309 | 310 | ||
310 | if (!result) { | 311 | if (!result) { |
311 | storeFailedMail(data,size,failuretext); | 312 | storeFailedMail(data,size,failuretext); |
312 | } else { | 313 | } else { |
313 | ; // odebug << "Mail sent." << oendl; | 314 | ; // odebug << "Mail sent." << oendl; |
314 | storeMail(data,size,"Sent"); | 315 | storeMail(data,size,"Sent"); |
315 | } | 316 | } |
316 | return result; | 317 | return result; |
317 | } | 318 | } |
318 | 319 | ||
319 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 320 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
320 | { | 321 | { |
321 | mailmime * mimeMail; | 322 | mailmime * mimeMail; |
322 | bool result = true; | 323 | bool result = true; |
323 | mimeMail = createMimeMail(mail ); | 324 | mimeMail = createMimeMail(mail ); |
324 | if ( mimeMail == 0 ) { | 325 | if ( mimeMail == 0 ) { |
325 | qDebug("SMTP wrapper:Error creating mail! "); | 326 | qDebug("SMTP wrapper:Error creating mail! "); |
326 | return false; | 327 | return false; |
327 | } else { | 328 | } else { |
328 | sendProgress = new progressMailSend(); | 329 | sendProgress = new progressMailSend(); |
329 | sendProgress->show(); | 330 | sendProgress->show(); |
330 | sendProgress->setMaxMails(1); | 331 | sendProgress->setMaxMails(1); |
331 | result = smtpSend( mimeMail,later); | 332 | result = smtpSend( mimeMail,later); |
332 | ; // odebug << "Clean up done" << oendl; | 333 | ; // odebug << "Clean up done" << oendl; |
333 | sendProgress->hide(); | 334 | sendProgress->hide(); |
334 | delete sendProgress; | 335 | delete sendProgress; |
335 | sendProgress = 0; | 336 | sendProgress = 0; |
336 | mailmime_free( mimeMail ); | 337 | mailmime_free( mimeMail ); |
337 | } | 338 | } |
338 | return result; | 339 | return result; |
339 | } | 340 | } |
340 | 341 | ||
341 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 342 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
342 | size_t curTok = 0; | 343 | size_t curTok = 0; |
343 | mailimf_fields *fields = 0; | 344 | mailimf_fields *fields = 0; |
344 | mailimf_field*ffrom = 0; | 345 | mailimf_field*ffrom = 0; |
345 | clist *rcpts = 0; | 346 | clist *rcpts = 0; |
346 | char*from = 0; | 347 | char*from = 0; |
347 | int res = 0; | 348 | int res = 0; |
348 | 349 | ||
349 | encodedString * data = wrap->fetchRawBody(which); | 350 | encodedString * data = wrap->fetchRawBody(which); |
350 | if (!data) | 351 | if (!data) |
351 | return 0; | 352 | return 0; |
@@ -388,73 +389,73 @@ bool SMTPwrapper::flushOutbox() { | |||
388 | ; // odebug << "No smtp account given" << oendl; | 389 | ; // odebug << "No smtp account given" << oendl; |
389 | return false; | 390 | return false; |
390 | } | 391 | } |
391 | 392 | ||
392 | bool reset_user_value = false; | 393 | bool reset_user_value = false; |
393 | QString localfolders = AbstractMail::defaultLocalfolder(); | 394 | QString localfolders = AbstractMail::defaultLocalfolder(); |
394 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 395 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
395 | if (!wrap) { | 396 | if (!wrap) { |
396 | ; // odebug << "memory error" << oendl; | 397 | ; // odebug << "memory error" << oendl; |
397 | return false; | 398 | return false; |
398 | } | 399 | } |
399 | QString oldPw, oldUser; | 400 | QString oldPw, oldUser; |
400 | QValueList<RecMailP> mailsToSend; | 401 | QValueList<RecMailP> mailsToSend; |
401 | QValueList<RecMailP> mailsToRemove; | 402 | QValueList<RecMailP> mailsToRemove; |
402 | QString mbox("Outgoing"); | 403 | QString mbox("Outgoing"); |
403 | wrap->listMessages(mbox,mailsToSend); | 404 | wrap->listMessages(mbox,mailsToSend); |
404 | if (mailsToSend.count()==0) { | 405 | if (mailsToSend.count()==0) { |
405 | delete wrap; | 406 | delete wrap; |
406 | ; // odebug << "No mails to send" << oendl; | 407 | ; // odebug << "No mails to send" << oendl; |
407 | return false; | 408 | return false; |
408 | } | 409 | } |
409 | 410 | ||
410 | oldPw = m_SmtpAccount->getPassword(); | 411 | oldPw = m_SmtpAccount->getPassword(); |
411 | oldUser = m_SmtpAccount->getUser(); | 412 | oldUser = m_SmtpAccount->getUser(); |
412 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 413 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
413 | // get'em | 414 | // get'em |
414 | QString user,pass; | 415 | QString user,pass; |
415 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 416 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
416 | login.show(); | 417 | login.show(); |
417 | if ( QDialog::Accepted == login.exec() ) { | 418 | if ( QDialog::Accepted == login.exec() ) { |
418 | // ok | 419 | // ok |
419 | user = login.getUser().latin1(); | 420 | user = login.getUser().latin1(); |
420 | pass = login.getPassword().latin1(); | 421 | pass = login.getPassword().latin1(); |
421 | reset_user_value = true; | 422 | reset_user_value = true; |
422 | m_SmtpAccount->setUser(user); | 423 | m_SmtpAccount->setUser(user); |
423 | m_SmtpAccount->setPassword(pass); | 424 | m_SmtpAccount->setPassword(pass); |
424 | } else { | 425 | } else { |
425 | return true; | 426 | return true; |
426 | } | 427 | } |
427 | } | 428 | } |
428 | 429 | ||
429 | 430 | ||
430 | sendProgress = new progressMailSend(); | 431 | sendProgress = new progressMailSend(); |
431 | sendProgress->show(); | 432 | sendProgress->show(); |
432 | sendProgress->setMaxMails(mailsToSend.count()); | 433 | sendProgress->setMaxMails(mailsToSend.count()); |
433 | 434 | ||
434 | while (mailsToSend.count()>0) { | 435 | while (mailsToSend.count()>0) { |
435 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | 436 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { |
436 | QMessageBox::critical(0,tr("Error sending mail"), | 437 | QMessageBox::critical(0,i18n("Error sending mail"), |
437 | tr("Error sending queued mail - breaking")); | 438 | i18n("Error sending queued mail - breaking")); |
438 | returnValue = false; | 439 | returnValue = false; |
439 | break; | 440 | break; |
440 | } | 441 | } |
441 | mailsToRemove.append((*mailsToSend.begin())); | 442 | mailsToRemove.append((*mailsToSend.begin())); |
442 | mailsToSend.remove(mailsToSend.begin()); | 443 | mailsToSend.remove(mailsToSend.begin()); |
443 | sendProgress->setCurrentMails(mailsToRemove.count()); | 444 | sendProgress->setCurrentMails(mailsToRemove.count()); |
444 | } | 445 | } |
445 | if (reset_user_value) { | 446 | if (reset_user_value) { |
446 | m_SmtpAccount->setUser(oldUser); | 447 | m_SmtpAccount->setUser(oldUser); |
447 | m_SmtpAccount->setPassword(oldPw); | 448 | m_SmtpAccount->setPassword(oldPw); |
448 | } | 449 | } |
449 | Config cfg( "mail" ); | 450 | Config cfg( "mail" ); |
450 | cfg.setGroup( "Status" ); | 451 | cfg.setGroup( "Status" ); |
451 | m_queuedMail = 0; | 452 | m_queuedMail = 0; |
452 | cfg.writeEntry( "outgoing", m_queuedMail ); | 453 | cfg.writeEntry( "outgoing", m_queuedMail ); |
453 | emit queuedMails( m_queuedMail ); | 454 | emit queuedMails( m_queuedMail ); |
454 | sendProgress->hide(); | 455 | sendProgress->hide(); |
455 | delete sendProgress; | 456 | delete sendProgress; |
456 | sendProgress = 0; | 457 | sendProgress = 0; |
457 | wrap->deleteMails(mbox,mailsToRemove); | 458 | wrap->deleteMails(mbox,mailsToRemove); |
458 | delete wrap; | 459 | delete wrap; |
459 | return returnValue; | 460 | return returnValue; |
460 | } | 461 | } |