author | alwin <alwin> | 2004-01-11 11:45:10 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-11 11:45:10 (UTC) |
commit | c384fb58ea944d6430777d403a6462429242c59b (patch) (side-by-side diff) | |
tree | 16b5d69630d142f6713aff80c2a666c492728ed1 | |
parent | 9edad3578862d4a3d1d85a8c311e3ace902f2f63 (diff) | |
download | opie-c384fb58ea944d6430777d403a6462429242c59b.zip opie-c384fb58ea944d6430777d403a6462429242c59b.tar.gz opie-c384fb58ea944d6430777d403a6462429242c59b.tar.bz2 |
when failure sending mails them will be stored into a local folder
and a message box appears.
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 24 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 1 |
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,32 +1,33 @@ #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <qdir.h> #include <qt.h> +#include <qmessagebox.h> #include <qpe/config.h> #include <qpe/qcopenvelope_qws.h> #include <libetpan/libetpan.h> #include "smtpwrapper.h" #include "mailwrapper.h" #include "abstractmail.h" #include "logindialog.h" #include "mailtypes.h" //#include "defines.h" #include "sendmailprogress.h" const char* SMTPwrapper::USER_AGENT="OpieMail v0.3"; progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() { settings = s; Config cfg( "mail" ); cfg.setGroup( "Status" ); m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); @@ -533,124 +534,145 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { msg = 0; if (later) { storeMail(data,size,"Outgoing"); if (data) free( data ); Config cfg( "mail" ); cfg.setGroup( "Status" ); cfg.writeEntry( "outgoing", ++m_queuedMail ); emit queuedMails( m_queuedMail ); return; } from = getFrom( mail ); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); smtpSend(from,rcpts,data,size,smtp); if (data) { free(data); } if (from) { free(from); } if (rcpts) smtp_address_list_free( rcpts ); } +void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) +{ + if (data) { + storeMail(data,size,"Sendfailed"); + } + if (failuremessage) { + QMessageBox::critical(0,tr("Error sending mail"), + tr("<center>%1</center>").arg(failuremessage)); + } +} + int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { const char *server, *user, *pass; bool ssl; uint16_t port; mailsmtp *session; int err,result; result = 1; server = user = pass = 0; server = smtp->getServer().latin1(); // FIXME: currently only TLS and Plain work. ssl = false; if ( smtp->ConnectionType() == 2 ) { ssl = true; } port = smtp->getPort().toUInt(); session = mailsmtp_new( 20, &progress ); if ( session == NULL ) goto free_mem; qDebug( "Servername %s at port %i", server, port ); if ( ssl ) { qDebug( "SSL session" ); err = mailsmtp_ssl_connect( session, server, port ); } else { qDebug( "No SSL session" ); err = mailsmtp_socket_connect( session, server, port ); } if ( err != MAILSMTP_NO_ERROR ) { qDebug("Error init connection"); + storeFailedMail(data,size,mailsmtpError(err)); result = 0; goto free_mem_session; } err = mailsmtp_init( session ); if ( err != MAILSMTP_NO_ERROR ) { + storeFailedMail(data,size,mailsmtpError(err)); result = 0; goto free_con_session; } qDebug( "INIT OK" ); if ( smtp->getLogin() ) { qDebug("smtp with auth"); if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { // get'em LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); login.show(); if ( QDialog::Accepted == login.exec() ) { // ok user = login.getUser().latin1(); pass = login.getPassword().latin1(); } else { result = 0; goto free_con_session; } } else { user = smtp->getUser().latin1(); pass = smtp->getPassword().latin1(); } qDebug( "session->auth: %i", session->auth); err = mailsmtp_auth( session, (char*)user, (char*)pass ); - if ( err == MAILSMTP_NO_ERROR ) + if ( err == MAILSMTP_NO_ERROR ) { qDebug("auth ok"); + } else { + storeFailedMail(data,size,tr("Authentification failed")); + result = 0; + goto free_con_session; + } qDebug( "Done auth!" ); } else { qDebug("SMTP without auth"); + result = 0; + goto free_con_session; } err = mailsmtp_send( session, from, rcpts, data, size ); if ( err != MAILSMTP_NO_ERROR ) { + storeFailedMail(data,size,mailsmtpError(err)); qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); result = 0; goto free_con_session; } qDebug( "Mail sent." ); storeMail(data,size,"Sent"); free_con_session: mailsmtp_quit( session ); free_mem_session: mailsmtp_free( session ); free_mem: return result; } void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { mailmime * mimeMail; SMTPaccount *smtp = aSmtp; if (!later && !smtp) { qDebug("Didn't get any send method - giving up"); return; 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 @@ -39,34 +39,35 @@ protected: mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); mailimf_fields *createImfFields(const Mail &mail ); mailmime *createMimeMail(const Mail&mail ); mailimf_address_list *parseAddresses(const QString&addr ); void addFileParts( mailmime *message,const QList<Attachment>&files ); mailmime *buildTxtPart(const QString&str ); mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); clist *createRcptList( mailimf_fields *fields ); static void storeMail(const char*mail, size_t length, const QString&box); static QString mailsmtpError( int err ); static void progress( size_t current, size_t maximum ); static void addRcpts( clist *list, mailimf_address_list *addr_list ); static char *getFrom( mailmime *mail ); static char *getFrom( mailimf_field *ffrom); static mailimf_field *getField( mailimf_fields *fields, int type ); int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); void storeMail(mailmime*mail, const QString&box); Settings *settings; int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); + void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); int m_queuedMail; static const char* USER_AGENT; protected slots: void emitQCop( int queued ); }; #endif |