summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp24
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h1
2 files changed, 24 insertions, 1 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 085d5e4..7671133 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,20 +1,21 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9#include <qmessagebox.h>
9 10
10#include <qpe/config.h> 11#include <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h> 12#include <qpe/qcopenvelope_qws.h>
12 13
13#include <libetpan/libetpan.h> 14#include <libetpan/libetpan.h>
14 15
15#include "smtpwrapper.h" 16#include "smtpwrapper.h"
16#include "mailwrapper.h" 17#include "mailwrapper.h"
17#include "abstractmail.h" 18#include "abstractmail.h"
18#include "logindialog.h" 19#include "logindialog.h"
19#include "mailtypes.h" 20#include "mailtypes.h"
20//#include "defines.h" 21//#include "defines.h"
@@ -545,24 +546,35 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
545 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 546 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
546 smtpSend(from,rcpts,data,size,smtp); 547 smtpSend(from,rcpts,data,size,smtp);
547 if (data) { 548 if (data) {
548 free(data); 549 free(data);
549 } 550 }
550 if (from) { 551 if (from) {
551 free(from); 552 free(from);
552 } 553 }
553 if (rcpts) 554 if (rcpts)
554 smtp_address_list_free( rcpts ); 555 smtp_address_list_free( rcpts );
555} 556}
556 557
558void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
559{
560 if (data) {
561 storeMail(data,size,"Sendfailed");
562 }
563 if (failuremessage) {
564 QMessageBox::critical(0,tr("Error sending mail"),
565 tr("<center>%1</center>").arg(failuremessage));
566 }
567}
568
557int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { 569int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) {
558 const char *server, *user, *pass; 570 const char *server, *user, *pass;
559 bool ssl; 571 bool ssl;
560 uint16_t port; 572 uint16_t port;
561 mailsmtp *session; 573 mailsmtp *session;
562 int err,result; 574 int err,result;
563 575
564 result = 1; 576 result = 1;
565 server = user = pass = 0; 577 server = user = pass = 0;
566 server = smtp->getServer().latin1(); 578 server = smtp->getServer().latin1();
567 579
568 // FIXME: currently only TLS and Plain work. 580 // FIXME: currently only TLS and Plain work.
@@ -580,30 +592,32 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
580 goto free_mem; 592 goto free_mem;
581 593
582 qDebug( "Servername %s at port %i", server, port ); 594 qDebug( "Servername %s at port %i", server, port );
583 if ( ssl ) { 595 if ( ssl ) {
584 qDebug( "SSL session" ); 596 qDebug( "SSL session" );
585 err = mailsmtp_ssl_connect( session, server, port ); 597 err = mailsmtp_ssl_connect( session, server, port );
586 } else { 598 } else {
587 qDebug( "No SSL session" ); 599 qDebug( "No SSL session" );
588 err = mailsmtp_socket_connect( session, server, port ); 600 err = mailsmtp_socket_connect( session, server, port );
589 } 601 }
590 if ( err != MAILSMTP_NO_ERROR ) { 602 if ( err != MAILSMTP_NO_ERROR ) {
591 qDebug("Error init connection"); 603 qDebug("Error init connection");
604 storeFailedMail(data,size,mailsmtpError(err));
592 result = 0; 605 result = 0;
593 goto free_mem_session; 606 goto free_mem_session;
594 } 607 }
595 608
596 err = mailsmtp_init( session ); 609 err = mailsmtp_init( session );
597 if ( err != MAILSMTP_NO_ERROR ) { 610 if ( err != MAILSMTP_NO_ERROR ) {
611 storeFailedMail(data,size,mailsmtpError(err));
598 result = 0; 612 result = 0;
599 goto free_con_session; 613 goto free_con_session;
600 } 614 }
601 615
602 qDebug( "INIT OK" ); 616 qDebug( "INIT OK" );
603 617
604 if ( smtp->getLogin() ) { 618 if ( smtp->getLogin() ) {
605 qDebug("smtp with auth"); 619 qDebug("smtp with auth");
606 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 620 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) {
607 // get'em 621 // get'em
608 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 622 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true );
609 login.show(); 623 login.show();
@@ -612,33 +626,41 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
612 user = login.getUser().latin1(); 626 user = login.getUser().latin1();
613 pass = login.getPassword().latin1(); 627 pass = login.getPassword().latin1();
614 } else { 628 } else {
615 result = 0; 629 result = 0;
616 goto free_con_session; 630 goto free_con_session;
617 } 631 }
618 } else { 632 } else {
619 user = smtp->getUser().latin1(); 633 user = smtp->getUser().latin1();
620 pass = smtp->getPassword().latin1(); 634 pass = smtp->getPassword().latin1();
621 } 635 }
622 qDebug( "session->auth: %i", session->auth); 636 qDebug( "session->auth: %i", session->auth);
623 err = mailsmtp_auth( session, (char*)user, (char*)pass ); 637 err = mailsmtp_auth( session, (char*)user, (char*)pass );
624 if ( err == MAILSMTP_NO_ERROR ) 638 if ( err == MAILSMTP_NO_ERROR ) {
625 qDebug("auth ok"); 639 qDebug("auth ok");
640 } else {
641 storeFailedMail(data,size,tr("Authentification failed"));
642 result = 0;
643 goto free_con_session;
644 }
626 qDebug( "Done auth!" ); 645 qDebug( "Done auth!" );
627 } else { 646 } else {
628 qDebug("SMTP without auth"); 647 qDebug("SMTP without auth");
648 result = 0;
649 goto free_con_session;
629 } 650 }
630 651
631 err = mailsmtp_send( session, from, rcpts, data, size ); 652 err = mailsmtp_send( session, from, rcpts, data, size );
632 if ( err != MAILSMTP_NO_ERROR ) { 653 if ( err != MAILSMTP_NO_ERROR ) {
654 storeFailedMail(data,size,mailsmtpError(err));
633 qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); 655 qDebug("Error sending mail: %s",mailsmtpError(err).latin1());
634 result = 0; 656 result = 0;
635 goto free_con_session; 657 goto free_con_session;
636 } 658 }
637 659
638 qDebug( "Mail sent." ); 660 qDebug( "Mail sent." );
639 storeMail(data,size,"Sent"); 661 storeMail(data,size,"Sent");
640 662
641free_con_session: 663free_con_session:
642 mailsmtp_quit( session ); 664 mailsmtp_quit( session );
643free_mem_session: 665free_mem_session:
644 mailsmtp_free( session ); 666 mailsmtp_free( session );
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 7dcdbfd..89826d9 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -51,22 +51,23 @@ protected:
51 static QString mailsmtpError( int err ); 51 static QString mailsmtpError( int err );
52 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
53 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
54 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
55 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
56 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
57 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); 57 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp );
58 58
59 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
60 Settings *settings; 60 Settings *settings;
61 61
62 int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which);
63 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage);
63 64
64 int m_queuedMail; 65 int m_queuedMail;
65 static const char* USER_AGENT; 66 static const char* USER_AGENT;
66 67
67protected slots: 68protected slots:
68 void emitQCop( int queued ); 69 void emitQCop( int queued );
69 70
70}; 71};
71 72
72#endif 73#endif