summaryrefslogtreecommitdiff
authoralwin <alwin>2003-12-24 01:29:43 (UTC)
committer alwin <alwin>2003-12-24 01:29:43 (UTC)
commit242f7a04e3e4963a5606ac603d54a4f115de4a04 (patch) (unidiff)
treedd8578fbc812791dd7e5026a28710a8313cf5cf8
parent7c720aabcad9b325dbf9910493e3c9fa1d63805e (diff)
downloadopie-242f7a04e3e4963a5606ac603d54a4f115de4a04.zip
opie-242f7a04e3e4963a5606ac603d54a4f115de4a04.tar.gz
opie-242f7a04e3e4963a5606ac603d54a4f115de4a04.tar.bz2
tried to implement a progress dialog when sending mails. It doesn't work
(dialog will show but makes no updates, when using qApp->progressEvents(x) dialog hides) I don't know why - and I giving up for the moment.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogress.cpp48
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogress.h19
-rw-r--r--noncore/net/mail/libmailwrapper/sendmailprogressui.ui110
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp16
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h4
-rw-r--r--noncore/net/mail/mail.pro9
-rw-r--r--noncore/net/mail/sendmailprogress.cpp48
-rw-r--r--noncore/net/mail/sendmailprogress.h19
-rw-r--r--noncore/net/mail/sendmailprogressui.ui110
-rw-r--r--noncore/net/mail/smtpwrapper.cpp16
-rw-r--r--noncore/net/mail/smtpwrapper.h4
11 files changed, 396 insertions, 7 deletions
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.cpp b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
new file mode 100644
index 0000000..13ddd37
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/sendmailprogress.cpp
@@ -0,0 +1,48 @@
1#include "sendmailprogress.h"
2#include <qprogressbar.h>
3#include <qlabel.h>
4#include <qstring.h>
5
6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{
9}
10
11progressMailSend::~progressMailSend()
12{
13}
14
15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{
17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails();
20}
21
22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{
24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent);
26 setMails();
27}
28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{
31 m_current_single = aCurrent;
32 m_max_single = aMax;
33 setSingle();
34}
35
36void progressMailSend::setSingle()
37{
38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single);
42}
43
44void progressMailSend::setMails()
45{
46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single);
47 allMailLabel->setText(text);
48}
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogress.h b/noncore/net/mail/libmailwrapper/sendmailprogress.h
new file mode 100644
index 0000000..5b7d33b
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/sendmailprogress.h
@@ -0,0 +1,19 @@
1#include "sendmailprogressui.h"
2
3class progressMailSend:public progressMailSendUI
4{
5 Q_OBJECT
6public:
7 progressMailSend(QWidget*parent = 0, const char * name = 0);
8 ~progressMailSend();
9
10 void setMaxMails(unsigned int aMaxMails);
11 void setCurrentMails(unsigned int aCurrent);
12
13 void setSingleMail(unsigned int aCurrent,unsigned int aMax);
14
15protected:
16 unsigned m_current_mail,m_current_single,m_max_mail,m_max_single;
17 void setSingle();
18 void setMails();
19};
diff --git a/noncore/net/mail/libmailwrapper/sendmailprogressui.ui b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
new file mode 100644
index 0000000..b90b088
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/sendmailprogressui.ui
@@ -0,0 +1,110 @@
1<!DOCTYPE UI><UI>
2<class>progressMailSendUI</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>progressMailSendUI</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>316</width>
15 <height>266</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Sending mail</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>4</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <widget>
38 <class>QLabel</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>singleMailLabel</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>Progress of mail</string>
46 </property>
47 <property stdset="1">
48 <name>alignment</name>
49 <set>AlignCenter</set>
50 </property>
51 <property>
52 <name>hAlign</name>
53 </property>
54 </widget>
55 <widget>
56 <class>QProgressBar</class>
57 <property stdset="1">
58 <name>name</name>
59 <cstring>singleMailProgressBar</cstring>
60 </property>
61 </widget>
62 <widget>
63 <class>QLabel</class>
64 <property stdset="1">
65 <name>name</name>
66 <cstring>allMailLabel</cstring>
67 </property>
68 <property stdset="1">
69 <name>text</name>
70 <string>Sending mail</string>
71 </property>
72 <property stdset="1">
73 <name>alignment</name>
74 <set>AlignCenter</set>
75 </property>
76 <property>
77 <name>hAlign</name>
78 </property>
79 </widget>
80 <widget>
81 <class>QProgressBar</class>
82 <property stdset="1">
83 <name>name</name>
84 <cstring>allMailProgressBar</cstring>
85 </property>
86 </widget>
87 <spacer>
88 <property>
89 <name>name</name>
90 <cstring>Spacer6</cstring>
91 </property>
92 <property stdset="1">
93 <name>orientation</name>
94 <enum>Vertical</enum>
95 </property>
96 <property stdset="1">
97 <name>sizeType</name>
98 <enum>Expanding</enum>
99 </property>
100 <property>
101 <name>sizeHint</name>
102 <size>
103 <width>20</width>
104 <height>20</height>
105 </size>
106 </property>
107 </spacer>
108 </vbox>
109</widget>
110</UI>
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index b81a87f..53c0af5 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,65 +1,68 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9 9
10#include <libetpan/libetpan.h> 10#include <libetpan/libetpan.h>
11 11
12#include "smtpwrapper.h" 12#include "smtpwrapper.h"
13#include "mailwrapper.h" 13#include "mailwrapper.h"
14#include "mboxwrapper.h" 14#include "mboxwrapper.h"
15#include "logindialog.h" 15#include "logindialog.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17#include "defines.h" 17#include "defines.h"
18#include "sendmailprogress.h"
19
20progressMailSend*SMTPwrapper::sendProgress = 0;
18 21
19SMTPwrapper::SMTPwrapper( Settings *s ) 22SMTPwrapper::SMTPwrapper( Settings *s )
20 : QObject() 23 : QObject()
21{ 24{
22 settings = s; 25 settings = s;
23} 26}
24 27
25QString SMTPwrapper::mailsmtpError( int errnum ) 28QString SMTPwrapper::mailsmtpError( int errnum )
26{ 29{
27 switch ( errnum ) { 30 switch ( errnum ) {
28 case MAILSMTP_NO_ERROR: 31 case MAILSMTP_NO_ERROR:
29 return tr( "No error" ); 32 return tr( "No error" );
30 case MAILSMTP_ERROR_UNEXPECTED_CODE: 33 case MAILSMTP_ERROR_UNEXPECTED_CODE:
31 return tr( "Unexpected error code" ); 34 return tr( "Unexpected error code" );
32 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
33 return tr( "Service not available" ); 36 return tr( "Service not available" );
34 case MAILSMTP_ERROR_STREAM: 37 case MAILSMTP_ERROR_STREAM:
35 return tr( "Stream error" ); 38 return tr( "Stream error" );
36 case MAILSMTP_ERROR_HOSTNAME: 39 case MAILSMTP_ERROR_HOSTNAME:
37 return tr( "gethostname() failed" ); 40 return tr( "gethostname() failed" );
38 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 41 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
39 return tr( "Not implemented" ); 42 return tr( "Not implemented" );
40 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
41 return tr( "Error, action not taken" ); 44 return tr( "Error, action not taken" );
42 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
43 return tr( "Data exceeds storage allocation" ); 46 return tr( "Data exceeds storage allocation" );
44 case MAILSMTP_ERROR_IN_PROCESSING: 47 case MAILSMTP_ERROR_IN_PROCESSING:
45 return tr( "Error in processing" ); 48 return tr( "Error in processing" );
46 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
47 // return tr( "Insufficient system storage" ); 50 // return tr( "Insufficient system storage" );
48 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
49 return tr( "Mailbox unavailable" ); 52 return tr( "Mailbox unavailable" );
50 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
51 return tr( "Mailbox name not allowed" ); 54 return tr( "Mailbox name not allowed" );
52 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
53 return tr( "Bad command sequence" ); 56 return tr( "Bad command sequence" );
54 case MAILSMTP_ERROR_USER_NOT_LOCAL: 57 case MAILSMTP_ERROR_USER_NOT_LOCAL:
55 return tr( "User not local" ); 58 return tr( "User not local" );
56 case MAILSMTP_ERROR_TRANSACTION_FAILED: 59 case MAILSMTP_ERROR_TRANSACTION_FAILED:
57 return tr( "Transaction failed" ); 60 return tr( "Transaction failed" );
58 case MAILSMTP_ERROR_MEMORY: 61 case MAILSMTP_ERROR_MEMORY:
59 return tr( "Memory error" ); 62 return tr( "Memory error" );
60 case MAILSMTP_ERROR_CONNECTION_REFUSED: 63 case MAILSMTP_ERROR_CONNECTION_REFUSED:
61 return tr( "Connection refused" ); 64 return tr( "Connection refused" );
62 default: 65 default:
63 return tr( "Unknown error code" ); 66 return tr( "Unknown error code" );
64 } 67 }
65} 68}
@@ -475,97 +478,100 @@ QString SMTPwrapper::getTmpFile() {
475 unique.setNum( num++ ); 478 unique.setNum( num++ );
476 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
477 480
478 return "/tmp/opiemail-tmp-" + unique; 481 return "/tmp/opiemail-tmp-" + unique;
479} 482}
480 483
481void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) 484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
482{ 485{
483 FILE *f; 486 FILE *f;
484 int err, col = 0; 487 int err, col = 0;
485 488
486 f = fopen( file.latin1(), "w" ); 489 f = fopen( file.latin1(), "w" );
487 if ( f == NULL ) { 490 if ( f == NULL ) {
488 qDebug( "writeToFile: error opening file" ); 491 qDebug( "writeToFile: error opening file" );
489 return; 492 return;
490 } 493 }
491 494
492 err = mailmime_write( f, &col, mail ); 495 err = mailmime_write( f, &col, mail );
493 if ( err != MAILIMF_NO_ERROR ) { 496 if ( err != MAILIMF_NO_ERROR ) {
494 fclose( f ); 497 fclose( f );
495 qDebug( "writeToFile: error writing mailmime" ); 498 qDebug( "writeToFile: error writing mailmime" );
496 return; 499 return;
497 } 500 }
498 501
499 fclose( f ); 502 fclose( f );
500} 503}
501 504
502void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
503{ 506{
504 507
505 QFile msg_cache(file); 508 QFile msg_cache(file);
506 QString msg = ""; 509 QString msg = "";
507 msg_cache.open(IO_ReadOnly); 510 msg_cache.open(IO_ReadOnly);
508 char*message = new char[4096]; 511 char*message = new char[4096];
509 memset(message,0,4096); 512 memset(message,0,4096);
510 while (msg_cache.readBlock(message,4095)>0) { 513 while (msg_cache.readBlock(message,4095)>0) {
511 msg+=message; 514 msg+=message;
512 memset(message,0,4096); 515 memset(message,0,4096);
513 } 516 }
514 delete message; 517 delete message;
515 *data = (char*)malloc(msg.length()+1*sizeof(char)); 518 *data = (char*)malloc(msg.length()+1*sizeof(char));
516 memset(*data,0,msg.length()+1); 519 memset(*data,0,msg.length()+1);
517 memcpy(*data,msg.ascii(),msg.length()); 520 memcpy(*data,msg.ascii(),msg.length());
518 *size=msg.length(); 521 *size=msg.length();
519} 522}
520 523
521void SMTPwrapper::progress( size_t current, size_t maximum ) 524void SMTPwrapper::progress( size_t current, size_t maximum )
522{ 525{
523// qDebug( "Current: %i of %i", current, maximum ); 526 if (SMTPwrapper::sendProgress) {
527 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
528 qDebug("%u of %u",current,maximum);
529 }
524} 530}
525 531
526void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
527{ 533{
528 if (!mail) return; 534 if (!mail) return;
529 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
530 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 536 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
531 wrap->storeMessage(mail,length,box); 537 wrap->storeMessage(mail,length,box);
532 delete wrap; 538 delete wrap;
533} 539}
534 540
535void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
536{ 542{
537 clist *rcpts = 0; 543 clist *rcpts = 0;
538 char *from, *data; 544 char *from, *data;
539 size_t size; 545 size_t size;
540 546
541 if ( smtp == NULL ) { 547 if ( smtp == NULL ) {
542 return; 548 return;
543 } 549 }
544 from = data = 0; 550 from = data = 0;
545 551
546 QString file = getTmpFile(); 552 QString file = getTmpFile();
547 writeToFile( file, mail ); 553 writeToFile( file, mail );
548 readFromFile( file, &data, &size ); 554 readFromFile( file, &data, &size );
549 QFile f( file ); 555 QFile f( file );
550 f.remove(); 556 f.remove();
551 557
552 if (later) { 558 if (later) {
553 storeMail(data,size,"Outgoing"); 559 storeMail(data,size,"Outgoing");
554 if (data) free( data ); 560 if (data) free( data );
555 return; 561 return;
556 } 562 }
557 from = getFrom( mail ); 563 from = getFrom( mail );
558 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
559 smtpSend(from,rcpts,data,size,smtp); 565 smtpSend(from,rcpts,data,size,smtp);
560} 566}
561 567
562int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
563{ 569{
564 char *server, *user, *pass; 570 char *server, *user, *pass;
565 bool ssl; 571 bool ssl;
566 uint16_t port; 572 uint16_t port;
567 mailsmtp *session; 573 mailsmtp *session;
568 int err,result; 574 int err,result;
569 575
570 result = 1; 576 result = 1;
571 server = user = pass = 0; 577 server = user = pass = 0;
@@ -600,115 +606,123 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou
600 // ok 606 // ok
601 user = strdup( login.getUser().latin1() ); 607 user = strdup( login.getUser().latin1() );
602 pass = strdup( login.getPassword().latin1() ); 608 pass = strdup( login.getPassword().latin1() );
603 } else { 609 } else {
604 result = 0; goto free_con_session; 610 result = 0; goto free_con_session;
605 } 611 }
606 } else { 612 } else {
607 user = strdup( smtp->getUser().latin1() ); 613 user = strdup( smtp->getUser().latin1() );
608 pass = strdup( smtp->getPassword().latin1() ); 614 pass = strdup( smtp->getPassword().latin1() );
609 } 615 }
610 qDebug( "session->auth: %i", session->auth); 616 qDebug( "session->auth: %i", session->auth);
611 err = mailsmtp_auth( session, user, pass ); 617 err = mailsmtp_auth( session, user, pass );
612 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
613 qDebug( "Done auth!" ); 619 qDebug( "Done auth!" );
614 } 620 }
615 621
616 err = mailsmtp_send( session, from, rcpts, data, size ); 622 err = mailsmtp_send( session, from, rcpts, data, size );
617 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
618 624
619 qDebug( "Mail sent." ); 625 qDebug( "Mail sent." );
620 storeMail(data,size,"Sent"); 626 storeMail(data,size,"Sent");
621 627
622free_con_session: 628free_con_session:
623 mailsmtp_quit( session ); 629 mailsmtp_quit( session );
624free_mem_session: 630free_mem_session:
625 mailsmtp_free( session ); 631 mailsmtp_free( session );
626free_mem: 632free_mem:
627 if (rcpts) smtp_address_list_free( rcpts ); 633 if (rcpts) smtp_address_list_free( rcpts );
628 if (data) free( data ); 634 if (data) free( data );
629 if (server) free( server ); 635 if (server) free( server );
630 if (from) free( from ); 636 if (from) free( from );
631 if ( smtp->getLogin() ) { 637 if ( smtp->getLogin() ) {
632 free( user ); 638 free( user );
633 free( pass ); 639 free( pass );
634 } 640 }
635 return result; 641 return result;
636} 642}
637 643
638void SMTPwrapper::sendMail(const Mail&mail,bool later ) 644void SMTPwrapper::sendMail(const Mail&mail,bool later )
639{ 645{
640 mailmime * mimeMail; 646 mailmime * mimeMail;
641 647
642 SMTPaccount *smtp = getAccount(mail.getName()); 648 SMTPaccount *smtp = getAccount(mail.getName());
643 649
644 mimeMail = createMimeMail(mail ); 650 mimeMail = createMimeMail(mail );
645 if ( mimeMail == NULL ) { 651 if ( mimeMail == NULL ) {
646 qDebug( "sendMail: error creating mime mail" ); 652 qDebug( "sendMail: error creating mime mail" );
647 } else { 653 } else {
654 sendProgress = new progressMailSend();
655 sendProgress->showMaximized();
656 sendProgress->show();
657 qApp->processEvents(10);
648 smtpSend( mimeMail,later,smtp); 658 smtpSend( mimeMail,later,smtp);
649 mailmime_free( mimeMail ); 659 mailmime_free( mimeMail );
650 qDebug("Clean up done"); 660 qDebug("Clean up done");
661 sendProgress->hide();
662 delete sendProgress;
663 sendProgress = 0;
651 } 664 }
652} 665}
653 666
654int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
655{ 668{
656 char*data = 0; 669 char*data = 0;
657 size_t length = 0; 670 size_t length = 0;
658 size_t curTok = 0; 671 size_t curTok = 0;
659 mailimf_fields *fields = 0; 672 mailimf_fields *fields = 0;
660 mailimf_field*ffrom = 0; 673 mailimf_field*ffrom = 0;
661 clist *rcpts = 0; 674 clist *rcpts = 0;
662 char*from = 0; 675 char*from = 0;
663 676
664 wrap->fetchRawBody(*which,&data,&length); 677 wrap->fetchRawBody(*which,&data,&length);
665 if (!data) return 0; 678 if (!data) return 0;
666 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 679 int err = mailimf_fields_parse( data, length, &curTok, &fields );
667 if (err != MAILIMF_NO_ERROR) { 680 if (err != MAILIMF_NO_ERROR) {
668 free(data); 681 free(data);
669 delete wrap; 682 delete wrap;
670 return 0; 683 return 0;
671 } 684 }
672 685
673 rcpts = createRcptList( fields ); 686 rcpts = createRcptList( fields );
674 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 687 ffrom = getField(fields, MAILIMF_FIELD_FROM );
675 from = getFrom(ffrom); 688 from = getFrom(ffrom);
689
676 qDebug("Size: %i vs. %i",length,strlen(data)); 690 qDebug("Size: %i vs. %i",length,strlen(data));
677 if (rcpts && from) { 691 if (rcpts && from) {
678 return smtpSend(from,rcpts,data,strlen(data),smtp ); 692 return smtpSend(from,rcpts,data,strlen(data),smtp );
679 } 693 }
680 return 0; 694 return 0;
681} 695}
682 696
683/* this is a special fun */ 697/* this is a special fun */
684void SMTPwrapper::flushOutbox(SMTPaccount*smtp) 698void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
685{ 699{
686 if (!smtp) return; 700 if (!smtp) return;
687 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
688 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 702 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
689 if (!wrap) { 703 if (!wrap) {
690 qDebug("memory error"); 704 qDebug("memory error");
691 return; 705 return;
692 } 706 }
693 QList<RecMail> mailsToSend; 707 QList<RecMail> mailsToSend;
694 QList<RecMail> mailsToRemove; 708 QList<RecMail> mailsToRemove;
695 QString mbox("Outgoing"); 709 QString mbox("Outgoing");
696 wrap->listMessages(mbox,mailsToSend); 710 wrap->listMessages(mbox,mailsToSend);
697 if (mailsToSend.count()==0) { 711 if (mailsToSend.count()==0) {
698 delete wrap; 712 delete wrap;
699 return; 713 return;
700 } 714 }
701 mailsToSend.setAutoDelete(false); 715 mailsToSend.setAutoDelete(false);
702 while (mailsToSend.count()>0) { 716 while (mailsToSend.count()>0) {
703 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 717 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
704 QMessageBox::critical(0,tr("Error sending mail"), 718 QMessageBox::critical(0,tr("Error sending mail"),
705 tr("Error sending queued mail - breaking")); 719 tr("Error sending queued mail - breaking"));
706 break; 720 break;
707 } 721 }
708 mailsToRemove.append(mailsToSend.at(0)); 722 mailsToRemove.append(mailsToSend.at(0));
709 mailsToSend.removeFirst(); 723 mailsToSend.removeFirst();
710 } 724 }
711 wrap->deleteMails(mbox,mailsToRemove); 725 wrap->deleteMails(mbox,mailsToRemove);
712 mailsToSend.setAutoDelete(true); 726 mailsToSend.setAutoDelete(true);
713 delete wrap; 727 delete wrap;
714} 728}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index c0dcc11..baa353b 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -1,63 +1,65 @@
1#ifndef SMTPwrapper_H 1#ifndef SMTPwrapper_H
2#define SMTPwrapper_H 2#define SMTPwrapper_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10#include "settings.h" 10#include "settings.h"
11 11
12class Mail; 12class Mail;
13class MBOXwrapper; 13class MBOXwrapper;
14class RecMail; 14class RecMail;
15class Attachment; 15class Attachment;
16struct mailimf_fields; 16struct mailimf_fields;
17struct mailimf_field; 17struct mailimf_field;
18struct mailimf_mailbox; 18struct mailimf_mailbox;
19struct mailmime; 19struct mailmime;
20struct mailimf_address_list; 20struct mailimf_address_list;
21class progressMailSend;
21 22
22class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
23{ 24{
24 Q_OBJECT 25 Q_OBJECT
25 26
26public: 27public:
27 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
28 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
29 void sendMail(const Mail& mail,bool later=false ); 30 void sendMail(const Mail& mail,bool later=false );
30 void flushOutbox(SMTPaccount*smtp); 31 void flushOutbox(SMTPaccount*smtp);
31 32
33 static progressMailSend*sendProgress;
32protected: 34protected:
33 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
34 mailimf_fields *createImfFields(const Mail &mail ); 36 mailimf_fields *createImfFields(const Mail &mail );
35 mailmime *createMimeMail(const Mail&mail ); 37 mailmime *createMimeMail(const Mail&mail );
36 38
37 mailimf_address_list *parseAddresses(const QString&addr ); 39 mailimf_address_list *parseAddresses(const QString&addr );
38 void addFileParts( mailmime *message,const QList<Attachment>&files ); 40 void addFileParts( mailmime *message,const QList<Attachment>&files );
39 mailmime *buildTxtPart(const QString&str ); 41 mailmime *buildTxtPart(const QString&str );
40 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
41 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
42 clist *createRcptList( mailimf_fields *fields ); 44 clist *createRcptList( mailimf_fields *fields );
43 SMTPaccount *getAccount(const QString&from ); 45 SMTPaccount *getAccount(const QString&from );
44 void writeToFile(const QString&file, mailmime *mail ); 46 void writeToFile(const QString&file, mailmime *mail );
45 void readFromFile(const QString&file, char **data, size_t *size ); 47 void readFromFile(const QString&file, char **data, size_t *size );
46 48
47 static void storeMail(char*mail, size_t length, const QString&box); 49 static void storeMail(char*mail, size_t length, const QString&box);
48 static QString mailsmtpError( int err ); 50 static QString mailsmtpError( int err );
49 static QString getTmpFile(); 51 static QString getTmpFile();
50 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
51 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
52 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
53 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
54 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
55 static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
56 58
57 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
58 Settings *settings; 60 Settings *settings;
59 61
60 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
61}; 63};
62 64
63#endif 65#endif
diff --git a/noncore/net/mail/mail.pro b/noncore/net/mail/mail.pro
index dd3c337..ea5fb58 100644
--- a/noncore/net/mail/mail.pro
+++ b/noncore/net/mail/mail.pro
@@ -1,70 +1,73 @@
1CONFIG += qt warn_on debug quick-app 1CONFIG += qt warn_on debug quick-app
2 2
3HEADERS = defines.h \ 3HEADERS = defines.h \
4 logindialog.h \ 4 logindialog.h \
5 settings.h \ 5 settings.h \
6 editaccounts.h \ 6 editaccounts.h \
7 mailwrapper.h \ 7 mailwrapper.h \
8 composemail.h \ 8 composemail.h \
9 accountview.h \ 9 accountview.h \
10 mainwindow.h \ 10 mainwindow.h \
11 viewmail.h \ 11 viewmail.h \
12 viewmailbase.h \ 12 viewmailbase.h \
13 opiemail.h \ 13 opiemail.h \
14 imapwrapper.h \ 14 imapwrapper.h \
15 mailtypes.h \ 15 mailtypes.h \
16 mailistviewitem.h \ 16 mailistviewitem.h \
17 pop3wrapper.h \ 17 pop3wrapper.h \
18 abstractmail.h \ 18 abstractmail.h \
19 settingsdialog.h \ 19 settingsdialog.h \
20 statuswidget.h \ 20 statuswidget.h \
21 smtpwrapper.h \ 21 smtpwrapper.h \
22 genericwrapper.h \ 22 genericwrapper.h \
23 mboxwrapper.h 23 mboxwrapper.h \
24 sendmailprogress.h
24 25
25SOURCES = main.cpp \ 26SOURCES = main.cpp \
26 opiemail.cpp \ 27 opiemail.cpp \
27 mainwindow.cpp \ 28 mainwindow.cpp \
28 accountview.cpp \ 29 accountview.cpp \
29 composemail.cpp \ 30 composemail.cpp \
30 mailwrapper.cpp \ 31 mailwrapper.cpp \
31 imapwrapper.cpp \ 32 imapwrapper.cpp \
32 addresspicker.cpp \ 33 addresspicker.cpp \
33 editaccounts.cpp \ 34 editaccounts.cpp \
34 logindialog.cpp \ 35 logindialog.cpp \
35 viewmail.cpp \ 36 viewmail.cpp \
36 viewmailbase.cpp \ 37 viewmailbase.cpp \
37 settings.cpp \ 38 settings.cpp \
38 mailtypes.cpp \ 39 mailtypes.cpp \
39 pop3wrapper.cpp \ 40 pop3wrapper.cpp \
40 abstractmail.cpp \ 41 abstractmail.cpp \
41 settingsdialog.cpp \ 42 settingsdialog.cpp \
42 statuswidget.cpp \ 43 statuswidget.cpp \
43 smtpwrapper.cpp \ 44 smtpwrapper.cpp \
44 genericwrapper.cpp \ 45 genericwrapper.cpp \
45 mboxwrapper.cpp 46 mboxwrapper.cpp \
47 sendmailprogress.cpp
46 48
47INTERFACES = editaccountsui.ui \ 49INTERFACES = editaccountsui.ui \
48 selectmailtypeui.ui \ 50 selectmailtypeui.ui \
49 imapconfigui.ui \ 51 imapconfigui.ui \
50 pop3configui.ui \ 52 pop3configui.ui \
51 nntpconfigui.ui \ 53 nntpconfigui.ui \
52 smtpconfigui.ui \ 54 smtpconfigui.ui \
53 addresspickerui.ui \ 55 addresspickerui.ui \
54 logindialogui.ui \ 56 logindialogui.ui \
55 composemailui.ui \ 57 composemailui.ui \
56 settingsdialogui.ui \ 58 settingsdialogui.ui \
57 statuswidgetui.ui 59 statuswidgetui.ui \
60 sendmailprogressui.ui
58 61
59INCLUDEPATH += $(OPIEDIR)/include 62INCLUDEPATH += $(OPIEDIR)/include
60 63
61CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) 64CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX )
62contains( CONFTEST, y ){ 65contains( CONFTEST, y ){
63 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv 66 LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv
64}else{ 67}else{
65 LIBS += -lqpe -letpan -lssl -lcrypto -lopie 68 LIBS += -lqpe -letpan -lssl -lcrypto -lopie
66} 69}
67 70
68TARGET = opiemail 71TARGET = opiemail
69 72
70include ( $(OPIEDIR)/include.pro ) 73include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/net/mail/sendmailprogress.cpp b/noncore/net/mail/sendmailprogress.cpp
new file mode 100644
index 0000000..13ddd37
--- a/dev/null
+++ b/noncore/net/mail/sendmailprogress.cpp
@@ -0,0 +1,48 @@
1#include "sendmailprogress.h"
2#include <qprogressbar.h>
3#include <qlabel.h>
4#include <qstring.h>
5
6progressMailSend::progressMailSend(QWidget*parent, const char * name)
7 :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0)
8{
9}
10
11progressMailSend::~progressMailSend()
12{
13}
14
15void progressMailSend::setMaxMails(unsigned int aMaxMails)
16{
17 m_max_mail = aMaxMails;
18 allMailProgressBar->setTotalSteps(aMaxMails);
19 setMails();
20}
21
22void progressMailSend::setCurrentMails(unsigned int aCurrent)
23{
24 m_current_mail = aCurrent;
25 allMailProgressBar->setProgress(aCurrent);
26 setMails();
27}
28
29void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax)
30{
31 m_current_single = aCurrent;
32 m_max_single = aMax;
33 setSingle();
34}
35
36void progressMailSend::setSingle()
37{
38 QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single);
39 singleMailLabel->setText(text);
40 singleMailProgressBar->setTotalSteps(m_max_single);
41 singleMailProgressBar->setProgress(m_current_single);
42}
43
44void progressMailSend::setMails()
45{
46 QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single);
47 allMailLabel->setText(text);
48}
diff --git a/noncore/net/mail/sendmailprogress.h b/noncore/net/mail/sendmailprogress.h
new file mode 100644
index 0000000..5b7d33b
--- a/dev/null
+++ b/noncore/net/mail/sendmailprogress.h
@@ -0,0 +1,19 @@
1#include "sendmailprogressui.h"
2
3class progressMailSend:public progressMailSendUI
4{
5 Q_OBJECT
6public:
7 progressMailSend(QWidget*parent = 0, const char * name = 0);
8 ~progressMailSend();
9
10 void setMaxMails(unsigned int aMaxMails);
11 void setCurrentMails(unsigned int aCurrent);
12
13 void setSingleMail(unsigned int aCurrent,unsigned int aMax);
14
15protected:
16 unsigned m_current_mail,m_current_single,m_max_mail,m_max_single;
17 void setSingle();
18 void setMails();
19};
diff --git a/noncore/net/mail/sendmailprogressui.ui b/noncore/net/mail/sendmailprogressui.ui
new file mode 100644
index 0000000..b90b088
--- a/dev/null
+++ b/noncore/net/mail/sendmailprogressui.ui
@@ -0,0 +1,110 @@
1<!DOCTYPE UI><UI>
2<class>progressMailSendUI</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>progressMailSendUI</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>316</width>
15 <height>266</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Sending mail</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <vbox>
29 <property stdset="1">
30 <name>margin</name>
31 <number>4</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <widget>
38 <class>QLabel</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>singleMailLabel</cstring>
42 </property>
43 <property stdset="1">
44 <name>text</name>
45 <string>Progress of mail</string>
46 </property>
47 <property stdset="1">
48 <name>alignment</name>
49 <set>AlignCenter</set>
50 </property>
51 <property>
52 <name>hAlign</name>
53 </property>
54 </widget>
55 <widget>
56 <class>QProgressBar</class>
57 <property stdset="1">
58 <name>name</name>
59 <cstring>singleMailProgressBar</cstring>
60 </property>
61 </widget>
62 <widget>
63 <class>QLabel</class>
64 <property stdset="1">
65 <name>name</name>
66 <cstring>allMailLabel</cstring>
67 </property>
68 <property stdset="1">
69 <name>text</name>
70 <string>Sending mail</string>
71 </property>
72 <property stdset="1">
73 <name>alignment</name>
74 <set>AlignCenter</set>
75 </property>
76 <property>
77 <name>hAlign</name>
78 </property>
79 </widget>
80 <widget>
81 <class>QProgressBar</class>
82 <property stdset="1">
83 <name>name</name>
84 <cstring>allMailProgressBar</cstring>
85 </property>
86 </widget>
87 <spacer>
88 <property>
89 <name>name</name>
90 <cstring>Spacer6</cstring>
91 </property>
92 <property stdset="1">
93 <name>orientation</name>
94 <enum>Vertical</enum>
95 </property>
96 <property stdset="1">
97 <name>sizeType</name>
98 <enum>Expanding</enum>
99 </property>
100 <property>
101 <name>sizeHint</name>
102 <size>
103 <width>20</width>
104 <height>20</height>
105 </size>
106 </property>
107 </spacer>
108 </vbox>
109</widget>
110</UI>
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
index b81a87f..53c0af5 100644
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/noncore/net/mail/smtpwrapper.cpp
@@ -1,65 +1,68 @@
1#include <stdlib.h> 1#include <stdlib.h>
2#include <sys/stat.h> 2#include <sys/stat.h>
3#include <sys/types.h> 3#include <sys/types.h>
4#include <unistd.h> 4#include <unistd.h>
5#include <fcntl.h> 5#include <fcntl.h>
6#include <string.h> 6#include <string.h>
7#include <qdir.h> 7#include <qdir.h>
8#include <qt.h> 8#include <qt.h>
9 9
10#include <libetpan/libetpan.h> 10#include <libetpan/libetpan.h>
11 11
12#include "smtpwrapper.h" 12#include "smtpwrapper.h"
13#include "mailwrapper.h" 13#include "mailwrapper.h"
14#include "mboxwrapper.h" 14#include "mboxwrapper.h"
15#include "logindialog.h" 15#include "logindialog.h"
16#include "mailtypes.h" 16#include "mailtypes.h"
17#include "defines.h" 17#include "defines.h"
18#include "sendmailprogress.h"
19
20progressMailSend*SMTPwrapper::sendProgress = 0;
18 21
19SMTPwrapper::SMTPwrapper( Settings *s ) 22SMTPwrapper::SMTPwrapper( Settings *s )
20 : QObject() 23 : QObject()
21{ 24{
22 settings = s; 25 settings = s;
23} 26}
24 27
25QString SMTPwrapper::mailsmtpError( int errnum ) 28QString SMTPwrapper::mailsmtpError( int errnum )
26{ 29{
27 switch ( errnum ) { 30 switch ( errnum ) {
28 case MAILSMTP_NO_ERROR: 31 case MAILSMTP_NO_ERROR:
29 return tr( "No error" ); 32 return tr( "No error" );
30 case MAILSMTP_ERROR_UNEXPECTED_CODE: 33 case MAILSMTP_ERROR_UNEXPECTED_CODE:
31 return tr( "Unexpected error code" ); 34 return tr( "Unexpected error code" );
32 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
33 return tr( "Service not available" ); 36 return tr( "Service not available" );
34 case MAILSMTP_ERROR_STREAM: 37 case MAILSMTP_ERROR_STREAM:
35 return tr( "Stream error" ); 38 return tr( "Stream error" );
36 case MAILSMTP_ERROR_HOSTNAME: 39 case MAILSMTP_ERROR_HOSTNAME:
37 return tr( "gethostname() failed" ); 40 return tr( "gethostname() failed" );
38 case MAILSMTP_ERROR_NOT_IMPLEMENTED: 41 case MAILSMTP_ERROR_NOT_IMPLEMENTED:
39 return tr( "Not implemented" ); 42 return tr( "Not implemented" );
40 case MAILSMTP_ERROR_ACTION_NOT_TAKEN: 43 case MAILSMTP_ERROR_ACTION_NOT_TAKEN:
41 return tr( "Error, action not taken" ); 44 return tr( "Error, action not taken" );
42 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION: 45 case MAILSMTP_ERROR_EXCEED_STORAGE_ALLOCATION:
43 return tr( "Data exceeds storage allocation" ); 46 return tr( "Data exceeds storage allocation" );
44 case MAILSMTP_ERROR_IN_PROCESSING: 47 case MAILSMTP_ERROR_IN_PROCESSING:
45 return tr( "Error in processing" ); 48 return tr( "Error in processing" );
46 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE: 49 // case MAILSMTP_ERROR_INSUFFISANT_SYSTEM_STORAGE:
47 // return tr( "Insufficient system storage" ); 50 // return tr( "Insufficient system storage" );
48 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE: 51 case MAILSMTP_ERROR_MAILBOX_UNAVAILABLE:
49 return tr( "Mailbox unavailable" ); 52 return tr( "Mailbox unavailable" );
50 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED: 53 case MAILSMTP_ERROR_MAILBOX_NAME_NOT_ALLOWED:
51 return tr( "Mailbox name not allowed" ); 54 return tr( "Mailbox name not allowed" );
52 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND: 55 case MAILSMTP_ERROR_BAD_SEQUENCE_OF_COMMAND:
53 return tr( "Bad command sequence" ); 56 return tr( "Bad command sequence" );
54 case MAILSMTP_ERROR_USER_NOT_LOCAL: 57 case MAILSMTP_ERROR_USER_NOT_LOCAL:
55 return tr( "User not local" ); 58 return tr( "User not local" );
56 case MAILSMTP_ERROR_TRANSACTION_FAILED: 59 case MAILSMTP_ERROR_TRANSACTION_FAILED:
57 return tr( "Transaction failed" ); 60 return tr( "Transaction failed" );
58 case MAILSMTP_ERROR_MEMORY: 61 case MAILSMTP_ERROR_MEMORY:
59 return tr( "Memory error" ); 62 return tr( "Memory error" );
60 case MAILSMTP_ERROR_CONNECTION_REFUSED: 63 case MAILSMTP_ERROR_CONNECTION_REFUSED:
61 return tr( "Connection refused" ); 64 return tr( "Connection refused" );
62 default: 65 default:
63 return tr( "Unknown error code" ); 66 return tr( "Unknown error code" );
64 } 67 }
65} 68}
@@ -475,97 +478,100 @@ QString SMTPwrapper::getTmpFile() {
475 unique.setNum( num++ ); 478 unique.setNum( num++ );
476 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 ); 479 } while ( list.contains( "opiemail-tmp-" + unique ) > 0 );
477 480
478 return "/tmp/opiemail-tmp-" + unique; 481 return "/tmp/opiemail-tmp-" + unique;
479} 482}
480 483
481void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) 484void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
482{ 485{
483 FILE *f; 486 FILE *f;
484 int err, col = 0; 487 int err, col = 0;
485 488
486 f = fopen( file.latin1(), "w" ); 489 f = fopen( file.latin1(), "w" );
487 if ( f == NULL ) { 490 if ( f == NULL ) {
488 qDebug( "writeToFile: error opening file" ); 491 qDebug( "writeToFile: error opening file" );
489 return; 492 return;
490 } 493 }
491 494
492 err = mailmime_write( f, &col, mail ); 495 err = mailmime_write( f, &col, mail );
493 if ( err != MAILIMF_NO_ERROR ) { 496 if ( err != MAILIMF_NO_ERROR ) {
494 fclose( f ); 497 fclose( f );
495 qDebug( "writeToFile: error writing mailmime" ); 498 qDebug( "writeToFile: error writing mailmime" );
496 return; 499 return;
497 } 500 }
498 501
499 fclose( f ); 502 fclose( f );
500} 503}
501 504
502void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) 505void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
503{ 506{
504 507
505 QFile msg_cache(file); 508 QFile msg_cache(file);
506 QString msg = ""; 509 QString msg = "";
507 msg_cache.open(IO_ReadOnly); 510 msg_cache.open(IO_ReadOnly);
508 char*message = new char[4096]; 511 char*message = new char[4096];
509 memset(message,0,4096); 512 memset(message,0,4096);
510 while (msg_cache.readBlock(message,4095)>0) { 513 while (msg_cache.readBlock(message,4095)>0) {
511 msg+=message; 514 msg+=message;
512 memset(message,0,4096); 515 memset(message,0,4096);
513 } 516 }
514 delete message; 517 delete message;
515 *data = (char*)malloc(msg.length()+1*sizeof(char)); 518 *data = (char*)malloc(msg.length()+1*sizeof(char));
516 memset(*data,0,msg.length()+1); 519 memset(*data,0,msg.length()+1);
517 memcpy(*data,msg.ascii(),msg.length()); 520 memcpy(*data,msg.ascii(),msg.length());
518 *size=msg.length(); 521 *size=msg.length();
519} 522}
520 523
521void SMTPwrapper::progress( size_t current, size_t maximum ) 524void SMTPwrapper::progress( size_t current, size_t maximum )
522{ 525{
523// qDebug( "Current: %i of %i", current, maximum ); 526 if (SMTPwrapper::sendProgress) {
527 SMTPwrapper::sendProgress->setSingleMail(current, maximum );
528 qDebug("%u of %u",current,maximum);
529 }
524} 530}
525 531
526void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) 532void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
527{ 533{
528 if (!mail) return; 534 if (!mail) return;
529 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 535 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
530 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 536 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
531 wrap->storeMessage(mail,length,box); 537 wrap->storeMessage(mail,length,box);
532 delete wrap; 538 delete wrap;
533} 539}
534 540
535void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 541void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
536{ 542{
537 clist *rcpts = 0; 543 clist *rcpts = 0;
538 char *from, *data; 544 char *from, *data;
539 size_t size; 545 size_t size;
540 546
541 if ( smtp == NULL ) { 547 if ( smtp == NULL ) {
542 return; 548 return;
543 } 549 }
544 from = data = 0; 550 from = data = 0;
545 551
546 QString file = getTmpFile(); 552 QString file = getTmpFile();
547 writeToFile( file, mail ); 553 writeToFile( file, mail );
548 readFromFile( file, &data, &size ); 554 readFromFile( file, &data, &size );
549 QFile f( file ); 555 QFile f( file );
550 f.remove(); 556 f.remove();
551 557
552 if (later) { 558 if (later) {
553 storeMail(data,size,"Outgoing"); 559 storeMail(data,size,"Outgoing");
554 if (data) free( data ); 560 if (data) free( data );
555 return; 561 return;
556 } 562 }
557 from = getFrom( mail ); 563 from = getFrom( mail );
558 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 564 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
559 smtpSend(from,rcpts,data,size,smtp); 565 smtpSend(from,rcpts,data,size,smtp);
560} 566}
561 567
562int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 568int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
563{ 569{
564 char *server, *user, *pass; 570 char *server, *user, *pass;
565 bool ssl; 571 bool ssl;
566 uint16_t port; 572 uint16_t port;
567 mailsmtp *session; 573 mailsmtp *session;
568 int err,result; 574 int err,result;
569 575
570 result = 1; 576 result = 1;
571 server = user = pass = 0; 577 server = user = pass = 0;
@@ -600,115 +606,123 @@ int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccou
600 // ok 606 // ok
601 user = strdup( login.getUser().latin1() ); 607 user = strdup( login.getUser().latin1() );
602 pass = strdup( login.getPassword().latin1() ); 608 pass = strdup( login.getPassword().latin1() );
603 } else { 609 } else {
604 result = 0; goto free_con_session; 610 result = 0; goto free_con_session;
605 } 611 }
606 } else { 612 } else {
607 user = strdup( smtp->getUser().latin1() ); 613 user = strdup( smtp->getUser().latin1() );
608 pass = strdup( smtp->getPassword().latin1() ); 614 pass = strdup( smtp->getPassword().latin1() );
609 } 615 }
610 qDebug( "session->auth: %i", session->auth); 616 qDebug( "session->auth: %i", session->auth);
611 err = mailsmtp_auth( session, user, pass ); 617 err = mailsmtp_auth( session, user, pass );
612 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok"); 618 if ( err == MAILSMTP_NO_ERROR ) qDebug("auth ok");
613 qDebug( "Done auth!" ); 619 qDebug( "Done auth!" );
614 } 620 }
615 621
616 err = mailsmtp_send( session, from, rcpts, data, size ); 622 err = mailsmtp_send( session, from, rcpts, data, size );
617 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;} 623 if ( err != MAILSMTP_NO_ERROR ) {result = 0; goto free_con_session;}
618 624
619 qDebug( "Mail sent." ); 625 qDebug( "Mail sent." );
620 storeMail(data,size,"Sent"); 626 storeMail(data,size,"Sent");
621 627
622free_con_session: 628free_con_session:
623 mailsmtp_quit( session ); 629 mailsmtp_quit( session );
624free_mem_session: 630free_mem_session:
625 mailsmtp_free( session ); 631 mailsmtp_free( session );
626free_mem: 632free_mem:
627 if (rcpts) smtp_address_list_free( rcpts ); 633 if (rcpts) smtp_address_list_free( rcpts );
628 if (data) free( data ); 634 if (data) free( data );
629 if (server) free( server ); 635 if (server) free( server );
630 if (from) free( from ); 636 if (from) free( from );
631 if ( smtp->getLogin() ) { 637 if ( smtp->getLogin() ) {
632 free( user ); 638 free( user );
633 free( pass ); 639 free( pass );
634 } 640 }
635 return result; 641 return result;
636} 642}
637 643
638void SMTPwrapper::sendMail(const Mail&mail,bool later ) 644void SMTPwrapper::sendMail(const Mail&mail,bool later )
639{ 645{
640 mailmime * mimeMail; 646 mailmime * mimeMail;
641 647
642 SMTPaccount *smtp = getAccount(mail.getName()); 648 SMTPaccount *smtp = getAccount(mail.getName());
643 649
644 mimeMail = createMimeMail(mail ); 650 mimeMail = createMimeMail(mail );
645 if ( mimeMail == NULL ) { 651 if ( mimeMail == NULL ) {
646 qDebug( "sendMail: error creating mime mail" ); 652 qDebug( "sendMail: error creating mime mail" );
647 } else { 653 } else {
654 sendProgress = new progressMailSend();
655 sendProgress->showMaximized();
656 sendProgress->show();
657 qApp->processEvents(10);
648 smtpSend( mimeMail,later,smtp); 658 smtpSend( mimeMail,later,smtp);
649 mailmime_free( mimeMail ); 659 mailmime_free( mimeMail );
650 qDebug("Clean up done"); 660 qDebug("Clean up done");
661 sendProgress->hide();
662 delete sendProgress;
663 sendProgress = 0;
651 } 664 }
652} 665}
653 666
654int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) 667int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
655{ 668{
656 char*data = 0; 669 char*data = 0;
657 size_t length = 0; 670 size_t length = 0;
658 size_t curTok = 0; 671 size_t curTok = 0;
659 mailimf_fields *fields = 0; 672 mailimf_fields *fields = 0;
660 mailimf_field*ffrom = 0; 673 mailimf_field*ffrom = 0;
661 clist *rcpts = 0; 674 clist *rcpts = 0;
662 char*from = 0; 675 char*from = 0;
663 676
664 wrap->fetchRawBody(*which,&data,&length); 677 wrap->fetchRawBody(*which,&data,&length);
665 if (!data) return 0; 678 if (!data) return 0;
666 int err = mailimf_fields_parse( data, length, &curTok, &fields ); 679 int err = mailimf_fields_parse( data, length, &curTok, &fields );
667 if (err != MAILIMF_NO_ERROR) { 680 if (err != MAILIMF_NO_ERROR) {
668 free(data); 681 free(data);
669 delete wrap; 682 delete wrap;
670 return 0; 683 return 0;
671 } 684 }
672 685
673 rcpts = createRcptList( fields ); 686 rcpts = createRcptList( fields );
674 ffrom = getField(fields, MAILIMF_FIELD_FROM ); 687 ffrom = getField(fields, MAILIMF_FIELD_FROM );
675 from = getFrom(ffrom); 688 from = getFrom(ffrom);
689
676 qDebug("Size: %i vs. %i",length,strlen(data)); 690 qDebug("Size: %i vs. %i",length,strlen(data));
677 if (rcpts && from) { 691 if (rcpts && from) {
678 return smtpSend(from,rcpts,data,strlen(data),smtp ); 692 return smtpSend(from,rcpts,data,strlen(data),smtp );
679 } 693 }
680 return 0; 694 return 0;
681} 695}
682 696
683/* this is a special fun */ 697/* this is a special fun */
684void SMTPwrapper::flushOutbox(SMTPaccount*smtp) 698void SMTPwrapper::flushOutbox(SMTPaccount*smtp)
685{ 699{
686 if (!smtp) return; 700 if (!smtp) return;
687 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); 701 QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/");
688 MBOXwrapper*wrap = new MBOXwrapper(localfolders); 702 MBOXwrapper*wrap = new MBOXwrapper(localfolders);
689 if (!wrap) { 703 if (!wrap) {
690 qDebug("memory error"); 704 qDebug("memory error");
691 return; 705 return;
692 } 706 }
693 QList<RecMail> mailsToSend; 707 QList<RecMail> mailsToSend;
694 QList<RecMail> mailsToRemove; 708 QList<RecMail> mailsToRemove;
695 QString mbox("Outgoing"); 709 QString mbox("Outgoing");
696 wrap->listMessages(mbox,mailsToSend); 710 wrap->listMessages(mbox,mailsToSend);
697 if (mailsToSend.count()==0) { 711 if (mailsToSend.count()==0) {
698 delete wrap; 712 delete wrap;
699 return; 713 return;
700 } 714 }
701 mailsToSend.setAutoDelete(false); 715 mailsToSend.setAutoDelete(false);
702 while (mailsToSend.count()>0) { 716 while (mailsToSend.count()>0) {
703 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 717 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
704 QMessageBox::critical(0,tr("Error sending mail"), 718 QMessageBox::critical(0,tr("Error sending mail"),
705 tr("Error sending queued mail - breaking")); 719 tr("Error sending queued mail - breaking"));
706 break; 720 break;
707 } 721 }
708 mailsToRemove.append(mailsToSend.at(0)); 722 mailsToRemove.append(mailsToSend.at(0));
709 mailsToSend.removeFirst(); 723 mailsToSend.removeFirst();
710 } 724 }
711 wrap->deleteMails(mbox,mailsToRemove); 725 wrap->deleteMails(mbox,mailsToRemove);
712 mailsToSend.setAutoDelete(true); 726 mailsToSend.setAutoDelete(true);
713 delete wrap; 727 delete wrap;
714} 728}
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h
index c0dcc11..baa353b 100644
--- a/noncore/net/mail/smtpwrapper.h
+++ b/noncore/net/mail/smtpwrapper.h
@@ -1,63 +1,65 @@
1#ifndef SMTPwrapper_H 1#ifndef SMTPwrapper_H
2#define SMTPwrapper_H 2#define SMTPwrapper_H
3 3
4#include <qpe/applnk.h> 4#include <qpe/applnk.h>
5 5
6#include <qbitarray.h> 6#include <qbitarray.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <libetpan/clist.h> 8#include <libetpan/clist.h>
9 9
10#include "settings.h" 10#include "settings.h"
11 11
12class Mail; 12class Mail;
13class MBOXwrapper; 13class MBOXwrapper;
14class RecMail; 14class RecMail;
15class Attachment; 15class Attachment;
16struct mailimf_fields; 16struct mailimf_fields;
17struct mailimf_field; 17struct mailimf_field;
18struct mailimf_mailbox; 18struct mailimf_mailbox;
19struct mailmime; 19struct mailmime;
20struct mailimf_address_list; 20struct mailimf_address_list;
21class progressMailSend;
21 22
22class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
23{ 24{
24 Q_OBJECT 25 Q_OBJECT
25 26
26public: 27public:
27 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
28 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
29 void sendMail(const Mail& mail,bool later=false ); 30 void sendMail(const Mail& mail,bool later=false );
30 void flushOutbox(SMTPaccount*smtp); 31 void flushOutbox(SMTPaccount*smtp);
31 32
33 static progressMailSend*sendProgress;
32protected: 34protected:
33 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
34 mailimf_fields *createImfFields(const Mail &mail ); 36 mailimf_fields *createImfFields(const Mail &mail );
35 mailmime *createMimeMail(const Mail&mail ); 37 mailmime *createMimeMail(const Mail&mail );
36 38
37 mailimf_address_list *parseAddresses(const QString&addr ); 39 mailimf_address_list *parseAddresses(const QString&addr );
38 void addFileParts( mailmime *message,const QList<Attachment>&files ); 40 void addFileParts( mailmime *message,const QList<Attachment>&files );
39 mailmime *buildTxtPart(const QString&str ); 41 mailmime *buildTxtPart(const QString&str );
40 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
41 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
42 clist *createRcptList( mailimf_fields *fields ); 44 clist *createRcptList( mailimf_fields *fields );
43 SMTPaccount *getAccount(const QString&from ); 45 SMTPaccount *getAccount(const QString&from );
44 void writeToFile(const QString&file, mailmime *mail ); 46 void writeToFile(const QString&file, mailmime *mail );
45 void readFromFile(const QString&file, char **data, size_t *size ); 47 void readFromFile(const QString&file, char **data, size_t *size );
46 48
47 static void storeMail(char*mail, size_t length, const QString&box); 49 static void storeMail(char*mail, size_t length, const QString&box);
48 static QString mailsmtpError( int err ); 50 static QString mailsmtpError( int err );
49 static QString getTmpFile(); 51 static QString getTmpFile();
50 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
51 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
52 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
53 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
54 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
55 static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); 57 int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp );
56 58
57 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
58 Settings *settings; 60 Settings *settings;
59 61
60 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
61}; 63};
62 64
63#endif 65#endif