-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 78 |
1 files changed, 52 insertions, 26 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 7671133..e8db9ca 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -20,6 +20,5 @@ #include "mailtypes.h" -//#include "defines.h" #include "sendmailprogress.h" -const char* SMTPwrapper::USER_AGENT="OpieMail v0.3"; +const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; @@ -574,2 +573,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT int err,result; + QString failuretext = ""; @@ -590,4 +590,7 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT session = mailsmtp_new( 20, &progress ); - if ( session == NULL ) - goto free_mem; + if ( session == NULL ) { + /* no failure message cause this happens when problems with memory - than we + we can not display any messagebox */ + return 0; + } @@ -603,17 +606,15 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT qDebug("Error init connection"); - storeFailedMail(data,size,mailsmtpError(err)); + failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); result = 0; - goto free_mem_session; } + if (result) { err = mailsmtp_init( session ); if ( err != MAILSMTP_NO_ERROR ) { - storeFailedMail(data,size,mailsmtpError(err)); result = 0; - goto free_con_session; + failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); + } } - qDebug( "INIT OK" ); - - if ( smtp->getLogin() ) { + if (result==1 && smtp->getLogin() ) { qDebug("smtp with auth"); @@ -629,3 +630,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT result = 0; - goto free_con_session; + failuretext=tr("Login aborted - storing mail to localfolder"); } @@ -636,2 +637,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT qDebug( "session->auth: %i", session->auth); + if (result) { err = mailsmtp_auth( session, (char*)user, (char*)pass ); @@ -640,29 +642,26 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } else { - storeFailedMail(data,size,tr("Authentification failed")); + failuretext = tr("Authentification failed"); result = 0; - goto free_con_session; } - qDebug( "Done auth!" ); - } else { - qDebug("SMTP without auth"); - result = 0; - goto free_con_session; + } } + if (result) { 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()); + failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); result = 0; - goto free_con_session; + } } + if (!result) { + storeFailedMail(data,size,failuretext); + } else { qDebug( "Mail sent." ); storeMail(data,size,"Sent"); - -free_con_session: + } + if (session) { mailsmtp_quit( session ); -free_mem_session: mailsmtp_free( session ); -free_mem: + } return result; @@ -743,2 +742,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { + bool reset_user_value = false; QString localfolders = AbstractMail::defaultLocalfolder(); @@ -749,2 +749,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { } + QString oldPw, oldUser; QList<RecMail> mailsToSend; @@ -757,2 +758,23 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { } + + oldPw = smtp->getPassword(); + oldUser = smtp->getUser(); + if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) { + // get'em + QString user,pass; + 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(); + reset_user_value = true; + smtp->setUser(user); + smtp->setPassword(pass); + } else { + return true; + } + } + + mailsToSend.setAutoDelete(false); @@ -773,2 +795,6 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { } + if (reset_user_value) { + smtp->setUser(oldUser); + smtp->setPassword(oldPw); + } Config cfg( "mail" ); |