-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 108 |
1 files changed, 67 insertions, 41 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 | |||
@@ -18,10 +18,9 @@ | |||
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 | ||
@@ -572,6 +571,7 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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; |
@@ -588,8 +588,11 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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 ) { |
@@ -601,21 +604,19 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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 | ||
609 | err = mailsmtp_init( session ); | 611 | if (result) { |
610 | if ( err != MAILSMTP_NO_ERROR ) { | 612 | err = mailsmtp_init( session ); |
611 | storeFailedMail(data,size,mailsmtpError(err)); | 613 | if (err != MAILSMTP_NO_ERROR) { |
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 |
@@ -627,44 +628,42 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,const char*data,size_t size, SMT | |||
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); |
637 | err = mailsmtp_auth( session, (char*)user, (char*)pass ); | 638 | if (result) { |
638 | if ( err == MAILSMTP_NO_ERROR ) { | 639 | err = mailsmtp_auth( session, (char*)user, (char*)pass ); |
639 | qDebug("auth ok"); | 640 | if ( err == MAILSMTP_NO_ERROR ) { |
640 | } else { | 641 | qDebug("auth ok"); |
641 | storeFailedMail(data,size,tr("Authentification failed")); | 642 | } else { |
642 | result = 0; | 643 | failuretext = tr("Authentification failed"); |
643 | goto free_con_session; | 644 | result = 0; |
645 | } | ||
644 | } | 646 | } |
645 | qDebug( "Done auth!" ); | ||
646 | } else { | ||
647 | qDebug("SMTP without auth"); | ||
648 | result = 0; | ||
649 | goto free_con_session; | ||
650 | } | 647 | } |
651 | 648 | ||
652 | err = mailsmtp_send( session, from, rcpts, data, size ); | 649 | if (result) { |
653 | if ( err != MAILSMTP_NO_ERROR ) { | 650 | err = mailsmtp_send( session, from, rcpts, data, size ); |
654 | storeFailedMail(data,size,mailsmtpError(err)); | 651 | if ( err != MAILSMTP_NO_ERROR ) { |
655 | qDebug("Error sending mail: %s",mailsmtpError(err).latin1()); | 652 | failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); |
656 | result = 0; | 653 | result = 0; |
657 | goto free_con_session; | 654 | } |
658 | } | 655 | } |
659 | 656 | ||
660 | qDebug( "Mail sent." ); | 657 | if (!result) { |
661 | storeMail(data,size,"Sent"); | 658 | storeFailedMail(data,size,failuretext); |
662 | 659 | } else { | |
663 | free_con_session: | 660 | qDebug( "Mail sent." ); |
664 | mailsmtp_quit( session ); | 661 | storeMail(data,size,"Sent"); |
665 | free_mem_session: | 662 | } |
666 | mailsmtp_free( session ); | 663 | if (session) { |
667 | free_mem: | 664 | mailsmtp_quit( session ); |
665 | mailsmtp_free( session ); | ||
666 | } | ||
668 | return result; | 667 | return result; |
669 | } | 668 | } |
670 | 669 | ||
@@ -741,12 +740,14 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
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"); |
@@ -755,6 +756,27 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
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(); |
@@ -771,6 +793,10 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) { | |||
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; |