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.cpp6
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,59 +1,61 @@
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
23using namespace Opie::Core; 25using namespace Opie::Core;
24progressMailSend*SMTPwrapper::sendProgress = 0; 26progressMailSend*SMTPwrapper::sendProgress = 0;
25 27
26SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 28SMTPwrapper::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
38SMTPwrapper::~SMTPwrapper() 40SMTPwrapper::~SMTPwrapper()
39{ 41{
40 disc_server(); 42 disc_server();
41} 43}
42 44
43void SMTPwrapper::emitQCop( int queued ) { 45void 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
51QString SMTPwrapper::mailsmtpError( int errnum ) { 53QString 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:
@@ -389,98 +391,98 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
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 */
420bool SMTPwrapper::flushOutbox() { 422bool 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" ) );