author | alwin <alwin> | 2004-01-12 14:36:22 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-12 14:36:22 (UTC) |
commit | 713a845a0d2ad3aba8230a5ba743a1c7b1622ef1 (patch) (unidiff) | |
tree | 99b6072598bbac82a5beaf22aa432d808c1ad9b3 /noncore/net/mail | |
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.
-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 @@ | |||
15 | 15 | ||
16 | #include "smtpwrapper.h" | 16 | #include "smtpwrapper.h" |
17 | #include "mailwrapper.h" | 17 | #include "mailwrapper.h" |
18 | #include "abstractmail.h" | 18 | #include "abstractmail.h" |
19 | #include "logindialog.h" | 19 | #include "logindialog.h" |
20 | #include "mailtypes.h" | 20 | #include "mailtypes.h" |
21 | //#include "defines.h" | ||
22 | #include "sendmailprogress.h" | 21 | #include "sendmailprogress.h" |
23 | 22 | ||
24 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.3"; | 23 | const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; |
25 | 24 | ||
26 | progressMailSend*SMTPwrapper::sendProgress = 0; | 25 | progressMailSend*SMTPwrapper::sendProgress = 0; |
27 | 26 | ||
28 | SMTPwrapper::SMTPwrapper( Settings *s ) | 27 | SMTPwrapper::SMTPwrapper( Settings *s ) |
29 | : QObject() { | 28 | : QObject() { |
30 | settings = s; | 29 | settings = s; |
@@ -569,12 +568,13 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char* | |||
569 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { | 568 | int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMTPaccount *smtp ) { |
570 | const char *server, *user, *pass; | 569 | const char *server, *user, *pass; |
571 | bool ssl; | 570 | bool ssl; |
572 | uint16_t port; | 571 | uint16_t port; |
573 | mailsmtp *session; | 572 | mailsmtp *session; |
574 | int err,result; | 573 | int err,result; |
574 | QString failuretext = ""; | ||
575 | 575 | ||
576 | result = 1; | 576 | result = 1; |
577 | server = user = pass = 0; | 577 | server = user = pass = 0; |
578 | server = smtp->getServer().latin1(); | 578 | server = smtp->getServer().latin1(); |
579 | 579 | ||
580 | // FIXME: currently only TLS and Plain work. | 580 | // 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 | |||
585 | ssl = true; | 585 | ssl = true; |
586 | } | 586 | } |
587 | 587 | ||
588 | port = smtp->getPort().toUInt(); | 588 | port = smtp->getPort().toUInt(); |
589 | 589 | ||
590 | session = mailsmtp_new( 20, &progress ); | 590 | session = mailsmtp_new( 20, &progress ); |
591 | if ( session == NULL ) | 591 | if ( session == NULL ) { |
592 | goto free_mem; | 592 | /* no failure message cause this happens when problems with memory - than we |
593 | we can not display any messagebox */ | ||
594 | return 0; | ||
595 | } | ||
593 | 596 | ||
594 | qDebug( "Servername %s at port %i", server, port ); | 597 | qDebug( "Servername %s at port %i", server, port ); |
595 | if ( ssl ) { | 598 | if ( ssl ) { |
596 | qDebug( "SSL session" ); | 599 | qDebug( "SSL session" ); |
597 | err = mailsmtp_ssl_connect( session, server, port ); | 600 | err = mailsmtp_ssl_connect( session, server, port ); |
598 | } else { | 601 | } else { |
599 | qDebug( "No SSL session" ); | 602 | qDebug( "No SSL session" ); |
600 | err = mailsmtp_socket_connect( session, server, port ); | 603 | err = mailsmtp_socket_connect( session, server, port ); |
601 | } | 604 | } |
602 | if ( err != MAILSMTP_NO_ERROR ) { | 605 | if ( err != MAILSMTP_NO_ERROR ) { |
603 | qDebug("Error init connection"); | 606 | qDebug("Error init connection"); |
604 | storeFailedMail(data,size,mailsmtpError(err)); | 607 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
605 | result = 0; | 608 | result = 0; |
606 | goto free_mem_session; | ||
607 | } | 609 | } |
608 | 610 | ||
611 | if (result) { | ||
609 | err = mailsmtp_init( session ); | 612 | err = mailsmtp_init( session ); |
610 | if ( err != MAILSMTP_NO_ERROR ) { | 613 | if ( err != MAILSMTP_NO_ERROR ) { |
611 | storeFailedMail(data,size,mailsmtpError(err)); | ||
612 | result = 0; | 614 | result = 0; |
613 | goto free_con_session; | 615 | failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); |
616 | } | ||
614 | } | 617 | } |
615 | 618 | ||
616 | qDebug( "INIT OK" ); | 619 | if (result==1 && smtp->getLogin() ) { |
617 | |||
618 | if ( smtp->getLogin() ) { | ||
619 | qDebug("smtp with auth"); | 620 | qDebug("smtp with auth"); |
620 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { | 621 | if ( smtp->getUser().isEmpty() || smtp->getPassword().isEmpty() ) { |
621 | // get'em | 622 | // get'em |
622 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | 623 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); |
623 | login.show(); | 624 | login.show(); |
624 | if ( QDialog::Accepted == login.exec() ) { | 625 | if ( QDialog::Accepted == login.exec() ) { |
625 | // ok | 626 | // ok |
626 | user = login.getUser().latin1(); | 627 | user = login.getUser().latin1(); |
627 | pass = login.getPassword().latin1(); | 628 | pass = login.getPassword().latin1(); |
628 | } else { | 629 | } else { |
629 | result = 0; | 630 | result = 0; |
630 | goto free_con_session; | 631 | failuretext=tr("Login aborted - storing mail to localfolder"); |
631 | } | 632 | } |
632 | } else { | 633 | } else { |
633 | user = smtp->getUser().latin1(); | 634 | user = smtp->getUser().latin1(); |
634 | pass = smtp->getPassword().latin1(); | 635 | pass = smtp->getPassword().latin1(); |
635 | } | 636 | } |
636 | qDebug( "session->auth: %i", session->auth); | 637 | qDebug( "session->auth: %i", session->auth); |
638 | if (result) { | ||
637 | err = mailsmtp_auth( session, (char*)user, (char*)pass ); | 639 | err = mailsmtp_auth( session, (char*)user, (char*)pass ); |
638 | if ( err == MAILSMTP_NO_ERROR ) { | 640 | if ( err == MAILSMTP_NO_ERROR ) { |
639 | qDebug("auth ok"); | 641 | qDebug("auth ok"); |
640 | } else { | 642 | } else { |
641 | storeFailedMail(data,size,tr("Authentification failed")); | 643 | failuretext = tr("Authentification failed"); |
642 | result = 0; | 644 | result = 0; |
643 | goto free_con_session; | ||
644 | } | 645 | } |
645 | qDebug( "Done auth!" ); | 646 | } |
646 | } else { | ||
647 | qDebug("SMTP without auth"); | ||
648 | result = 0; | ||
649 | goto free_con_session; | ||
650 | } | 647 | } |
651 | 648 | ||
649 | if (result) { | ||
652 | err = mailsmtp_send( session, from, rcpts, data, size ); | 650 | err = mailsmtp_send( session, from, rcpts, data, size ); |
653 | if ( err != MAILSMTP_NO_ERROR ) { | 651 | if ( err != MAILSMTP_NO_ERROR ) { |
654 | storeFailedMail(data,size,mailsmtpError(err)); | 652 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
655 | qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); | ||
656 | result = 0; | 653 | result = 0; |
657 | goto free_con_session; | 654 | } |
658 | } | 655 | } |
659 | 656 | ||
657 | if (!result) { | ||
658 | storeFailedMail(data,size,failuretext); | ||
659 | } else { | ||
660 | qDebug( "Mail sent." ); | 660 | qDebug( "Mail sent." ); |
661 | storeMail(data,size,"Sent"); | 661 | storeMail(data,size,"Sent"); |
662 | 662 | } | |
663 | free_con_session: | 663 | if (session) { |
664 | mailsmtp_quit( session ); | 664 | mailsmtp_quit( session ); |
665 | free_mem_session: | ||
666 | mailsmtp_free( session ); | 665 | mailsmtp_free( session ); |
667 | free_mem: | 666 | } |
668 | return result; | 667 | return result; |
669 | } | 668 | } |
670 | 669 | ||
671 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { | 670 | void SMTPwrapper::sendMail(const Mail&mail,SMTPaccount*aSmtp,bool later ) { |
672 | mailmime * mimeMail; | 671 | mailmime * mimeMail; |
673 | 672 | ||
@@ -738,26 +737,49 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which | |||
738 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | 737 | bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { |
739 | bool returnValue = true; | 738 | bool returnValue = true; |
740 | 739 | ||
741 | if (!smtp) | 740 | if (!smtp) |
742 | return false; | 741 | return false; |
743 | 742 | ||
743 | bool reset_user_value = false; | ||
744 | QString localfolders = AbstractMail::defaultLocalfolder(); | 744 | QString localfolders = AbstractMail::defaultLocalfolder(); |
745 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); | 745 | AbstractMail*wrap = AbstractMail::getWrapper(localfolders); |
746 | if (!wrap) { | 746 | if (!wrap) { |
747 | qDebug("memory error"); | 747 | qDebug("memory error"); |
748 | return false; | 748 | return false; |
749 | } | 749 | } |
750 | QString oldPw, oldUser; | ||
750 | QList<RecMail> mailsToSend; | 751 | QList<RecMail> mailsToSend; |
751 | QList<RecMail> mailsToRemove; | 752 | QList<RecMail> mailsToRemove; |
752 | QString mbox("Outgoing"); | 753 | QString mbox("Outgoing"); |
753 | wrap->listMessages(mbox,mailsToSend); | 754 | wrap->listMessages(mbox,mailsToSend); |
754 | if (mailsToSend.count()==0) { | 755 | if (mailsToSend.count()==0) { |
755 | delete wrap; | 756 | delete wrap; |
756 | return false; | 757 | return false; |
757 | } | 758 | } |
759 | |||
760 | oldPw = smtp->getPassword(); | ||
761 | oldUser = smtp->getUser(); | ||
762 | if (smtp->getLogin() && (smtp->getUser().isEmpty() || smtp->getPassword().isEmpty()) ) { | ||
763 | // get'em | ||
764 | QString user,pass; | ||
765 | LoginDialog login( smtp->getUser(), smtp->getPassword(), NULL, 0, true ); | ||
766 | login.show(); | ||
767 | if ( QDialog::Accepted == login.exec() ) { | ||
768 | // ok | ||
769 | user = login.getUser().latin1(); | ||
770 | pass = login.getPassword().latin1(); | ||
771 | reset_user_value = true; | ||
772 | smtp->setUser(user); | ||
773 | smtp->setPassword(pass); | ||
774 | } else { | ||
775 | return true; | ||
776 | } | ||
777 | } | ||
778 | |||
779 | |||
758 | mailsToSend.setAutoDelete(false); | 780 | mailsToSend.setAutoDelete(false); |
759 | sendProgress = new progressMailSend(); | 781 | sendProgress = new progressMailSend(); |
760 | sendProgress->show(); | 782 | sendProgress->show(); |
761 | sendProgress->setMaxMails(mailsToSend.count()); | 783 | sendProgress->setMaxMails(mailsToSend.count()); |
762 | 784 | ||
763 | while (mailsToSend.count()>0) { | 785 | while (mailsToSend.count()>0) { |
@@ -768,12 +790,16 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
768 | break; | 790 | break; |
769 | } | 791 | } |
770 | mailsToRemove.append(mailsToSend.at(0)); | 792 | mailsToRemove.append(mailsToSend.at(0)); |
771 | mailsToSend.removeFirst(); | 793 | mailsToSend.removeFirst(); |
772 | sendProgress->setCurrentMails(mailsToRemove.count()); | 794 | sendProgress->setCurrentMails(mailsToRemove.count()); |
773 | } | 795 | } |
796 | if (reset_user_value) { | ||
797 | smtp->setUser(oldUser); | ||
798 | smtp->setPassword(oldPw); | ||
799 | } | ||
774 | Config cfg( "mail" ); | 800 | Config cfg( "mail" ); |
775 | cfg.setGroup( "Status" ); | 801 | cfg.setGroup( "Status" ); |
776 | m_queuedMail = 0; | 802 | m_queuedMail = 0; |
777 | cfg.writeEntry( "outgoing", m_queuedMail ); | 803 | cfg.writeEntry( "outgoing", m_queuedMail ); |
778 | emit queuedMails( m_queuedMail ); | 804 | emit queuedMails( m_queuedMail ); |
779 | sendProgress->hide(); | 805 | sendProgress->hide(); |