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 | |
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 | 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 | |||
@@ -9,28 +9,27 @@ | |||
9 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
10 | 10 | ||
11 | #include <qpe/config.h> | 11 | #include <qpe/config.h> |
12 | #include <qpe/qcopenvelope_qws.h> | 12 | #include <qpe/qcopenvelope_qws.h> |
13 | 13 | ||
14 | #include <libetpan/libetpan.h> | 14 | #include <libetpan/libetpan.h> |
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; |
31 | Config cfg( "mail" ); | 30 | Config cfg( "mail" ); |
32 | cfg.setGroup( "Status" ); | 31 | cfg.setGroup( "Status" ); |
33 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); | 32 | m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); |
34 | emit queuedMails( m_queuedMail ); | 33 | emit queuedMails( m_queuedMail ); |
35 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); | 34 | connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) ); |
36 | } | 35 | } |
@@ -563,117 +562,117 @@ void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char* | |||
563 | if (failuremessage) { | 562 | if (failuremessage) { |
564 | QMessageBox::critical(0,tr("Error sending mail"), | 563 | QMessageBox::critical(0,tr("Error sending mail"), |
565 | tr("<center>%1</center>").arg(failuremessage)); | 564 | tr("<center>%1</center>").arg(failuremessage)); |
566 | } | 565 | } |
567 | } | 566 | } |
568 | 567 | ||
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. |
581 | 581 | ||
582 | ssl = false; | 582 | ssl = false; |
583 | 583 | ||
584 | if ( smtp->ConnectionType() == 2 ) { | 584 | if ( smtp->ConnectionType() == 2 ) { |
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 | ||
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 |
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); |
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 | ||
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 | ||
674 | SMTPaccount *smtp = aSmtp; | 673 | SMTPaccount *smtp = aSmtp; |
675 | 674 | ||
676 | if (!later && !smtp) { | 675 | if (!later && !smtp) { |
677 | qDebug("Didn't get any send method - giving up"); | 676 | qDebug("Didn't get any send method - giving up"); |
678 | return; | 677 | return; |
679 | } | 678 | } |
@@ -732,54 +731,81 @@ int SMTPwrapper::sendQueuedMail(AbstractMail*wrap,SMTPaccount*smtp,RecMail*which | |||
732 | smtp_address_list_free( rcpts ); | 731 | smtp_address_list_free( rcpts ); |
733 | } | 732 | } |
734 | return res; | 733 | return res; |
735 | } | 734 | } |
736 | 735 | ||
737 | /* this is a special fun */ | 736 | /* this is a special fun */ |
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) { |
764 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { | 786 | if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { |
765 | QMessageBox::critical(0,tr("Error sending mail"), | 787 | QMessageBox::critical(0,tr("Error sending mail"), |
766 | tr("Error sending queued mail - breaking")); | 788 | tr("Error sending queued mail - breaking")); |
767 | returnValue = false; | 789 | returnValue = false; |
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(); |
780 | delete sendProgress; | 806 | delete sendProgress; |
781 | sendProgress = 0; | 807 | sendProgress = 0; |
782 | wrap->deleteMails(mbox,mailsToRemove); | 808 | wrap->deleteMails(mbox,mailsToRemove); |
783 | mailsToSend.setAutoDelete(true); | 809 | mailsToSend.setAutoDelete(true); |
784 | delete wrap; | 810 | delete wrap; |
785 | return returnValue; | 811 | return returnValue; |