author | alwin <alwin> | 2004-01-12 14:36:22 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-12 14:36:22 (UTC) |
commit | 713a845a0d2ad3aba8230a5ba743a1c7b1622ef1 (patch) (side-by-side diff) | |
tree | 99b6072598bbac82a5beaf22aa432d808c1ad9b3 /noncore/net/mail/libmailwrapper | |
parent | 2a0686efdcce2c6bd572468d0f340f3188d00c8c (diff) | |
download | opie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.zip opie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.tar.gz opie-713a845a0d2ad3aba8230a5ba743a1c7b1622ef1.tar.bz2 |
generating clean failuremessages
bugfix - smtp without login was resolved as wrong
when sending enqueued mails login will asked when starting flush not
on every mail.
Diffstat (limited to 'noncore/net/mail/libmailwrapper') (more/less context) (show whitespace changes)
-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 @@ -15,16 +15,15 @@ #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"; +const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() { settings = s; @@ -569,12 +568,13 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char* 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; + QString failuretext = ""; result = 1; server = user = pass = 0; server = smtp->getServer().latin1(); // FIXME: currently only TLS and Plain work. @@ -585,89 +585,88 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT ssl = true; } port = smtp->getPort().toUInt(); 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; + } 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)); + 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"); 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; + failuretext=tr("Login aborted - storing mail to localfolder"); } } else { user = smtp->getUser().latin1(); pass = smtp->getPassword().latin1(); } qDebug( "session->auth: %i", session->auth); + if (result) { err = mailsmtp_auth( session, (char*)user, (char*)pass ); if ( err == MAILSMTP_NO_ERROR ) { qDebug("auth ok"); } 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; } void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { mailmime * mimeMail; @@ -738,26 +737,49 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { bool returnValue = true; if (!smtp) return false; + bool reset_user_value = false; QString localfolders = AbstractMail::defaultLocalfolder(); AbstractMail*wrap = AbstractMail::getWrapper(localfolders); if (!wrap) { qDebug("memory error"); return false; } + QString oldPw, oldUser; QList<RecMail> mailsToSend; QList<RecMail> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; return false; } + + 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); sendProgress = new progressMailSend(); sendProgress->show(); sendProgress->setMaxMails(mailsToSend.count()); while (mailsToSend.count()>0) { @@ -768,12 +790,16 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { break; } mailsToRemove.append(mailsToSend.at(0)); mailsToSend.removeFirst(); sendProgress->setCurrentMails(mailsToRemove.count()); } + if (reset_user_value) { + smtp->setUser(oldUser); + smtp->setPassword(oldPw); + } Config cfg( "mail" ); cfg.setGroup( "Status" ); m_queuedMail = 0; cfg.writeEntry( "outgoing", m_queuedMail ); emit queuedMails( m_queuedMail ); sendProgress->hide(); |