summaryrefslogtreecommitdiff
path: root/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
Unidiff
Diffstat (limited to 'noncore/net/mail/libmailwrapper/smtpwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index e2cea7a..ba78c3b 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -94,49 +94,49 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
94 return; 94 return;
95 QString localfolders = AbstractMail::defaultLocalfolder(); 95 QString localfolders = AbstractMail::defaultLocalfolder();
96 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 96 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
97 wrap->createMbox(box); 97 wrap->createMbox(box);
98 wrap->storeMessage(mail,length,box); 98 wrap->storeMessage(mail,length,box);
99 delete wrap; 99 delete wrap;
100} 100}
101 101
102void SMTPwrapper::smtpSend( mailmime *mail,bool later) { 102void SMTPwrapper::smtpSend( mailmime *mail,bool later) {
103 clist *rcpts = 0; 103 clist *rcpts = 0;
104 char *from, *data; 104 char *from, *data;
105 size_t size; 105 size_t size;
106 106
107 from = data = 0; 107 from = data = 0;
108 108
109 mailmessage * msg = 0; 109 mailmessage * msg = 0;
110 msg = mime_message_init(mail); 110 msg = mime_message_init(mail);
111 mime_message_set_tmpdir(msg,getenv( "HOME" )); 111 mime_message_set_tmpdir(msg,getenv( "HOME" ));
112 int r = mailmessage_fetch(msg,&data,&size); 112 int r = mailmessage_fetch(msg,&data,&size);
113 mime_message_detach_mime(msg); 113 mime_message_detach_mime(msg);
114 mailmessage_free(msg); 114 mailmessage_free(msg);
115 if (r != MAIL_NO_ERROR || !data) { 115 if (r != MAIL_NO_ERROR || !data) {
116 if (data) 116 if (data)
117 free(data); 117 free(data);
118 qDebug("Error fetching mime..."); 118 odebug << "Error fetching mime..." << oendl;
119 return; 119 return;
120 } 120 }
121 msg = 0; 121 msg = 0;
122 if (later) { 122 if (later) {
123 storeMail(data,size,"Outgoing"); 123 storeMail(data,size,"Outgoing");
124 if (data) 124 if (data)
125 free( data ); 125 free( data );
126 Config cfg( "mail" ); 126 Config cfg( "mail" );
127 cfg.setGroup( "Status" ); 127 cfg.setGroup( "Status" );
128 cfg.writeEntry( "outgoing", ++m_queuedMail ); 128 cfg.writeEntry( "outgoing", ++m_queuedMail );
129 emit queuedMails( m_queuedMail ); 129 emit queuedMails( m_queuedMail );
130 return; 130 return;
131 } 131 }
132 from = getFrom( mail ); 132 from = getFrom( mail );
133 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 133 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
134 smtpSend(from,rcpts,data,size); 134 smtpSend(from,rcpts,data,size);
135 if (data) { 135 if (data) {
136 free(data); 136 free(data);
137 } 137 }
138 if (from) { 138 if (from) {
139 free(from); 139 free(from);
140 } 140 }
141 if (rcpts) 141 if (rcpts)
142 smtp_address_list_free( rcpts ); 142 smtp_address_list_free( rcpts );
@@ -187,166 +187,166 @@ void SMTPwrapper::connect_server()
187 server = user = pass = 0; 187 server = user = pass = 0;
188 QString failuretext = ""; 188 QString failuretext = "";
189 189
190 if (m_smtp || !m_SmtpAccount) { 190 if (m_smtp || !m_SmtpAccount) {
191 return; 191 return;
192 } 192 }
193 server = m_SmtpAccount->getServer().latin1(); 193 server = m_SmtpAccount->getServer().latin1();
194 if ( m_SmtpAccount->ConnectionType() == 2 ) { 194 if ( m_SmtpAccount->ConnectionType() == 2 ) {
195 ssl = true; 195 ssl = true;
196 try_tls = false; 196 try_tls = false;
197 } else if (m_SmtpAccount->ConnectionType() == 1) { 197 } else if (m_SmtpAccount->ConnectionType() == 1) {
198 force_tls = true; 198 force_tls = true;
199 } 199 }
200 int result = 1; 200 int result = 1;
201 port = m_SmtpAccount->getPort().toUInt(); 201 port = m_SmtpAccount->getPort().toUInt();
202 202
203 m_smtp = mailsmtp_new( 20, &progress ); 203 m_smtp = mailsmtp_new( 20, &progress );
204 if ( m_smtp == NULL ) { 204 if ( m_smtp == NULL ) {
205 /* no failure message cause this happens when problems with memory - than we 205 /* no failure message cause this happens when problems with memory - than we
206 we can not display any messagebox */ 206 we can not display any messagebox */
207 return; 207 return;
208 } 208 }
209 209
210 int err = MAILSMTP_NO_ERROR; 210 int err = MAILSMTP_NO_ERROR;
211 qDebug( "Servername %s at port %i", server, port ); 211 odebug << "Servername " << server << " at port " << port << "" << oendl;
212 if ( ssl ) { 212 if ( ssl ) {
213 qDebug( "SSL session" ); 213 odebug << "SSL session" << oendl;
214 err = mailsmtp_ssl_connect( m_smtp, server, port ); 214 err = mailsmtp_ssl_connect( m_smtp, server, port );
215 } else { 215 } else {
216 qDebug( "No SSL session" ); 216 odebug << "No SSL session" << oendl;
217 err = mailsmtp_socket_connect( m_smtp, server, port ); 217 err = mailsmtp_socket_connect( m_smtp, server, port );
218 } 218 }
219 if ( err != MAILSMTP_NO_ERROR ) { 219 if ( err != MAILSMTP_NO_ERROR ) {
220 qDebug("Error init connection"); 220 odebug << "Error init connection" << oendl;
221 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 221 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
222 result = 0; 222 result = 0;
223 } 223 }
224 224
225 /* switch to tls after init 'cause there it will send the ehlo */ 225 /* switch to tls after init 'cause there it will send the ehlo */
226 if (result) { 226 if (result) {
227 err = mailsmtp_init( m_smtp ); 227 err = mailsmtp_init( m_smtp );
228 if (err != MAILSMTP_NO_ERROR) { 228 if (err != MAILSMTP_NO_ERROR) {
229 result = 0; 229 result = 0;
230 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 230 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
231 } 231 }
232 } 232 }
233 233
234 if (try_tls) { 234 if (try_tls) {
235 err = start_smtp_tls(); 235 err = start_smtp_tls();
236 if (err != MAILSMTP_NO_ERROR) { 236 if (err != MAILSMTP_NO_ERROR) {
237 try_tls = false; 237 try_tls = false;
238 } else { 238 } else {
239 err = mailesmtp_ehlo(m_smtp); 239 err = mailesmtp_ehlo(m_smtp);
240 } 240 }
241 } 241 }
242 242
243 if (!try_tls && force_tls) { 243 if (!try_tls && force_tls) {
244 result = 0; 244 result = 0;
245 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); 245 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err));
246 } 246 }
247 247
248 if (result==1 && m_SmtpAccount->getLogin() ) { 248 if (result==1 && m_SmtpAccount->getLogin() ) {
249 qDebug("smtp with auth"); 249 odebug << "smtp with auth" << oendl;
250 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { 250 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
251 // get'em 251 // get'em
252 LoginDialog login( m_SmtpAccount->getUser(), 252 LoginDialog login( m_SmtpAccount->getUser(),
253 m_SmtpAccount->getPassword(), NULL, 0, true ); 253 m_SmtpAccount->getPassword(), NULL, 0, true );
254 login.show(); 254 login.show();
255 if ( QDialog::Accepted == login.exec() ) { 255 if ( QDialog::Accepted == login.exec() ) {
256 // ok 256 // ok
257 user = login.getUser().latin1(); 257 user = login.getUser().latin1();
258 pass = login.getPassword().latin1(); 258 pass = login.getPassword().latin1();
259 } else { 259 } else {
260 result = 0; 260 result = 0;
261 failuretext=tr("Login aborted - storing mail to localfolder"); 261 failuretext=tr("Login aborted - storing mail to localfolder");
262 } 262 }
263 } else { 263 } else {
264 user = m_SmtpAccount->getUser().latin1(); 264 user = m_SmtpAccount->getUser().latin1();
265 pass = m_SmtpAccount->getPassword().latin1(); 265 pass = m_SmtpAccount->getPassword().latin1();
266 } 266 }
267 qDebug( "session->auth: %i", m_smtp->auth); 267 odebug << "session->auth: " << m_smtp->auth << "" << oendl;
268 if (result) { 268 if (result) {
269 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); 269 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass );
270 if ( err == MAILSMTP_NO_ERROR ) { 270 if ( err == MAILSMTP_NO_ERROR ) {
271 qDebug("auth ok"); 271 odebug << "auth ok" << oendl;
272 } else { 272 } else {
273 failuretext = tr("Authentification failed"); 273 failuretext = tr("Authentification failed");
274 result = 0; 274 result = 0;
275 } 275 }
276 } 276 }
277 } 277 }
278} 278}
279 279
280void SMTPwrapper::disc_server() 280void SMTPwrapper::disc_server()
281{ 281{
282 if (m_smtp) { 282 if (m_smtp) {
283 mailsmtp_quit( m_smtp ); 283 mailsmtp_quit( m_smtp );
284 mailsmtp_free( m_smtp ); 284 mailsmtp_free( m_smtp );
285 m_smtp = 0; 285 m_smtp = 0;
286 } 286 }
287} 287}
288 288
289int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) 289int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
290{ 290{
291 int err,result; 291 int err,result;
292 QString failuretext = ""; 292 QString failuretext = "";
293 293
294 connect_server(); 294 connect_server();
295 295
296 result = 1; 296 result = 1;
297 if (m_smtp) { 297 if (m_smtp) {
298 err = mailsmtp_send( m_smtp, from, rcpts, data, size ); 298 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
299 if ( err != MAILSMTP_NO_ERROR ) { 299 if ( err != MAILSMTP_NO_ERROR ) {
300 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); 300 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
301 result = 0; 301 result = 0;
302 } 302 }
303 } else { 303 } else {
304 result = 0; 304 result = 0;
305 } 305 }
306 306
307 if (!result) { 307 if (!result) {
308 storeFailedMail(data,size,failuretext); 308 storeFailedMail(data,size,failuretext);
309 } else { 309 } else {
310 qDebug( "Mail sent." ); 310 odebug << "Mail sent." << oendl;
311 storeMail(data,size,"Sent"); 311 storeMail(data,size,"Sent");
312 } 312 }
313 return result; 313 return result;
314} 314}
315 315
316void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later ) 316void SMTPwrapper::sendMail(const Opie::Core::OSmartPointer<Mail>&mail,bool later )
317{ 317{
318 mailmime * mimeMail; 318 mailmime * mimeMail;
319 319
320 mimeMail = createMimeMail(mail ); 320 mimeMail = createMimeMail(mail );
321 if ( mimeMail == NULL ) { 321 if ( mimeMail == NULL ) {
322 qDebug( "sendMail: error creating mime mail" ); 322 odebug << "sendMail: error creating mime mail" << oendl;
323 } else { 323 } else {
324 sendProgress = new progressMailSend(); 324 sendProgress = new progressMailSend();
325 sendProgress->show(); 325 sendProgress->show();
326 sendProgress->setMaxMails(1); 326 sendProgress->setMaxMails(1);
327 smtpSend( mimeMail,later); 327 smtpSend( mimeMail,later);
328 qDebug("Clean up done"); 328 odebug << "Clean up done" << oendl;
329 sendProgress->hide(); 329 sendProgress->hide();
330 delete sendProgress; 330 delete sendProgress;
331 sendProgress = 0; 331 sendProgress = 0;
332 mailmime_free( mimeMail ); 332 mailmime_free( mimeMail );
333 } 333 }
334} 334}
335 335
336int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) { 336int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
337 size_t curTok = 0; 337 size_t curTok = 0;
338 mailimf_fields *fields = 0; 338 mailimf_fields *fields = 0;
339 mailimf_field*ffrom = 0; 339 mailimf_field*ffrom = 0;
340 clist *rcpts = 0; 340 clist *rcpts = 0;
341 char*from = 0; 341 char*from = 0;
342 int res = 0; 342 int res = 0;
343 343
344 encodedString * data = wrap->fetchRawBody(which); 344 encodedString * data = wrap->fetchRawBody(which);
345 if (!data) 345 if (!data)
346 return 0; 346 return 0;
347 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 347 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
348 if (err != MAILIMF_NO_ERROR) { 348 if (err != MAILIMF_NO_ERROR) {
349 delete data; 349 delete data;
350 delete wrap; 350 delete wrap;
351 return 0; 351 return 0;
352 } 352 }
@@ -357,69 +357,69 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,const RecMailP&which) {
357 357
358 if (rcpts && from) { 358 if (rcpts && from) {
359 res = smtpSend(from,rcpts,data->Content(),data->Length()); 359 res = smtpSend(from,rcpts,data->Content(),data->Length());
360 } 360 }
361 if (fields) { 361 if (fields) {
362 mailimf_fields_free(fields); 362 mailimf_fields_free(fields);
363 fields = 0; 363 fields = 0;
364 } 364 }
365 if (data) { 365 if (data) {
366 delete data; 366 delete data;
367 } 367 }
368 if (from) { 368 if (from) {
369 free(from); 369 free(from);
370 } 370 }
371 if (rcpts) { 371 if (rcpts) {
372 smtp_address_list_free( rcpts ); 372 smtp_address_list_free( rcpts );
373 } 373 }
374 return res; 374 return res;
375} 375}
376 376
377/* this is a special fun */ 377/* this is a special fun */
378bool SMTPwrapper::flushOutbox() { 378bool SMTPwrapper::flushOutbox() {
379 bool returnValue = true; 379 bool returnValue = true;
380 380
381 qDebug("Sending the queue"); 381 odebug << "Sending the queue" << oendl;
382 if (!m_SmtpAccount) { 382 if (!m_SmtpAccount) {
383 qDebug("No smtp account given"); 383 odebug << "No smtp account given" << oendl;
384 return false; 384 return false;
385 } 385 }
386 386
387 bool reset_user_value = false; 387 bool reset_user_value = false;
388 QString localfolders = AbstractMail::defaultLocalfolder(); 388 QString localfolders = AbstractMail::defaultLocalfolder();
389 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 389 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
390 if (!wrap) { 390 if (!wrap) {
391 qDebug("memory error"); 391 odebug << "memory error" << oendl;
392 return false; 392 return false;
393 } 393 }
394 QString oldPw, oldUser; 394 QString oldPw, oldUser;
395 QValueList<RecMailP> mailsToSend; 395 QValueList<RecMailP> mailsToSend;
396 QValueList<RecMailP> mailsToRemove; 396 QValueList<RecMailP> mailsToRemove;
397 QString mbox("Outgoing"); 397 QString mbox("Outgoing");
398 wrap->listMessages(mbox,mailsToSend); 398 wrap->listMessages(mbox,mailsToSend);
399 if (mailsToSend.count()==0) { 399 if (mailsToSend.count()==0) {
400 delete wrap; 400 delete wrap;
401 qDebug("No mails to send"); 401 odebug << "No mails to send" << oendl;
402 return false; 402 return false;
403 } 403 }
404 404
405 oldPw = m_SmtpAccount->getPassword(); 405 oldPw = m_SmtpAccount->getPassword();
406 oldUser = m_SmtpAccount->getUser(); 406 oldUser = m_SmtpAccount->getUser();
407 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { 407 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
408 // get'em 408 // get'em
409 QString user,pass; 409 QString user,pass;
410 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); 410 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
411 login.show(); 411 login.show();
412 if ( QDialog::Accepted == login.exec() ) { 412 if ( QDialog::Accepted == login.exec() ) {
413 // ok 413 // ok
414 user = login.getUser().latin1(); 414 user = login.getUser().latin1();
415 pass = login.getPassword().latin1(); 415 pass = login.getPassword().latin1();
416 reset_user_value = true; 416 reset_user_value = true;
417 m_SmtpAccount->setUser(user); 417 m_SmtpAccount->setUser(user);
418 m_SmtpAccount->setPassword(pass); 418 m_SmtpAccount->setPassword(pass);
419 } else { 419 } else {
420 return true; 420 return true;
421 } 421 }
422 } 422 }
423 423
424 424
425 sendProgress = new progressMailSend(); 425 sendProgress = new progressMailSend();