summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/smtpwrapper.cpp
Unidiff
Diffstat (limited to 'kmicromail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/smtpwrapper.cpp15
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,178 +1,183 @@
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
20using namespace Opie::Core; 23using namespace Opie::Core;
21progressMailSend*SMTPwrapper::sendProgress = 0; 24progressMailSend*SMTPwrapper::sendProgress = 0;
22 25
23SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) 26SMTPwrapper::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
35SMTPwrapper::~SMTPwrapper() 38SMTPwrapper::~SMTPwrapper()
36{ 39{
37 disc_server(); 40 disc_server();
38} 41}
39 42
40void SMTPwrapper::emitQCop( int queued ) { 43void 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
45QString SMTPwrapper::mailsmtpError( int errnum ) { 50QString 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" );
67 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 72 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
68 // return i18n( "Insufficient system storage" ); 73 // return i18n( "Insufficient system storage" );
69 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 74 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
70 return i18n( "Mailbox unavailable" ); 75 return i18n( "Mailbox unavailable" );
71 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 76 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
72 return i18n( "Mailbox name not allowed" ); 77 return i18n( "Mailbox name not allowed" );
73 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 78 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
74 return i18n( "Bad command sequence" ); 79 return i18n( "Bad command sequence" );
75 case MAILSMTP_ERROR_USER_NOT_LOCAL: 80 case MAILSMTP_ERROR_USER_NOT_LOCAL:
76 return i18n( "User not local" ); 81 return i18n( "User not local" );
77 case MAILSMTP_ERROR_TRANSACTION_FAILED: 82 case MAILSMTP_ERROR_TRANSACTION_FAILED:
78 return i18n( "Transaction failed" ); 83 return i18n( "Transaction failed" );
79 case MAILSMTP_ERROR_MEMORY: 84 case MAILSMTP_ERROR_MEMORY:
80 return i18n( "Memory error" ); 85 return i18n( "Memory error" );
81 case MAILSMTP_ERROR_CONNECTION_REFUSED: 86 case MAILSMTP_ERROR_CONNECTION_REFUSED:
82 return i18n( "Connection refused" ); 87 return i18n( "Connection refused" );
83 default: 88 default:
84 return i18n( "Unknown error code" ); 89 return i18n( "Unknown error code" );
85 } 90 }
86} 91}
87 92
88 93
89void SMTPwrapper::progress( size_t current, size_t maximum ) { 94void SMTPwrapper::progress( size_t current, size_t maximum ) {
90 if (SMTPwrapper::sendProgress) { 95 if (SMTPwrapper::sendProgress) {
91 SMTPwrapper::sendProgress->setSingleMail(current, maximum ); 96 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
92 qApp->processEvents(); 97 qApp->processEvents();
93 } 98 }
94} 99}
95 100
96void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 101void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
97 if (!mail) 102 if (!mail)
98 return; 103 return;
99 QString localfolders = AbstractMail::defaultLocalfolder(); 104 QString localfolders = AbstractMail::defaultLocalfolder();
100 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 105 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
101 wrap->createMbox(box); 106 wrap->createMbox(box);
102 wrap->storeMessage(mail,length,box); 107 wrap->storeMessage(mail,length,box);
103 delete wrap; 108 delete wrap;
104} 109}
105 110
106bool SMTPwrapper::smtpSend( mailmime *mail,bool later) { 111bool 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
150void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 155void 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 }
155 if (failuremessage) { 160 if (failuremessage) {
156 QMessageBox::critical(0,i18n("Error sending mail"), 161 QMessageBox::critical(0,i18n("Error sending mail"),
157 i18n("<center>%1</center>").arg(failuremessage)); 162 i18n("<center>%1</center>").arg(failuremessage));
158 } 163 }
159} 164}
160 165
161int SMTPwrapper::start_smtp_tls() 166int SMTPwrapper::start_smtp_tls()
162{ 167{
163 if (!m_smtp) { 168 if (!m_smtp) {
164 return MAILSMTP_ERROR_IN_PROCESSING; 169 return MAILSMTP_ERROR_IN_PROCESSING;
165 } 170 }
166 int err = mailesmtp_starttls(m_smtp); 171 int err = mailesmtp_starttls(m_smtp);
167 if (err != MAILSMTP_NO_ERROR) return err; 172 if (err != MAILSMTP_NO_ERROR) return err;
168 mailstream_low * low; 173 mailstream_low * low;
169 mailstream_low * new_low; 174 mailstream_low * new_low;
170 low = mailstream_get_low(m_smtp->stream); 175 low = mailstream_get_low(m_smtp->stream);
171 if (!low) { 176 if (!low) {
172 return MAILSMTP_ERROR_IN_PROCESSING; 177 return MAILSMTP_ERROR_IN_PROCESSING;
173 } 178 }
174 int fd = mailstream_low_get_fd(low); 179 int fd = mailstream_low_get_fd(low);
175 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 180 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
176 mailstream_low_free(low); 181 mailstream_low_free(low);
177 mailstream_set_low(m_smtp->stream, new_low); 182 mailstream_set_low(m_smtp->stream, new_low);
178 } else { 183 } else {
@@ -402,60 +407,60 @@ bool SMTPwrapper::flushOutbox() {
402 QValueList<RecMailP> mailsToRemove; 407 QValueList<RecMailP> mailsToRemove;
403 QString mbox("Outgoing"); 408 QString mbox("Outgoing");
404 wrap->listMessages(mbox,mailsToSend); 409 wrap->listMessages(mbox,mailsToSend);
405 if (mailsToSend.count()==0) { 410 if (mailsToSend.count()==0) {
406 delete wrap; 411 delete wrap;
407 ; // odebug << "No mails to send" << oendl; 412 ; // odebug << "No mails to send" << oendl;
408 return false; 413 return false;
409 } 414 }
410 415
411 oldPw = m_SmtpAccount->getPassword(); 416 oldPw = m_SmtpAccount->getPassword();
412 oldUser = m_SmtpAccount->getUser(); 417 oldUser = m_SmtpAccount->getUser();
413 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 418 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
414 // get'em 419 // get'em
415 QString user,pass; 420 QString user,pass;
416 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 421 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
417 login.show(); 422 login.show();
418 if ( QDialog::Accepted == login.exec() ) { 423 if ( QDialog::Accepted == login.exec() ) {
419 // ok 424 // ok
420 user = login.getUser().latin1(); 425 user = login.getUser().latin1();
421 pass = login.getPassword().latin1(); 426 pass = login.getPassword().latin1();
422 reset_user_value = true; 427 reset_user_value = true;
423 m_SmtpAccount->setUser(user); 428 m_SmtpAccount->setUser(user);
424 m_SmtpAccount->setPassword(pass); 429 m_SmtpAccount->setPassword(pass);
425 } else { 430 } else {
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}