summaryrefslogtreecommitdiff
authoralwin <alwin>2004-02-13 02:52:41 (UTC)
committer alwin <alwin>2004-02-13 02:52:41 (UTC)
commitaca5ba5ed24b4da61517560ea91f566afd132d28 (patch) (unidiff)
tree86085c6042e591dc9f211a8716cb63ff30cb5f4e
parent2fd9c32e07714b7caf38994c0b0f1da8ffb27aa9 (diff)
downloadopie-aca5ba5ed24b4da61517560ea91f566afd132d28.zip
opie-aca5ba5ed24b4da61517560ea91f566afd132d28.tar.gz
opie-aca5ba5ed24b4da61517560ea91f566afd132d28.tar.bz2
interface changes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/composemail.cpp4
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp156
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h27
-rw-r--r--noncore/net/mail/opiemail.cpp5
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()
222 222
223 SMTPwrapper wrapper( settings ); 223 SMTPwrapper wrapper( smtp );
224 wrapper.sendMail( *mail,smtp,checkBoxLater->isChecked() ); 224 wrapper.sendMail( *mail,checkBoxLater->isChecked() );
225 225
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;
26 26
27SMTPwrapper::SMTPwrapper( Settings *s ) 27SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp )
28: QObject() { 28 : QObject()
29 settings = s; 29{
30 m_SmtpAccount = aSmtp;
30 Config cfg( "mail" ); 31 Config cfg( "mail" );
@@ -34,2 +35,8 @@ SMTPwrapper::SMTPwrapper( Settings *s )
34 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); 35 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
36 m_smtp = 0;
37}
38
39SMTPwrapper::~SMTPwrapper()
40{
41 disc_server();
35} 42}
@@ -512,3 +519,3 @@ void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
512 519
513void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { 520void SMTPwrapper::smtpSend( mailmime *mail,bool later) {
514 clist *rcpts = 0; 521 clist *rcpts = 0;
@@ -517,5 +524,2 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
517 524
518 if ( smtp == NULL ) {
519 return;
520 }
521 from = data = 0; 525 from = data = 0;
@@ -547,3 +551,3 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
547 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 551 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
548 smtpSend(from,rcpts,data,size,smtp); 552 smtpSend(from,rcpts,data,size);
549 if (data) { 553 if (data) {
@@ -569,8 +573,8 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*
569 573
570int SMTPwrapper::start_smtp_tls(mailsmtp *session) 574int SMTPwrapper::start_smtp_tls()
571{ 575{
572 if (!session) { 576 if (!m_smtp) {
573 return MAILSMTP_ERROR_IN_PROCESSING; 577 return MAILSMTP_ERROR_IN_PROCESSING;
574 } 578 }
575 int err = mailesmtp_starttls(session); 579 int err = mailesmtp_starttls(m_smtp);
576 if (err != MAILSMTP_NO_ERROR) return err; 580 if (err != MAILSMTP_NO_ERROR) return err;
@@ -578,3 +582,3 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session)
578 mailstream_low * new_low; 582 mailstream_low * new_low;
579 low = mailstream_get_low(session->stream); 583 low = mailstream_get_low(m_smtp->stream);
580 if (!low) { 584 if (!low) {
@@ -585,3 +589,3 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session)
585 mailstream_low_free(low); 589 mailstream_low_free(low);
586 mailstream_set_low(session->stream, new_low); 590 mailstream_set_low(m_smtp->stream, new_low);
587 } else { 591 } else {
@@ -592,3 +596,4 @@ int SMTPwrapper::start_smtp_tls(mailsmtp *session)
592 596
593int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { 597void SMTPwrapper::connect_server()
598{
594 const char *server, *user, *pass; 599 const char *server, *user, *pass;
@@ -596,12 +601,2 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
596 uint16_t port; 601 uint16_t port;
597 mailsmtp *session;
598 int err,result;
599 QString failuretext = "";
600
601 result = 1;
602 server = user = pass = 0;
603 server = smtp->getServer().latin1();
604
605 // FIXME: currently only TLS and Plain work.
606
607 ssl = false; 602 ssl = false;
@@ -609,19 +604,26 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
609 bool force_tls=false; 604 bool force_tls=false;
610 605 server = user = pass = 0;
611 if ( smtp->ConnectionType() == 2 ) { 606 QString failuretext = "";
607
608 if (m_smtp || !m_SmtpAccount) {
609 return;
610 }
611 server = m_SmtpAccount->getServer().latin1();
612 if ( m_SmtpAccount->ConnectionType() == 2 ) {
612 ssl = true; 613 ssl = true;
613 try_tls = false; 614 try_tls = false;
614 } else if (smtp->ConnectionType() == 1) { 615 } else if (m_SmtpAccount->ConnectionType() == 1) {
615 force_tls = true; 616 force_tls = true;
616 } 617 }
618 int result = 1;
619 port = m_SmtpAccount->getPort().toUInt();
617 620
618 port = smtp->getPort().toUInt(); 621 m_smtp = mailsmtp_new( 20, &progress );
619 622 if ( m_smtp == NULL ) {
620 session = mailsmtp_new( 20, &progress );
621 if ( session == NULL ) {
622 /* no failure message cause this happens when problems with memory - than we 623 /* no failure message cause this happens when problems with memory - than we
623 we can not display any messagebox */ 624 we can not display any messagebox */
624 return 0; 625 return;
625 } 626 }
626 627
628 int err = MAILSMTP_NO_ERROR;
627 qDebug( "Servername %s at port %i", server, port ); 629 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
629 qDebug( "SSL session" ); 631 qDebug( "SSL session" );
630 err = mailsmtp_ssl_connect( session, server, port ); 632 err = mailsmtp_ssl_connect( m_smtp, server, port );
631 } else { 633 } else {
632 qDebug( "No SSL session" ); 634 qDebug( "No SSL session" );
633 err = mailsmtp_socket_connect( session, server, port ); 635 err = mailsmtp_socket_connect( m_smtp, server, port );
634 } 636 }
@@ -642,3 +644,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
642 if (result) { 644 if (result) {
643 err = mailsmtp_init( session ); 645 err = mailsmtp_init( m_smtp );
644 if (err != MAILSMTP_NO_ERROR) { 646 if (err != MAILSMTP_NO_ERROR) {
@@ -650,3 +652,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
650 if (try_tls) { 652 if (try_tls) {
651 err = start_smtp_tls(session); 653 err = start_smtp_tls();
652 if (err != MAILSMTP_NO_ERROR) { 654 if (err != MAILSMTP_NO_ERROR) {
@@ -654,3 +656,3 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
654 } else { 656 } else {
655 err = mailesmtp_ehlo(session); 657 err = mailesmtp_ehlo(m_smtp);
656 } 658 }
@@ -663,7 +665,8 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
663 665
664 if (result==1 && smtp->getLogin() ) { 666 if (result==1 && m_SmtpAccount->getLogin() ) {
665 qDebug("smtp with auth"); 667 qDebug("smtp with auth");
666 if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { 668 if ( m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty() ) {
667 // get'em 669 // get'em
668 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 670 LoginDialog login( m_SmtpAccount->getUser(),
671 m_SmtpAccount->getPassword(), NULL, 0, true );
669 login.show(); 672 login.show();
@@ -678,8 +681,8 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
678 } else { 681 } else {
679 user = smtp->getUser().latin1(); 682 user = m_SmtpAccount->getUser().latin1();
680 pass = smtp->getPassword().latin1(); 683 pass = m_SmtpAccount->getPassword().latin1();
681 } 684 }
682 qDebug( "session->auth: %i", session->auth); 685 qDebug( "session->auth: %i", m_smtp->auth);
683 if (result) { 686 if (result) {
684 err = mailsmtp_auth( session, (char*)user, (char*)pass ); 687 err = mailsmtp_auth( m_smtp, (char*)user, (char*)pass );
685 if ( err == MAILSMTP_NO_ERROR ) { 688 if ( err == MAILSMTP_NO_ERROR ) {
@@ -692,5 +695,23 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
692 } 695 }
696}
693 697
694 if (result) { 698void SMTPwrapper::disc_server()
695 err = mailsmtp_send( session, from, rcpts, data, size ); 699{
700 if (m_smtp) {
701 mailsmtp_quit( m_smtp );
702 mailsmtp_free( m_smtp );
703 m_smtp = 0;
704 }
705}
706
707int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size )
708{
709 int err,result;
710 QString failuretext = "";
711
712 connect_server();
713
714 result = 1;
715 if (m_smtp) {
716 err = mailsmtp_send( m_smtp, from, rcpts, data, size );
696 if ( err != MAILSMTP_NO_ERROR ) { 717 if ( err != MAILSMTP_NO_ERROR ) {
@@ -699,2 +720,4 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
699 } 720 }
721 } else {
722 result = 0;
700 } 723 }
@@ -707,6 +730,2 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
707 } 730 }
708 if (session) {
709 mailsmtp_quit( session );
710 mailsmtp_free( session );
711 }
712 return result; 731 return result;
@@ -714,11 +733,6 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT
714 733
715void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { 734void SMTPwrapper::sendMail(const Mail&mail,bool later )
735{
716 mailmime * mimeMail; 736 mailmime * mimeMail;
717 737
718 SMTPaccount *smtp = aSmtp;
719
720 if (!later && !smtp) {
721 qDebug("Didn't get any send method - giving up");
722 return;
723 }
724 mimeMail = createMimeMail(mail ); 738 mimeMail = createMimeMail(mail );
@@ -730,3 +744,3 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) {
730 sendProgress->setMaxMails(1); 744 sendProgress->setMaxMails(1);
731 smtpSend( mimeMail,later,smtp); 745 smtpSend( mimeMail,later);
732 qDebug("Clean up done"); 746 qDebug("Clean up done");
@@ -739,3 +753,3 @@ void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) {
739 753
740int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which) { 754int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,RecMail*which) {
741 size_t curTok = 0; 755 size_t curTok = 0;
@@ -762,3 +776,3 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
762 if (rcpts && from) { 776 if (rcpts && from) {
763 res = smtpSend(from,rcpts,data->Content(),data->Length(),smtp ); 777 res = smtpSend(from,rcpts,data->Content(),data->Length());
764 } 778 }
@@ -781,3 +795,3 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which
781/* this is a special fun */ 795/* this is a special fun */
782bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { 796bool SMTPwrapper::flushOutbox() {
783 bool returnValue = true; 797 bool returnValue = true;
@@ -785,3 +799,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
785 qDebug("Sending the queue"); 799 qDebug("Sending the queue");
786 if (!smtp) { 800 if (!m_SmtpAccount) {
787 qDebug("No smtp account given"); 801 qDebug("No smtp account given");
@@ -808,8 +822,8 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
808 822
809 oldPw = smtp->getPassword(); 823 oldPw = m_SmtpAccount->getPassword();
810 oldUser = smtp->getUser(); 824 oldUser = m_SmtpAccount->getUser();
811 if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) { 825 if (m_SmtpAccount->getLogin() && (m_SmtpAccount->getUser().isEmpty() || m_SmtpAccount->getPassword().isEmpty()) ) {
812 // get'em 826 // get'em
813 QString user,pass; 827 QString user,pass;
814 LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); 828 LoginDialog login( m_SmtpAccount->getUser(), m_SmtpAccount->getPassword(), NULL, 0, true );
815 login.show(); 829 login.show();
@@ -820,4 +834,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
820 reset_user_value = true; 834 reset_user_value = true;
821 smtp->setUser(user); 835 m_SmtpAccount->setUser(user);
822 smtp->setPassword(pass); 836 m_SmtpAccount->setPassword(pass);
823 } else { 837 } else {
@@ -834,3 +848,3 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
834 while (mailsToSend.count()>0) { 848 while (mailsToSend.count()>0) {
835 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 849 if (sendQueuedMail(wrap,mailsToSend.at(0))==0) {
836 QMessageBox::critical(0,tr("Error sending mail"), 850 QMessageBox::critical(0,tr("Error sending mail"),
@@ -845,4 +859,4 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) {
845 if (reset_user_value) { 859 if (reset_user_value) {
846 smtp->setUser(oldUser); 860 m_SmtpAccount->setUser(oldUser);
847 smtp->setPassword(oldPw); 861 m_SmtpAccount->setPassword(oldPw);
848 } 862 }
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 @@
1// -*- Mode: C++; -*-
1#ifndef SMTPwrapper_H 2#ifndef SMTPwrapper_H
@@ -22,2 +23,3 @@ class progressMailSend;
22struct mailsmtp; 23struct mailsmtp;
24class SMTPaccount;
23 25
@@ -28,6 +30,6 @@ class SMTPwrapper : public QObject
28public: 30public:
29 SMTPwrapper( Settings *s ); 31 SMTPwrapper(SMTPaccount * aSmtp);
30 virtual ~SMTPwrapper(){} 32 virtual ~SMTPwrapper();
31 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); 33 void sendMail(const Mail& mail,bool later=false );
32 bool flushOutbox(SMTPaccount*smtp); 34 bool flushOutbox();
33 35
@@ -39,2 +41,9 @@ signals:
39protected: 41protected:
42 mailsmtp *m_smtp;
43 SMTPaccount * m_SmtpAccount;
44
45 void connect_server();
46 void disc_server();
47 int start_smtp_tls();
48
40 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 49 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
@@ -47,3 +56,3 @@ protected:
47 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 56 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
48 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 57 void smtpSend( mailmime *mail,bool later);
49 clist *createRcptList( mailimf_fields *fields ); 58 clist *createRcptList( mailimf_fields *fields );
@@ -57,10 +66,8 @@ protected:
57 static mailimf_field *getField( mailimf_fields *fields, int type ); 66 static mailimf_field *getField( mailimf_fields *fields, int type );
58 static int start_smtp_tls(mailsmtp *session);
59 67
60 int smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ); 68 int smtpSend(char*from,clist*rcpts,const char*data,size_t size);
61 69
62 void storeMail(mailmime*mail, const QString&box); 70 void storeMail(mailmime*mail, const QString&box);
63 Settings *settings;
64 71
65 int sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which); 72 int sendQueuedMail(AbstractMail*wrap,RecMail*which);
66 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage); 73 void storeFailedMail(const char*data,unsigned int size, const char*failuremessage);
@@ -71,3 +78,3 @@ protected:
71protected slots: 78protected slots:
72 void emitQCop( int queued ); 79 void emitQCop( int queued );
73 80
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()
96 if (smtp) { 96 if (smtp) {
97 SMTPwrapper * wrap = new SMTPwrapper(settings); 97 SMTPwrapper * wrap = new SMTPwrapper(smtp);
98 if ( wrap->flushOutbox(smtp) ) { 98 if ( wrap->flushOutbox() ) {
99 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed")); 99 QMessageBox::information(0,tr("Info"),tr("Mail queue flushed"));
100 } 100 }
101 delete wrap;
101 } 102 }