Diffstat (limited to 'kmicromail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/smtpwrapper.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kmicromail/libmailwrapper/smtpwrapper.cpp b/kmicromail/libmailwrapper/smtpwrapper.cpp index 7c813cc..2df55ff 100644 --- a/kmicromail/libmailwrapper/smtpwrapper.cpp +++ b/kmicromail/libmailwrapper/smtpwrapper.cpp | |||
@@ -1,107 +1,109 @@ | |||
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 | //Added by qt3to4: | ||
13 | #include <Q3ValueList> | ||
12 | #include <stdlib.h> | 14 | #include <stdlib.h> |
13 | #ifndef DESKTOP_VERSION | 15 | #ifndef DESKTOP_VERSION |
14 | //#include <qpe/config.h> | 16 | //#include <qpe/config.h> |
15 | #include <qpe/qcopenvelope_qws.h> | 17 | #include <qpe/qcopenvelope_qws.h> |
16 | #endif | 18 | #endif |
17 | #include <libetpan/libetpan.h> | 19 | #include <libetpan/libetpan.h> |
18 | #include <klocale.h> | 20 | #include <klocale.h> |
19 | #include <kglobal.h> | 21 | #include <kglobal.h> |
20 | #include <kconfig.h> | 22 | #include <kconfig.h> |
21 | 23 | ||
22 | 24 | ||
23 | using namespace Opie::Core; | 25 | using namespace Opie::Core; |
24 | progressMailSend*SMTPwrapper::sendProgress = 0; | 26 | progressMailSend*SMTPwrapper::sendProgress = 0; |
25 | 27 | ||
26 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) | 28 | SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) |
27 | : Generatemail() | 29 | : Generatemail() |
28 | { | 30 | { |
29 | m_SmtpAccount = aSmtp; | 31 | m_SmtpAccount = aSmtp; |
30 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 32 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
31 | cfg.setGroup( "Status" ); | 33 | cfg.setGroup( "Status" ); |
32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 34 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
33 | emit queuedMails( m_queuedMail ); | 35 | emit queuedMails( m_queuedMail ); |
34 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); | 36 | connect( this, SIGNAL( queuedMails(int) ), this, SLOT( emitQCop(int) ) ); |
35 | m_smtp = 0; | 37 | m_smtp = 0; |
36 | } | 38 | } |
37 | 39 | ||
38 | SMTPwrapper::~SMTPwrapper() | 40 | SMTPwrapper::~SMTPwrapper() |
39 | { | 41 | { |
40 | disc_server(); | 42 | disc_server(); |
41 | } | 43 | } |
42 | 44 | ||
43 | void SMTPwrapper::emitQCop( int queued ) { | 45 | void SMTPwrapper::emitQCop( int queued ) { |
44 | #ifndef DESKTOP_VERSION | 46 | #ifndef DESKTOP_VERSION |
45 | // LR : not used in kde-pim | 47 | // LR : not used in kde-pim |
46 | //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); | 48 | //QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); |
47 | //env << queued; | 49 | //env << queued; |
48 | #endif | 50 | #endif |
49 | } | 51 | } |
50 | 52 | ||
51 | QString SMTPwrapper::mailsmtpError( int errnum ) { | 53 | QString SMTPwrapper::mailsmtpError( int errnum ) { |
52 | switch ( errnum ) { | 54 | switch ( errnum ) { |
53 | case MAILSMTP_NO_ERROR: | 55 | case MAILSMTP_NO_ERROR: |
54 | return i18n( "No error" ); | 56 | return i18n( "No error" ); |
55 | case MAILSMTP_ERROR_UNEXPECTED_CODE: | 57 | case MAILSMTP_ERROR_UNEXPECTED_CODE: |
56 | return i18n( "Unexpected error code" ); | 58 | return i18n( "Unexpected error code" ); |
57 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: | 59 | case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: |
58 | return i18n( "Service not available" ); | 60 | return i18n( "Service not available" ); |
59 | case MAILSMTP_ERROR_STREAM: | 61 | case MAILSMTP_ERROR_STREAM: |
60 | return i18n( "Stream error" ); | 62 | return i18n( "Stream error" ); |
61 | case MAILSMTP_ERROR_HOSTNAME: | 63 | case MAILSMTP_ERROR_HOSTNAME: |
62 | return i18n( "gethostname() failed" ); | 64 | return i18n( "gethostname() failed" ); |
63 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: | 65 | case MAILSMTP_ERROR_NOT_IMPLEMENTED: |
64 | return i18n( "Not implemented" ); | 66 | return i18n( "Not implemented" ); |
65 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: | 67 | case MAILSMTP_ERROR_ACTION_NOT_TAKEN: |
66 | return i18n( "Error, action not taken" ); | 68 | return i18n( "Error, action not taken" ); |
67 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: | 69 | case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: |
68 | return i18n( "Data exceeds storage allocation" ); | 70 | return i18n( "Data exceeds storage allocation" ); |
69 | case MAILSMTP_ERROR_IN_PROCESSING: | 71 | case MAILSMTP_ERROR_IN_PROCESSING: |
70 | return i18n( "Error in processing" ); | 72 | return i18n( "Error in processing" ); |
71 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: | 73 | case MAILSMTP_ERROR_STARTTLS_NOT_SUPPORTED: |
72 | return i18n( "Starttls not supported" ); | 74 | return i18n( "Starttls not supported" ); |
73 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: | 75 | // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: |
74 | // return i18n( "Insufficient system storage" ); | 76 | // return i18n( "Insufficient system storage" ); |
75 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: | 77 | case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: |
76 | return i18n( "Mailbox unavailable" ); | 78 | return i18n( "Mailbox unavailable" ); |
77 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: | 79 | case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: |
78 | return i18n( "Mailbox name not allowed" ); | 80 | return i18n( "Mailbox name not allowed" ); |
79 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: | 81 | case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: |
80 | return i18n( "Bad command sequence" ); | 82 | return i18n( "Bad command sequence" ); |
81 | case MAILSMTP_ERROR_USER_NOT_LOCAL: | 83 | case MAILSMTP_ERROR_USER_NOT_LOCAL: |
82 | return i18n( "User not local" ); | 84 | return i18n( "User not local" ); |
83 | case MAILSMTP_ERROR_TRANSACTION_FAILED: | 85 | case MAILSMTP_ERROR_TRANSACTION_FAILED: |
84 | return i18n( "Transaction failed" ); | 86 | return i18n( "Transaction failed" ); |
85 | case MAILSMTP_ERROR_MEMORY: | 87 | case MAILSMTP_ERROR_MEMORY: |
86 | return i18n( "Memory error" ); | 88 | return i18n( "Memory error" ); |
87 | case MAILSMTP_ERROR_CONNECTION_REFUSED: | 89 | case MAILSMTP_ERROR_CONNECTION_REFUSED: |
88 | return i18n( "Connection refused" ); | 90 | return i18n( "Connection refused" ); |
89 | default: | 91 | default: |
90 | return i18n( "Unknown error code" ); | 92 | return i18n( "Unknown error code" ); |
91 | } | 93 | } |
92 | } | 94 | } |
93 | 95 | ||
94 | 96 | ||
95 | void SMTPwrapper::progress( size_t current, size_t maximum ) { | 97 | void SMTPwrapper::progress( size_t current, size_t maximum ) { |
96 | if (SMTPwrapper::sendProgress) { | 98 | if (SMTPwrapper::sendProgress) { |
97 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); | 99 | SMTPwrapper::sendProgress->setSingleMail(current, maximum ); |
98 | qApp->processEvents(); | 100 | qApp->processEvents(); |
99 | } | 101 | } |
100 | } | 102 | } |
101 | 103 | ||
102 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { | 104 | void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { |
103 | if (!mail) | 105 | if (!mail) |
104 | return; | 106 | return; |
105 | QString localfolders = AbstractMail::defaultLocalfolder(); | 107 | QString localfolders = AbstractMail::defaultLocalfolder(); |
106 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 108 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
107 | wrap->createMbox(box); | 109 | wrap->createMbox(box); |
@@ -341,161 +343,161 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) | |||
341 | } | 343 | } |
342 | 344 | ||
343 | if (!result) { | 345 | if (!result) { |
344 | storeFailedMail(data,size,failuretext); | 346 | storeFailedMail(data,size,failuretext); |
345 | } else { | 347 | } else { |
346 | ; // odebug << "Mail sent." << oendl; | 348 | ; // odebug << "Mail sent." << oendl; |
347 | storeMail(data,size,"Sent"); | 349 | storeMail(data,size,"Sent"); |
348 | } | 350 | } |
349 | return result; | 351 | return result; |
350 | } | 352 | } |
351 | 353 | ||
352 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) | 354 | bool SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) |
353 | { | 355 | { |
354 | mailmime * mimeMail; | 356 | mailmime * mimeMail; |
355 | bool result = true; | 357 | bool result = true; |
356 | mimeMail = createMimeMail(mail ); | 358 | mimeMail = createMimeMail(mail ); |
357 | if ( mimeMail == 0 ) { | 359 | if ( mimeMail == 0 ) { |
358 | qDebug("SMTP wrapper:Error creating mail! "); | 360 | qDebug("SMTP wrapper:Error creating mail! "); |
359 | return false; | 361 | return false; |
360 | } else { | 362 | } else { |
361 | sendProgress = new progressMailSend(); | 363 | sendProgress = new progressMailSend(); |
362 | sendProgress->show(); | 364 | sendProgress->show(); |
363 | sendProgress->setMaxMails(1); | 365 | sendProgress->setMaxMails(1); |
364 | result = smtpSend( mimeMail,later); | 366 | result = smtpSend( mimeMail,later); |
365 | ; // odebug << "Clean up done" << oendl; | 367 | ; // odebug << "Clean up done" << oendl; |
366 | sendProgress->hide(); | 368 | sendProgress->hide(); |
367 | delete sendProgress; | 369 | delete sendProgress; |
368 | sendProgress = 0; | 370 | sendProgress = 0; |
369 | mailmime_free( mimeMail ); | 371 | mailmime_free( mimeMail ); |
370 | if ( m_smtp ) { | 372 | if ( m_smtp ) { |
371 | mailsmtp_free(m_smtp); | 373 | mailsmtp_free(m_smtp); |
372 | m_smtp = 0; | 374 | m_smtp = 0; |
373 | } | 375 | } |
374 | } | 376 | } |
375 | return result; | 377 | return result; |
376 | } | 378 | } |
377 | 379 | ||
378 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { | 380 | int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { |
379 | size_t curTok = 0; | 381 | size_t curTok = 0; |
380 | mailimf_fields *fields = 0; | 382 | mailimf_fields *fields = 0; |
381 | mailimf_field*ffrom = 0; | 383 | mailimf_field*ffrom = 0; |
382 | clist *rcpts = 0; | 384 | clist *rcpts = 0; |
383 | char*from = 0; | 385 | char*from = 0; |
384 | int res = 0; | 386 | int res = 0; |
385 | 387 | ||
386 | encodedString * data = wrap->fetchRawBody(which); | 388 | encodedString * data = wrap->fetchRawBody(which); |
387 | if (!data) | 389 | if (!data) |
388 | return 0; | 390 | return 0; |
389 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); | 391 | int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); |
390 | if (err != MAILIMF_NO_ERROR) { | 392 | if (err != MAILIMF_NO_ERROR) { |
391 | delete data; | 393 | delete data; |
392 | delete wrap; | 394 | delete wrap; |
393 | return 0; | 395 | return 0; |
394 | } | 396 | } |
395 | 397 | ||
396 | rcpts = createRcptList( fields ); | 398 | rcpts = createRcptList( fields ); |
397 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); | 399 | ffrom = getField(fields, MAILIMF_FIELD_FROM ); |
398 | from = getFrom(ffrom); | 400 | from = getFrom(ffrom); |
399 | 401 | ||
400 | if (rcpts && from) { | 402 | if (rcpts && from) { |
401 | res = smtpSend(from,rcpts,data->Content(),data->Length()); | 403 | res = smtpSend(from,rcpts,data->Content(),data->Length()); |
402 | } | 404 | } |
403 | if (fields) { | 405 | if (fields) { |
404 | mailimf_fields_free(fields); | 406 | mailimf_fields_free(fields); |
405 | fields = 0; | 407 | fields = 0; |
406 | } | 408 | } |
407 | if (data) { | 409 | if (data) { |
408 | delete data; | 410 | delete data; |
409 | } | 411 | } |
410 | if (from) { | 412 | if (from) { |
411 | free(from); | 413 | free(from); |
412 | } | 414 | } |
413 | if (rcpts) { | 415 | if (rcpts) { |
414 | smtp_address_list_free( rcpts ); | 416 | smtp_address_list_free( rcpts ); |
415 | } | 417 | } |
416 | return res; | 418 | return res; |
417 | } | 419 | } |
418 | 420 | ||
419 | /* this is a special fun */ | 421 | /* this is a special fun */ |
420 | bool SMTPwrapper::flushOutbox() { | 422 | bool SMTPwrapper::flushOutbox() { |
421 | bool returnValue = true; | 423 | bool returnValue = true; |
422 | 424 | ||
423 | ; // odebug << "Sending the queue" << oendl; | 425 | ; // odebug << "Sending the queue" << oendl; |
424 | if (!m_SmtpAccount) { | 426 | if (!m_SmtpAccount) { |
425 | ; // odebug << "No smtp account given" << oendl; | 427 | ; // odebug << "No smtp account given" << oendl; |
426 | return false; | 428 | return false; |
427 | } | 429 | } |
428 | 430 | ||
429 | bool reset_user_value = false; | 431 | bool reset_user_value = false; |
430 | QString localfolders = AbstractMail::defaultLocalfolder(); | 432 | QString localfolders = AbstractMail::defaultLocalfolder(); |
431 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 433 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
432 | if (!wrap) { | 434 | if (!wrap) { |
433 | ; // odebug << "memory error" << oendl; | 435 | ; // odebug << "memory error" << oendl; |
434 | return false; | 436 | return false; |
435 | } | 437 | } |
436 | QString oldPw, oldUser; | 438 | QString oldPw, oldUser; |
437 | QValueList<RecMailP> mailsToSend; | 439 | Q3ValueList<RecMailP> mailsToSend; |
438 | QValueList<RecMailP> mailsToRemove; | 440 | Q3ValueList<RecMailP> mailsToRemove; |
439 | QString mbox("Outgoing"); | 441 | QString mbox("Outgoing"); |
440 | wrap->listMessages(mbox,mailsToSend); | 442 | wrap->listMessages(mbox,mailsToSend); |
441 | if (mailsToSend.count()==0) { | 443 | if (mailsToSend.count()==0) { |
442 | delete wrap; | 444 | delete wrap; |
443 | ; // odebug << "No mails to send" << oendl; | 445 | ; // odebug << "No mails to send" << oendl; |
444 | return false; | 446 | return false; |
445 | } | 447 | } |
446 | 448 | ||
447 | oldPw = m_SmtpAccount->getPassword(); | 449 | oldPw = m_SmtpAccount->getPassword(); |
448 | oldUser = m_SmtpAccount->getUser(); | 450 | oldUser = m_SmtpAccount->getUser(); |
449 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { | 451 | if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { |
450 | // get'em | 452 | // get'em |
451 | QString user,pass; | 453 | QString user,pass; |
452 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); | 454 | LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); |
453 | login.show(); | 455 | login.show(); |
454 | if ( QDialog::Accepted == login.exec() ) { | 456 | if ( QDialog::Accepted == login.exec() ) { |
455 | // ok | 457 | // ok |
456 | user = login.getUser().latin1(); | 458 | user = login.getUser().latin1(); |
457 | pass = login.getPassword().latin1(); | 459 | pass = login.getPassword().latin1(); |
458 | reset_user_value = true; | 460 | reset_user_value = true; |
459 | m_SmtpAccount->setUser(user); | 461 | m_SmtpAccount->setUser(user); |
460 | m_SmtpAccount->setPassword(pass); | 462 | m_SmtpAccount->setPassword(pass); |
461 | } else { | 463 | } else { |
462 | return true; | 464 | return true; |
463 | } | 465 | } |
464 | } | 466 | } |
465 | 467 | ||
466 | 468 | ||
467 | sendProgress = new progressMailSend(); | 469 | sendProgress = new progressMailSend(); |
468 | sendProgress->show(); | 470 | sendProgress->show(); |
469 | sendProgress->setMaxMails(mailsToSend.count()); | 471 | sendProgress->setMaxMails(mailsToSend.count()); |
470 | 472 | ||
471 | while (returnValue && mailsToSend.count()>0) { | 473 | while (returnValue && mailsToSend.count()>0) { |
472 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { | 474 | if (sendQueuedMail(wrap, (*mailsToSend.begin()))==0) { |
473 | QMessageBox::critical(0,i18n("Error sending mail"), | 475 | QMessageBox::critical(0,i18n("Error sending mail"), |
474 | i18n("Error sending queued mail.\nBreaking.")); | 476 | i18n("Error sending queued mail.\nBreaking.")); |
475 | returnValue = false; | 477 | returnValue = false; |
476 | } | 478 | } |
477 | mailsToRemove.append((*mailsToSend.begin())); | 479 | mailsToRemove.append((*mailsToSend.begin())); |
478 | mailsToSend.remove(mailsToSend.begin()); | 480 | mailsToSend.remove(mailsToSend.begin()); |
479 | sendProgress->setCurrentMails(mailsToRemove.count()); | 481 | sendProgress->setCurrentMails(mailsToRemove.count()); |
480 | } | 482 | } |
481 | if (reset_user_value) { | 483 | if (reset_user_value) { |
482 | m_SmtpAccount->setUser(oldUser); | 484 | m_SmtpAccount->setUser(oldUser); |
483 | m_SmtpAccount->setPassword(oldPw); | 485 | m_SmtpAccount->setPassword(oldPw); |
484 | } | 486 | } |
485 | 487 | ||
486 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); | 488 | KConfig cfg( locateLocal("config", "kopiemailrc" ) ); |
487 | cfg.setGroup( "Status" ); | 489 | cfg.setGroup( "Status" ); |
488 | m_queuedMail = mailsToSend.count(); | 490 | m_queuedMail = mailsToSend.count(); |
489 | cfg.writeEntry( "outgoing", m_queuedMail ); | 491 | cfg.writeEntry( "outgoing", m_queuedMail ); |
490 | emit queuedMails( m_queuedMail ); | 492 | emit queuedMails( m_queuedMail ); |
491 | sendProgress->hide(); | 493 | sendProgress->hide(); |
492 | delete sendProgress; | 494 | delete sendProgress; |
493 | sendProgress = 0; | 495 | sendProgress = 0; |
494 | wrap->deleteMails(mbox,mailsToRemove); | 496 | wrap->deleteMails(mbox,mailsToRemove); |
495 | delete wrap; | 497 | delete wrap; |
496 | if ( m_smtp ) { | 498 | if ( m_smtp ) { |
497 | mailsmtp_free(m_smtp); | 499 | mailsmtp_free(m_smtp); |
498 | m_smtp = 0; | 500 | m_smtp = 0; |
499 | } | 501 | } |
500 | return returnValue; | 502 | return returnValue; |
501 | } | 503 | } |