summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/smtpwrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/smtpwrapper.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp59
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
@@ -5,24 +5,25 @@
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
19using namespace Opie::Core; 20using namespace Opie::Core;
20progressMailSend*SMTPwrapper::sendProgress = 0; 21progressMailSend*SMTPwrapper::sendProgress = 0;
21 22
22SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 23SMTPwrapper::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 );
@@ -35,61 +36,61 @@ SMTPwrapper::~SMTPwrapper()
35{ 36{
36 disc_server(); 37 disc_server();
37} 38}
38 39
39void SMTPwrapper::emitQCop( int queued ) { 40void 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
44QString SMTPwrapper::mailsmtpError( int errnum ) { 45QString 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
88void SMTPwrapper::progress( size_t current, size_t maximum ) { 89void 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
95void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 96void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
@@ -143,26 +144,26 @@ bool SMTPwrapper::smtpSend( mailmime *mail,bool later) {
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
149void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 150void 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
160int SMTPwrapper::start_smtp_tls() 161int 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;
@@ -212,77 +213,77 @@ void SMTPwrapper::connect_server()
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
283void SMTPwrapper::disc_server() 284void 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;
@@ -291,25 +292,25 @@ void SMTPwrapper::disc_server()
291 292
292int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 293int 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 }
@@ -424,26 +425,26 @@ bool SMTPwrapper::flushOutbox() {
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" );