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
@@ -211,26 +211,26 @@ void ComposeMail::accept()
211 if ( !sigMultiLine->text().isEmpty() ) { 211 if ( !sigMultiLine->text().isEmpty() ) {
212 txt.append( "\n--\n" ); 212 txt.append( "\n--\n" );
213 txt.append( sigMultiLine->text() ); 213 txt.append( sigMultiLine->text() );
214 } 214 }
215 qDebug(txt); 215 qDebug(txt);
216 mail->setMessage( txt ); 216 mail->setMessage( txt );
217 AttachViewItem *it = (AttachViewItem *) attList->firstChild(); 217 AttachViewItem *it = (AttachViewItem *) attList->firstChild();
218 while ( it != NULL ) { 218 while ( it != NULL ) {
219 mail->addAttachment( it->getAttachment() ); 219 mail->addAttachment( it->getAttachment() );
220 it = (AttachViewItem *) it->nextSibling(); 220 it = (AttachViewItem *) it->nextSibling();
221 } 221 }
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
226 QDialog::accept(); 226 QDialog::accept();
227} 227}
228 228
229AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) 229AttachViewItem::AttachViewItem( QListView *parent, Attachment *att )
230 : QListViewItem( parent ) 230 : QListViewItem( parent )
231{ 231{
232 attachment = att; 232 attachment = att;
233 qDebug( att->getMimeType() ); 233 qDebug( att->getMimeType() );
234 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? 234 setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ?
235 Resource::loadPixmap( "UnknownDocument-14" ) : 235 Resource::loadPixmap( "UnknownDocument-14" ) :
236 attachment->getDocLnk().pixmap() ); 236 attachment->getDocLnk().pixmap() );
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
@@ -15,32 +15,39 @@
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 "sendmailprogress.h" 21#include "sendmailprogress.h"
22 22
23const char* SMTPwrapper::USER_AGENT="OpieMail v0.4"; 23const char* SMTPwrapper::USER_AGENT="OpieMail v0.4";
24 24
25progressMailSend*SMTPwrapper::sendProgress = 0; 25progressMailSend*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" );
31 cfg.setGroup( "Status" ); 32 cfg.setGroup( "Status" );
32 m_queuedMail = cfg.readNumEntry( "outgoing", 0 ); 33 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
33 emit queuedMails( m_queuedMail ); 34 emit queuedMails( m_queuedMail );
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}
36 43
37void SMTPwrapper::emitQCop( int queued ) { 44void SMTPwrapper::emitQCop( int queued ) {
38 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" ); 45 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
39 env << queued; 46 env << queued;
40} 47}
41 48
42QString SMTPwrapper::mailsmtpError( int errnum ) { 49QString SMTPwrapper::mailsmtpError( int errnum ) {
43 switch ( errnum ) { 50 switch ( errnum ) {
44 case MAILSMTP_NO_ERROR: 51 case MAILSMTP_NO_ERROR:
45 return tr( "No error" ); 52 return tr( "No error" );
46 case MAILSMTP_ERROR_UNEXPECTED_CODE: 53 case MAILSMTP_ERROR_UNEXPECTED_CODE:
@@ -501,32 +508,29 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) {
501} 508}
502 509
503void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) { 510void SMTPwrapper::storeMail(const char*mail, size_t length, const QString&box) {
504 if (!mail) 511 if (!mail)
505 return; 512 return;
506 QString localfolders = AbstractMail::defaultLocalfolder(); 513 QString localfolders = AbstractMail::defaultLocalfolder();
507 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 514 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
508 wrap->createMbox(box); 515 wrap->createMbox(box);
509 wrap->storeMessage(mail,length,box); 516 wrap->storeMessage(mail,length,box);
510 delete wrap; 517 delete wrap;
511} 518}
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;
515 char *from, *data; 522 char *from, *data;
516 size_t size; 523 size_t size;
517 524
518 if ( smtp == NULL ) {
519 return;
520 }
521 from = data = 0; 525 from = data = 0;
522 526
523 mailmessage * msg = 0; 527 mailmessage * msg = 0;
524 msg = mime_message_init(mail); 528 msg = mime_message_init(mail);
525 mime_message_set_tmpdir(msg,getenv( "HOME" )); 529 mime_message_set_tmpdir(msg,getenv( "HOME" ));
526 int r = mailmessage_fetch(msg,&data,&size); 530 int r = mailmessage_fetch(msg,&data,&size);
527 mime_message_detach_mime(msg); 531 mime_message_detach_mime(msg);
528 mailmessage_free(msg); 532 mailmessage_free(msg);
529 if (r != MAIL_NO_ERROR || !data) { 533 if (r != MAIL_NO_ERROR || !data) {
530 if (data) 534 if (data)
531 free(data); 535 free(data);
532 qDebug("Error fetching mime..."); 536 qDebug("Error fetching mime...");
@@ -536,324 +540,334 @@ void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) {
536 if (later) { 540 if (later) {
537 storeMail(data,size,"Outgoing"); 541 storeMail(data,size,"Outgoing");
538 if (data) 542 if (data)
539 free( data ); 543 free( data );
540 Config cfg( "mail" ); 544 Config cfg( "mail" );
541 cfg.setGroup( "Status" ); 545 cfg.setGroup( "Status" );
542 cfg.writeEntry( "outgoing", ++m_queuedMail ); 546 cfg.writeEntry( "outgoing", ++m_queuedMail );
543 emit queuedMails( m_queuedMail ); 547 emit queuedMails( m_queuedMail );
544 return; 548 return;
545 } 549 }
546 from = getFrom( mail ); 550 from = getFrom( mail );
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) {
550 free(data); 554 free(data);
551 } 555 }
552 if (from) { 556 if (from) {
553 free(from); 557 free(from);
554 } 558 }
555 if (rcpts) 559 if (rcpts)
556 smtp_address_list_free( rcpts ); 560 smtp_address_list_free( rcpts );
557} 561}
558 562
559void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage) 563void SMTPwrapper::storeFailedMail(const char*data,unsigned int size, const char*failuremessage)
560{ 564{
561 if (data) { 565 if (data) {
562 storeMail(data,size,"Sendfailed"); 566 storeMail(data,size,"Sendfailed");
563 } 567 }
564 if (failuremessage) { 568 if (failuremessage) {
565 QMessageBox::critical(0,tr("Error sending mail"), 569 QMessageBox::critical(0,tr("Error sending mail"),
566 tr("<center>%1</center>").arg(failuremessage)); 570 tr("<center>%1</center>").arg(failuremessage));
567 } 571 }
568} 572}
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;
577 mailstream_low * low; 581 mailstream_low * low;
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) {
581 return MAILSMTP_ERROR_IN_PROCESSING; 585 return MAILSMTP_ERROR_IN_PROCESSING;
582 } 586 }
583 int fd = mailstream_low_get_fd(low); 587 int fd = mailstream_low_get_fd(low);
584 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) { 588 if (fd > -1 && (new_low = mailstream_low_ssl_open(fd))!=0) {
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 {
588 return MAILSMTP_ERROR_IN_PROCESSING; 592 return MAILSMTP_ERROR_IN_PROCESSING;
589 } 593 }
590 return err; 594 return err;
591} 595}
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;
595 bool ssl; 600 bool ssl;
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;
608 bool try_tls = true; 603 bool try_tls = true;
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 );
628 if ( ssl ) { 630 if ( ssl ) {
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 }
635 if ( err != MAILSMTP_NO_ERROR ) { 637 if ( err != MAILSMTP_NO_ERROR ) {
636 qDebug("Error init connection"); 638 qDebug("Error init connection");
637 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 639 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
638 result = 0; 640 result = 0;
639 } 641 }
640 642
641 /* switch to tls after init 'cause there it will send the ehlo */ 643 /* switch to tls after init 'cause there it will send the ehlo */
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) {
645 result = 0; 647 result = 0;
646 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err)); 648 failuretext = tr("Error init SMTP connection: %1").arg(mailsmtpError(err));
647 } 649 }
648 } 650 }
649 651
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) {
653 try_tls = false; 655 try_tls = false;
654 } else { 656 } else {
655 err = mailesmtp_ehlo(session); 657 err = mailesmtp_ehlo(m_smtp);
656 } 658 }
657 } 659 }
658 660
659 if (!try_tls && force_tls) { 661 if (!try_tls && force_tls) {
660 result = 0; 662 result = 0;
661 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err)); 663 failuretext = tr("Error init SMTP tls: %1").arg(mailsmtpError(err));
662 } 664 }
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();
670 if ( QDialog::Accepted == login.exec() ) { 673 if ( QDialog::Accepted == login.exec() ) {
671 // ok 674 // ok
672 user = login.getUser().latin1(); 675 user = login.getUser().latin1();
673 pass = login.getPassword().latin1(); 676 pass = login.getPassword().latin1();
674 } else { 677 } else {
675 result = 0; 678 result = 0;
676 failuretext=tr("Login aborted - storing mail to localfolder"); 679 failuretext=tr("Login aborted - storing mail to localfolder");
677 } 680 }
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 ) {
686 qDebug("auth ok"); 689 qDebug("auth ok");
687 } else { 690 } else {
688 failuretext = tr("Authentification failed"); 691 failuretext = tr("Authentification failed");
689 result = 0; 692 result = 0;
690 } 693 }
691 } 694 }
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 ) {
697 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err)); 718 failuretext=tr("Error sending mail: %1").arg(mailsmtpError(err));
698 result = 0; 719 result = 0;
699 } 720 }
721 } else {
722 result = 0;
700 } 723 }
701 724
702 if (!result) { 725 if (!result) {
703 storeFailedMail(data,size,failuretext); 726 storeFailedMail(data,size,failuretext);
704 } else { 727 } else {
705 qDebug( "Mail sent." ); 728 qDebug( "Mail sent." );
706 storeMail(data,size,"Sent"); 729 storeMail(data,size,"Sent");
707 } 730 }
708 if (session) {
709 mailsmtp_quit( session );
710 mailsmtp_free( session );
711 }
712 return result; 731 return result;
713} 732}
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 );
725 if ( mimeMail == NULL ) { 739 if ( mimeMail == NULL ) {
726 qDebug( "sendMail: error creating mime mail" ); 740 qDebug( "sendMail: error creating mime mail" );
727 } else { 741 } else {
728 sendProgress = new progressMailSend(); 742 sendProgress = new progressMailSend();
729 sendProgress->show(); 743 sendProgress->show();
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");
733 sendProgress->hide(); 747 sendProgress->hide();
734 delete sendProgress; 748 delete sendProgress;
735 sendProgress = 0; 749 sendProgress = 0;
736 mailmime_free( mimeMail ); 750 mailmime_free( mimeMail );
737 } 751 }
738} 752}
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;
742 mailimf_fields *fields = 0; 756 mailimf_fields *fields = 0;
743 mailimf_field*ffrom = 0; 757 mailimf_field*ffrom = 0;
744 clist *rcpts = 0; 758 clist *rcpts = 0;
745 char*from = 0; 759 char*from = 0;
746 int res = 0; 760 int res = 0;
747 761
748 encodedString * data = wrap->fetchRawBody(*which); 762 encodedString * data = wrap->fetchRawBody(*which);
749 if (!data) 763 if (!data)
750 return 0; 764 return 0;
751 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields ); 765 int err = mailimf_fields_parse( data->Content(), data->Length(), &curTok, &fields );
752 if (err != MAILIMF_NO_ERROR) { 766 if (err != MAILIMF_NO_ERROR) {
753 delete data; 767 delete data;
754 delete wrap; 768 delete wrap;
755 return 0; 769 return 0;
756 } 770 }
757 771
758 rcpts = createRcptList( fields ); 772 rcpts = createRcptList( fields );
759 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 773 ffrom = getField(fields, MAILIMF_FIELD_FROM );
760 from = getFrom(ffrom); 774 from = getFrom(ffrom);
761 775
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 }
765 if (fields) { 779 if (fields) {
766 mailimf_fields_free(fields); 780 mailimf_fields_free(fields);
767 fields = 0; 781 fields = 0;
768 } 782 }
769 if (data) { 783 if (data) {
770 delete data; 784 delete data;
771 } 785 }
772 if (from) { 786 if (from) {
773 free(from); 787 free(from);
774 } 788 }
775 if (rcpts) { 789 if (rcpts) {
776 smtp_address_list_free( rcpts ); 790 smtp_address_list_free( rcpts );
777 } 791 }
778 return res; 792 return res;
779} 793}
780 794
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;
784 798
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");
788 return false; 802 return false;
789 } 803 }
790 804
791 bool reset_user_value = false; 805 bool reset_user_value = false;
792 QString localfolders = AbstractMail::defaultLocalfolder(); 806 QString localfolders = AbstractMail::defaultLocalfolder();
793 AbstractMail*wrap = AbstractMail::getWrapper(localfolders); 807 AbstractMail*wrap = AbstractMail::getWrapper(localfolders);
794 if (!wrap) { 808 if (!wrap) {
795 qDebug("memory error"); 809 qDebug("memory error");
796 return false; 810 return false;
797 } 811 }
798 QString oldPw, oldUser; 812 QString oldPw, oldUser;
799 QList<RecMail> mailsToSend; 813 QList<RecMail> mailsToSend;
800 QList<RecMail> mailsToRemove; 814 QList<RecMail> mailsToRemove;
801 QString mbox("Outgoing"); 815 QString mbox("Outgoing");
802 wrap->listMessages(mbox,mailsToSend); 816 wrap->listMessages(mbox,mailsToSend);
803 if (mailsToSend.count()==0) { 817 if (mailsToSend.count()==0) {
804 delete wrap; 818 delete wrap;
805 qDebug("No mails to send"); 819 qDebug("No mails to send");
806 return false; 820 return false;
807 } 821 }
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();
816 if ( QDialog::Accepted == login.exec() ) { 830 if ( QDialog::Accepted == login.exec() ) {
817 // ok 831 // ok
818 user = login.getUser().latin1(); 832 user = login.getUser().latin1();
819 pass = login.getPassword().latin1(); 833 pass = login.getPassword().latin1();
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 {
824 return true; 838 return true;
825 } 839 }
826 } 840 }
827 841
828 842
829 mailsToSend.setAutoDelete(false); 843 mailsToSend.setAutoDelete(false);
830 sendProgress = new progressMailSend(); 844 sendProgress = new progressMailSend();
831 sendProgress->show(); 845 sendProgress->show();
832 sendProgress->setMaxMails(mailsToSend.count()); 846 sendProgress->setMaxMails(mailsToSend.count());
833 847
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"),
837 tr("Error sending queued mail - breaking")); 851 tr("Error sending queued mail - breaking"));
838 returnValue = false; 852 returnValue = false;
839 break; 853 break;
840 } 854 }
841 mailsToRemove.append(mailsToSend.at(0)); 855 mailsToRemove.append(mailsToSend.at(0));
842 mailsToSend.removeFirst(); 856 mailsToSend.removeFirst();
843 sendProgress->setCurrentMails(mailsToRemove.count()); 857 sendProgress->setCurrentMails(mailsToRemove.count());
844 } 858 }
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 }
849 Config cfg( "mail" ); 863 Config cfg( "mail" );
850 cfg.setGroup( "Status" ); 864 cfg.setGroup( "Status" );
851 m_queuedMail = 0; 865 m_queuedMail = 0;
852 cfg.writeEntry( "outgoing", m_queuedMail ); 866 cfg.writeEntry( "outgoing", m_queuedMail );
853 emit queuedMails( m_queuedMail ); 867 emit queuedMails( m_queuedMail );
854 sendProgress->hide(); 868 sendProgress->hide();
855 delete sendProgress; 869 delete sendProgress;
856 sendProgress = 0; 870 sendProgress = 0;
857 wrap->deleteMails(mbox,mailsToRemove); 871 wrap->deleteMails(mbox,mailsToRemove);
858 mailsToSend.setAutoDelete(true); 872 mailsToSend.setAutoDelete(true);
859 delete wrap; 873 delete wrap;
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,76 +1,83 @@
1// -*- Mode: C++; -*-
1#ifndef SMTPwrapper_H 2#ifndef SMTPwrapper_H
2#define SMTPwrapper_H 3#define SMTPwrapper_H
3 4
4#include <qpe/applnk.h> 5#include <qpe/applnk.h>
5 6
6#include <qbitarray.h> 7#include <qbitarray.h>
7#include <qdatetime.h> 8#include <qdatetime.h>
8#include <libetpan/clist.h> 9#include <libetpan/clist.h>
9 10
10#include "settings.h" 11#include "settings.h"
11 12
12class Mail; 13class Mail;
13class AbstractMail; 14class AbstractMail;
14class RecMail; 15class RecMail;
15class Attachment; 16class Attachment;
16struct mailimf_fields; 17struct mailimf_fields;
17struct mailimf_field; 18struct mailimf_field;
18struct mailimf_mailbox; 19struct mailimf_mailbox;
19struct mailmime; 20struct mailmime;
20struct mailimf_address_list; 21struct mailimf_address_list;
21class progressMailSend; 22class progressMailSend;
22struct mailsmtp; 23struct mailsmtp;
24class SMTPaccount;
23 25
24class SMTPwrapper : public QObject 26class SMTPwrapper : public QObject
25{ 27{
26 Q_OBJECT 28 Q_OBJECT
27 29
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
34 static progressMailSend*sendProgress; 36 static progressMailSend*sendProgress;
35 37
36signals: 38signals:
37 void queuedMails( int ); 39 void queuedMails( int );
38 40
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 );
41 mailimf_fields *createImfFields(const Mail &mail ); 50 mailimf_fields *createImfFields(const Mail &mail );
42 mailmime *createMimeMail(const Mail&mail ); 51 mailmime *createMimeMail(const Mail&mail );
43 52
44 mailimf_address_list *parseAddresses(const QString&addr ); 53 mailimf_address_list *parseAddresses(const QString&addr );
45 void addFileParts( mailmime *message,const QList<Attachment>&files ); 54 void addFileParts( mailmime *message,const QList<Attachment>&files );
46 mailmime *buildTxtPart(const QString&str ); 55 mailmime *buildTxtPart(const QString&str );
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 );
50 59
51 static void storeMail(const char*mail, size_t length, const QString&box); 60 static void storeMail(const char*mail, size_t length, const QString&box);
52 static QString mailsmtpError( int err ); 61 static QString mailsmtpError( int err );
53 static void progress( size_t current, size_t maximum ); 62 static void progress( size_t current, size_t maximum );
54 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 63 static void addRcpts( clist *list, mailimf_address_list *addr_list );
55 static char *getFrom( mailmime *mail ); 64 static char *getFrom( mailmime *mail );
56 static char *getFrom( mailimf_field *ffrom); 65 static char *getFrom( mailimf_field *ffrom);
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);
67 74
68 int m_queuedMail; 75 int m_queuedMail;
69 static const char* USER_AGENT; 76 static const char* USER_AGENT;
70 77
71protected slots: 78protected slots:
72 void emitQCop( int queued ); 79 void emitQCop( int queued );
73 80
74}; 81};
75 82
76#endif 83#endif
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
@@ -85,28 +85,29 @@ void OpieMail::slotSendQueued()
85 if (smtpList.count()==1) { 85 if (smtpList.count()==1) {
86 smtp = smtpList.at(0); 86 smtp = smtpList.at(0);
87 } else { 87 } else {
88 smtp = 0; 88 smtp = 0;
89 selectsmtp selsmtp; 89 selectsmtp selsmtp;
90 selsmtp.setSelectionlist(&smtpList); 90 selsmtp.setSelectionlist(&smtpList);
91 selsmtp.showMaximized(); 91 selsmtp.showMaximized();
92 if (selsmtp.exec()==QDialog::Accepted) { 92 if (selsmtp.exec()==QDialog::Accepted) {
93 smtp = selsmtp.selected_smtp(); 93 smtp = selsmtp.selected_smtp();
94 } 94 }
95 } 95 }
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 }
102} 103}
103 104
104void OpieMail::slotSearchMails() 105void OpieMail::slotSearchMails()
105{ 106{
106 qDebug( "Search Mails" ); 107 qDebug( "Search Mails" );
107} 108}
108 109
109void OpieMail::slotEditSettings() 110void OpieMail::slotEditSettings()
110{ 111{
111 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp ); 112 SettingsDialog settingsDialog( this, 0, true, WStyle_ContextHelp );
112 settingsDialog.showMaximized(); 113 settingsDialog.showMaximized();