-rw-r--r-- | noncore/net/mail/composemail.cpp | 4 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 156 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 27 | ||||
-rw-r--r-- | noncore/net/mail/opiemail.cpp | 5 |
4 files changed, 107 insertions, 85 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index 5e823e8..abcc3f6 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp @@ -222,4 +222,4 @@ void ComposeMail::accept() - SMTPwrapper wrapper( settings ); - wrapper.sendMail( *mail,smtp,checkBoxLater->isChecked() ); + SMTPwrapper wrapper( smtp ); + wrapper.sendMail( *mail,checkBoxLater->isChecked() ); diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 3ab6b77..a3c68ae 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -26,5 +26,6 @@ progressMailSend*SMTPwrapper::sendProgress = 0; -SMTPwrapper::SMTPwrapper( Settings *s ) -: QObject() { - settings = s; +SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp ) + : QObject() +{ + m_SmtpAccount = aSmtp; Config cfg( "mail" ); @@ -34,2 +35,8 @@ SMTPwrapper::SMTPwrapper( Settings *s ) connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); + m_smtp = 0; +} + +SMTPwrapper::~SMTPwrapper() +{ + disc_server(); } @@ -512,3 +519,3 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { -void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { +void SMTPwrapper::smtpSend( mailmime *mail,bool later) { clist *rcpts = 0; @@ -517,5 +524,2 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { - if ( smtp == NULL ) { - return; - } from = data = 0; @@ -547,3 +551,3 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); - smtpSend(from,rcpts,data,size,smtp); + smtpSend(from,rcpts,data,size); if (data) { @@ -569,8 +573,8 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char* -int SMTPwrapper::start_smtp_tls(mailsmtp *session) +int SMTPwrapper::start_smtp_tls() { - if (!session) { + if (!m_smtp) { return MAILSMTP_ERROR_IN_PROCESSING; } - int err = mailesmtp_starttls(session); + int err = mailesmtp_starttls(m_smtp); if (err != MAILSMTP_NO_ERROR) return err; @@ -578,3 +582,3 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session) mailstream_low * new_low; - low = mailstream_get_low(session->stream); + low = mailstream_get_low(m_smtp->stream); if (!low) { @@ -585,3 +589,3 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session) mailstream_low_free(low); - mailstream_set_low(session->stream, new_low); + mailstream_set_low(m_smtp->stream, new_low); } else { @@ -592,3 +596,4 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session) -int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { +void SMTPwrapper::connect_server() +{ const char *server, *user, *pass; @@ -596,12 +601,2 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT 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. - ssl = false; @@ -609,19 +604,26 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT bool force_tls=false; - - if ( smtp->ConnectionType() == 2 ) { + server = user = pass = 0; + QString failuretext = ""; + + if (m_smtp || !m_SmtpAccount) { + return; + } + server = m_SmtpAccount->getServer().latin1(); + if ( m_SmtpAccount->ConnectionType() == 2 ) { ssl = true; try_tls = false; - } else if (smtp->ConnectionType() == 1) { + } else if (m_SmtpAccount->ConnectionType() == 1) { force_tls = true; } + int result = 1; + port = m_SmtpAccount->getPort().toUInt(); - port = smtp->getPort().toUInt(); - - session = mailsmtp_new( 20, &progress ); - if ( session == NULL ) { + m_smtp = mailsmtp_new( 20, &progress ); + if ( m_smtp == NULL ) { /* no failure message cause this happens when problems with memory - than we we can not display any messagebox */ - return 0; + return; } + int err = MAILSMTP_NO_ERROR; qDebug( "Servername %s at port %i", server, port ); @@ -629,6 +631,6 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT qDebug( "SSL session" ); - err = mailsmtp_ssl_connect( session, server, port ); + err = mailsmtp_ssl_connect( m_smtp, server, port ); } else { qDebug( "No SSL session" ); - err = mailsmtp_socket_connect( session, server, port ); + err = mailsmtp_socket_connect( m_smtp, server, port ); } @@ -642,3 +644,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT if (result) { - err = mailsmtp_init( session ); + err = mailsmtp_init( m_smtp ); if (err != MAILSMTP_NO_ERROR) { @@ -650,3 +652,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT if (try_tls) { - err = start_smtp_tls(session); + err = start_smtp_tls(); if (err != MAILSMTP_NO_ERROR) { @@ -654,3 +656,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } else { - err = mailesmtp_ehlo(session); + err = mailesmtp_ehlo(m_smtp); } @@ -663,7 +665,8 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT - if (result==1 && smtp->getLogin() ) { + if (result==1 && m_SmtpAccount->getLogin() ) { qDebug("smtp with auth"); - if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { + if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) { // get'em - LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); + LoginDialog login( m_SmtpAccount->getUser(), + m_SmtpAccount->getPassword(), NULL, 0, true ); login.show(); @@ -678,8 +681,8 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } else { - user = smtp->getUser().latin1(); - pass = smtp->getPassword().latin1(); + user = m_SmtpAccount->getUser().latin1(); + pass = m_SmtpAccount->getPassword().latin1(); } - qDebug( "session->auth: %i", session->auth); + qDebug( "session->auth: %i", m_smtp->auth); if (result) { - err = mailsmtp_auth( session, (char*)user, (char*)pass ); + err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass ); if ( err == MAILSMTP_NO_ERROR ) { @@ -692,5 +695,23 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } +} - if (result) { - err = mailsmtp_send( session, from, rcpts, data, size ); +void SMTPwrapper::disc_server() +{ + if (m_smtp) { + mailsmtp_quit( m_smtp ); + mailsmtp_free( m_smtp ); + m_smtp = 0; + } +} + +int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size ) +{ + int err,result; + QString failuretext = ""; + + connect_server(); + + result = 1; + if (m_smtp) { + err = mailsmtp_send( m_smtp, from, rcpts, data, size ); if ( err != MAILSMTP_NO_ERROR ) { @@ -699,2 +720,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } + } else { + result = 0; } @@ -707,6 +730,2 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT } - if (session) { - mailsmtp_quit( session ); - mailsmtp_free( session ); - } return result; @@ -714,11 +733,6 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT -void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { +void SMTPwrapper::sendMail(const Mail&mail,bool later ) +{ mailmime * mimeMail; - SMTPaccount *smtp = aSmtp; - - if (!later && !smtp) { - qDebug("Didn't get any send method - giving up"); - return; - } mimeMail = createMimeMail(mail ); @@ -730,3 +744,3 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { sendProgress->setMaxMails(1); - smtpSend( mimeMail,later,smtp); + smtpSend( mimeMail,later); qDebug("Clean up done"); @@ -739,3 +753,3 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { -int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) { +int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) { size_t curTok = 0; @@ -762,3 +776,3 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which if (rcpts && from) { - res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); + res = smtpSend(from,rcpts,data->Content(),data->Length()); } @@ -781,3 +795,3 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which /* this is a special fun */ -bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { +bool SMTPwrapper::flushOutbox() { bool returnValue = true; @@ -785,3 +799,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { qDebug("Sending the queue"); - if (!smtp) { + if (!m_SmtpAccount) { qDebug("No smtp account given"); @@ -808,8 +822,8 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { - oldPw = smtp->getPassword(); - oldUser = smtp->getUser(); - if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) { + oldPw = m_SmtpAccount->getPassword(); + oldUser = m_SmtpAccount->getUser(); + if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) { // get'em QString user,pass; - LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); + LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true ); login.show(); @@ -820,4 +834,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { reset_user_value = true; - smtp->setUser(user); - smtp->setPassword(pass); + m_SmtpAccount->setUser(user); + m_SmtpAccount->setPassword(pass); } else { @@ -834,3 +848,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { while (mailsToSend.count()>0) { - if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { + if (sendQueuedMail(wrap,mailsToSend.at(0))==0) { QMessageBox::critical(0,tr("Error sending mail"), @@ -845,4 +859,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { if (reset_user_value) { - smtp->setUser(oldUser); - smtp->setPassword(oldPw); + m_SmtpAccount->setUser(oldUser); + m_SmtpAccount->setPassword(oldPw); } diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 75e4891..7f6aac1 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h @@ -1 +1,2 @@ +// -*- Mode: C++; -*- #ifndef SMTPwrapper_H @@ -22,2 +23,3 @@ class progressMailSend; struct mailsmtp; +class SMTPaccount; @@ -28,6 +30,6 @@ class SMTPwrapper : public QObject public: - SMTPwrapper( Settings *s ); - virtual ~SMTPwrapper(){} - void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); - bool flushOutbox(SMTPaccount*smtp); + SMTPwrapper(SMTPaccount * aSmtp); + virtual ~SMTPwrapper(); + void sendMail(const Mail& mail,bool later=false ); + bool flushOutbox(); @@ -39,2 +41,9 @@ signals: protected: + mailsmtp *m_smtp; + SMTPaccount * m_SmtpAccount; + + void connect_server(); + void disc_server(); + int start_smtp_tls(); + mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); @@ -47,3 +56,3 @@ protected: mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); - void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); + void smtpSend( mailmime *mail,bool later); clist *createRcptList( mailimf_fields *fields ); @@ -57,10 +66,8 @@ protected: static mailimf_field *getField( mailimf_fields *fields, int type ); - static int start_smtp_tls(mailsmtp *session); - int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); + int smtpSend(char*from,clist*rcpts,const char*data,size_t size); void storeMail(mailmime*mail, const QString&box); - Settings *settings; - int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); + int sendQueuedMail(AbstractMail*wrap,RecMail*which); void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); @@ -71,3 +78,3 @@ protected: protected slots: - void emitQCop( int queued ); + void emitQCop( int queued ); diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp index ea0019d..0795436 100644 --- a/noncore/net/mail/opiemail.cpp +++ b/noncore/net/mail/opiemail.cpp @@ -96,6 +96,7 @@ void OpieMail::slotSendQueued() if (smtp) { - SMTPwrapper * wrap = new SMTPwrapper(settings); - if ( wrap->flushOutbox(smtp) ) { + SMTPwrapper * wrap = new SMTPwrapper(smtp); + if ( wrap->flushOutbox() ) { QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); } + delete wrap; } |