summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp30
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h10
-rw-r--r--noncore/net/mail/opiemail.cpp3
-rw-r--r--noncore/net/mail/smtpwrapper.cpp30
-rw-r--r--noncore/net/mail/smtpwrapper.h10
5 files changed, 75 insertions, 8 deletions
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 30c0707..7e03af9 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,37 +1,50 @@
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 <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h>
12
10#include <libetpan/libetpan.h> 13#include <libetpan/libetpan.h>
11 14
12#include "smtpwrapper.h" 15#include "smtpwrapper.h"
13#include "mailwrapper.h" 16#include "mailwrapper.h"
14#include "mboxwrapper.h" 17#include "mboxwrapper.h"
15#include "logindialog.h" 18#include "logindialog.h"
16#include "mailtypes.h" 19#include "mailtypes.h"
17#include "defines.h" 20#include "defines.h"
18#include "sendmailprogress.h" 21#include "sendmailprogress.h"
19 22
20progressMailSend*SMTPwrapper::sendProgress = 0; 23progressMailSend*SMTPwrapper::sendProgress = 0;
21 24
22SMTPwrapper::SMTPwrapper( Settings *s ) 25SMTPwrapper::SMTPwrapper( Settings *s )
23 : QObject() 26 : QObject()
24{ 27{
25 settings = s; 28 settings = s;
29 Config cfg( "mail" );
30 cfg.setGroup( "Status" );
31 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
32 emit queuedMails( m_queuedMail );
33 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
34}
35
36void SMTPwrapper::emitQCop( int queued ) {
37 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
38 env << queued;
26} 39}
27 40
28QString SMTPwrapper::mailsmtpError( int errnum ) 41QString SMTPwrapper::mailsmtpError( int errnum )
29{ 42{
30 switch ( errnum ) { 43 switch ( errnum ) {
31 case MAILSMTP_NO_ERROR: 44 case MAILSMTP_NO_ERROR:
32 return tr( "No error" ); 45 return tr( "No error" );
33 case MAILSMTP_ERROR_UNEXPECTED_CODE: 46 case MAILSMTP_ERROR_UNEXPECTED_CODE:
34 return tr( "Unexpected error code" ); 47 return tr( "Unexpected error code" );
35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 48 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
36 return tr( "Service not available" ); 49 return tr( "Service not available" );
37 case MAILSMTP_ERROR_STREAM: 50 case MAILSMTP_ERROR_STREAM:
@@ -239,25 +252,25 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
239 mailmime_parameter * param = 0; 252 mailmime_parameter * param = 0;
240 char*name = 0; 253 char*name = 0;
241 char*file = 0; 254 char*file = 0;
242 int err; 255 int err;
243 256
244 int pos = filename.findRev( '/' ); 257 int pos = filename.findRev( '/' );
245 258
246 if (filename.length()>0) { 259 if (filename.length()>0) {
247 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 260 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
248 name = strdup( tmp.latin1() ); // just filename 261 name = strdup( tmp.latin1() ); // just filename
249 file = strdup( filename.latin1() ); // full name with path 262 file = strdup( filename.latin1() ); // full name with path
250 } 263 }
251 264
252 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 265 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
253 int mechanism = MAILMIME_MECHANISM_BASE64; 266 int mechanism = MAILMIME_MECHANISM_BASE64;
254 267
255 if ( mimetype.startsWith( "text/" ) ) { 268 if ( mimetype.startsWith( "text/" ) ) {
256 param = mailmime_parameter_new( strdup( "charset" ), 269 param = mailmime_parameter_new( strdup( "charset" ),
257 strdup( "iso-8859-1" ) ); 270 strdup( "iso-8859-1" ) );
258 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 271 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
259 } 272 }
260 273
261 fields = mailmime_fields_new_filename( 274 fields = mailmime_fields_new_filename(
262 disptype, name, 275 disptype, name,
263 mechanism ); 276 mechanism );
@@ -341,25 +354,25 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
341 mailimf_fields *fields; 354 mailimf_fields *fields;
342 int err; 355 int err;
343 356
344 fields = createImfFields( mail ); 357 fields = createImfFields( mail );
345 if ( fields == NULL ) goto err_free; 358 if ( fields == NULL ) goto err_free;
346 359
347 message = mailmime_new_message_data( NULL ); 360 message = mailmime_new_message_data( NULL );
348 if ( message == NULL ) goto err_free_fields; 361 if ( message == NULL ) goto err_free_fields;
349 362
350 mailmime_set_imf_fields( message, fields ); 363 mailmime_set_imf_fields( message, fields );
351 364
352 txtPart = buildTxtPart( mail.getMessage() ); 365 txtPart = buildTxtPart( mail.getMessage() );
353 366
354 if ( txtPart == NULL ) goto err_free_message; 367 if ( txtPart == NULL ) goto err_free_message;
355 368
356 err = mailmime_smart_add_part( message, txtPart ); 369 err = mailmime_smart_add_part( message, txtPart );
357 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 370 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
358 371
359 addFileParts( message, mail.getAttachments() ); 372 addFileParts( message, mail.getAttachments() );
360 373
361 return message; // Success :) 374 return message; // Success :)
362 375
363err_free_txtPart: 376err_free_txtPart:
364 mailmime_free( txtPart ); 377 mailmime_free( txtPart );
365err_free_message: 378err_free_message:
@@ -480,42 +493,46 @@ void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
480} 493}
481 494
482void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 495void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
483{ 496{
484 clist *rcpts = 0; 497 clist *rcpts = 0;
485 char *from, *data; 498 char *from, *data;
486 size_t size; 499 size_t size;
487 500
488 if ( smtp == NULL ) { 501 if ( smtp == NULL ) {
489 return; 502 return;
490 } 503 }
491 from = data = 0; 504 from = data = 0;
492 505
493 mailmessage * msg = 0; 506 mailmessage * msg = 0;
494 msg = mime_message_init(mail); 507 msg = mime_message_init(mail);
495 mime_message_set_tmpdir(msg,getenv( "HOME" )); 508 mime_message_set_tmpdir(msg,getenv( "HOME" ));
496 int r = mailmessage_fetch(msg,&data,&size); 509 int r = mailmessage_fetch(msg,&data,&size);
497 mime_message_detach_mime(msg); 510 mime_message_detach_mime(msg);
498 mailmessage_free(msg); 511 mailmessage_free(msg);
499 if (r != MAIL_NO_ERROR || !data) { 512 if (r != MAIL_NO_ERROR || !data) {
500 if (data) free(data); 513 if (data) free(data);
501 qDebug("Error fetching mime..."); 514 qDebug("Error fetching mime...");
502 return; 515 return;
503 } 516 }
504 QString tmp = data; 517 QString tmp = data;
505 tmp.replace(QRegExp("\r+",true,false),""); 518 tmp.replace(QRegExp("\r+",true,false),"");
506 msg = 0; 519 msg = 0;
507 if (later) { 520 if (later) {
508 storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); 521 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
509 if (data) free( data ); 522 if (data) free( data );
523 Config cfg( "mail" );
524 cfg.setGroup( "Status" );
525 cfg.writeEntry( "outgoing", ++m_queuedMail );
526 emit queuedMails( m_queuedMail );
510 return; 527 return;
511 } 528 }
512 from = getFrom( mail ); 529 from = getFrom( mail );
513 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 530 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
514 smtpSend(from,rcpts,data,size,smtp); 531 smtpSend(from,rcpts,data,size,smtp);
515 if (data) {free(data);} 532 if (data) {free(data);}
516 if (from) {free(from);} 533 if (from) {free(from);}
517 if (rcpts) smtp_address_list_free( rcpts ); 534 if (rcpts) smtp_address_list_free( rcpts );
518} 535}
519 536
520int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 537int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
521{ 538{
@@ -644,25 +661,25 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
644 from = getFrom(ffrom); 661 from = getFrom(ffrom);
645 662
646 qDebug("Size: %i vs. %i",length,strlen(data)); 663 qDebug("Size: %i vs. %i",length,strlen(data));
647 if (rcpts && from) { 664 if (rcpts && from) {
648 res = smtpSend(from,rcpts,data,length,smtp ); 665 res = smtpSend(from,rcpts,data,length,smtp );
649 } 666 }
650 if (fields) { 667 if (fields) {
651 mailimf_fields_free(fields); 668 mailimf_fields_free(fields);
652 fields = 0; 669 fields = 0;
653 } 670 }
654 if (data) { 671 if (data) {
655 free(data); 672 free(data);
656 } 673 }
657 if (from) { 674 if (from) {
658 free(from); 675 free(from);
659 } 676 }
660 if (rcpts) { 677 if (rcpts) {
661 smtp_address_list_free( rcpts ); 678 smtp_address_list_free( rcpts );
662 } 679 }
663 return res; 680 return res;
664} 681}
665 682
666/* this is a special fun */ 683/* this is a special fun */
667bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 684bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
668{ 685{
@@ -691,20 +708,25 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
691 708
692 while (mailsToSend.count()>0) { 709 while (mailsToSend.count()>0) {
693 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 710 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
694 QMessageBox::critical(0,tr("Error sending mail"), 711 QMessageBox::critical(0,tr("Error sending mail"),
695 tr("Error sending queued mail - breaking")); 712 tr("Error sending queued mail - breaking"));
696 returnValue = false; 713 returnValue = false;
697 break; 714 break;
698 } 715 }
699 mailsToRemove.append(mailsToSend.at(0)); 716 mailsToRemove.append(mailsToSend.at(0));
700 mailsToSend.removeFirst(); 717 mailsToSend.removeFirst();
701 sendProgress->setCurrentMails(mailsToRemove.count()); 718 sendProgress->setCurrentMails(mailsToRemove.count());
702 } 719 }
720 Config cfg( "mail" );
721 cfg.setGroup( "Status" );
722 m_queuedMail = 0;
723 cfg.writeEntry( "outgoing", m_queuedMail );
724 emit queuedMails( m_queuedMail );
703 sendProgress->hide(); 725 sendProgress->hide();
704 delete sendProgress; 726 delete sendProgress;
705 sendProgress = 0; 727 sendProgress = 0;
706 wrap->deleteMails(mbox,mailsToRemove); 728 wrap->deleteMails(mbox,mailsToRemove);
707 mailsToSend.setAutoDelete(true); 729 mailsToSend.setAutoDelete(true);
708 delete wrap; 730 delete wrap;
709 return returnValue; 731 return returnValue;
710} 732}
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 0535983..05becf2 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -22,24 +22,28 @@ class progressMailSend;
22 22
23class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26 26
27public: 27public:
28 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
29 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); 30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
31 bool flushOutbox(SMTPaccount*smtp); 31 bool flushOutbox(SMTPaccount*smtp);
32 32
33 static progressMailSend*sendProgress; 33 static progressMailSend*sendProgress;
34
35signals:
36 void queuedMails( int );
37
34protected: 38protected:
35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
36 mailimf_fields *createImfFields(const Mail &mail ); 40 mailimf_fields *createImfFields(const Mail &mail );
37 mailmime *createMimeMail(const Mail&mail ); 41 mailmime *createMimeMail(const Mail&mail );
38 42
39 mailimf_address_list *parseAddresses(const QString&addr ); 43 mailimf_address_list *parseAddresses(const QString&addr );
40 void addFileParts( mailmime *message,const QList<Attachment>&files ); 44 void addFileParts( mailmime *message,const QList<Attachment>&files );
41 mailmime *buildTxtPart(const QString&str ); 45 mailmime *buildTxtPart(const QString&str );
42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
44 clist *createRcptList( mailimf_fields *fields ); 48 clist *createRcptList( mailimf_fields *fields );
45 49
@@ -47,15 +51,21 @@ protected:
47 static QString mailsmtpError( int err ); 51 static QString mailsmtpError( int err );
48 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
49 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
50 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
51 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
52 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
53 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 );
54 58
55 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
56 Settings *settings; 60 Settings *settings;
57 61
58 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63
64 int m_queuedMail;
65
66protected slots:
67 void emitQCop( int queued );
68
59}; 69};
60 70
61#endif 71#endif
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index e35f5b6..54453b7 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -16,24 +16,27 @@ OpieMail::OpieMail( QWidget *parent, const char *name, WFlags flags )
16 folderView->populate( settings->getAccounts() ); 16 folderView->populate( settings->getAccounts() );
17 17
18 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) ); 18 connect( composeMail, SIGNAL( activated() ), SLOT( slotComposeMail() ) );
19 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) ); 19 connect( sendQueued, SIGNAL( activated() ), SLOT( slotSendQueued() ) );
20// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) ); 20// connect( searchMails, SIGNAL( activated() ), SLOT( slotSearchMails() ) );
21 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) ); 21 connect( editAccounts, SIGNAL( activated() ), SLOT( slotEditAccounts() ) );
22 // Added by Stefan Eilers to allow starting by addressbook.. 22 // Added by Stefan Eilers to allow starting by addressbook..
23 // copied from old mail2 23 // copied from old mail2
24#if !defined(QT_NO_COP) 24#if !defined(QT_NO_COP)
25 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), 25 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ),
26 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 26 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
27#endif 27#endif
28
29
30
28} 31}
29 32
30void OpieMail::appMessage(const QCString &msg, const QByteArray &data) 33void OpieMail::appMessage(const QCString &msg, const QByteArray &data)
31{ 34{
32 // copied from old mail2 35 // copied from old mail2
33 if (msg == "writeMail(QString,QString)") { 36 if (msg == "writeMail(QString,QString)") {
34 QDataStream stream(data,IO_ReadOnly); 37 QDataStream stream(data,IO_ReadOnly);
35 QString name, email; 38 QString name, email;
36 stream >> name >> email; 39 stream >> name >> email;
37 // removing the whitespaces at beginning and end is needed! 40 // removing the whitespaces at beginning and end is needed!
38 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace()); 41 slotwriteMail(name.stripWhiteSpace(),email.stripWhiteSpace());
39 } else if (msg == "newMail()") { 42 } else if (msg == "newMail()") {
diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp
index 30c0707..7e03af9 100644
--- a/noncore/net/mail/smtpwrapper.cpp
+++ b/noncore/net/mail/smtpwrapper.cpp
@@ -1,37 +1,50 @@
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 <qpe/config.h>
11#include <qpe/qcopenvelope_qws.h>
12
10#include <libetpan/libetpan.h> 13#include <libetpan/libetpan.h>
11 14
12#include "smtpwrapper.h" 15#include "smtpwrapper.h"
13#include "mailwrapper.h" 16#include "mailwrapper.h"
14#include "mboxwrapper.h" 17#include "mboxwrapper.h"
15#include "logindialog.h" 18#include "logindialog.h"
16#include "mailtypes.h" 19#include "mailtypes.h"
17#include "defines.h" 20#include "defines.h"
18#include "sendmailprogress.h" 21#include "sendmailprogress.h"
19 22
20progressMailSend*SMTPwrapper::sendProgress = 0; 23progressMailSend*SMTPwrapper::sendProgress = 0;
21 24
22SMTPwrapper::SMTPwrapper( Settings *s ) 25SMTPwrapper::SMTPwrapper( Settings *s )
23 : QObject() 26 : QObject()
24{ 27{
25 settings = s; 28 settings = s;
29 Config cfg( "mail" );
30 cfg.setGroup( "Status" );
31 m_queuedMail = cfg.readNumEntry( "outgoing", 0 );
32 emit queuedMails( m_queuedMail );
33 connect( this, SIGNAL( queuedMails( int ) ), this, SLOT( emitQCop( int ) ) );
34}
35
36void SMTPwrapper::emitQCop( int queued ) {
37 QCopEnvelope env( "QPE/Pim", "outgoingMails(int)" );
38 env << queued;
26} 39}
27 40
28QString SMTPwrapper::mailsmtpError( int errnum ) 41QString SMTPwrapper::mailsmtpError( int errnum )
29{ 42{
30 switch ( errnum ) { 43 switch ( errnum ) {
31 case MAILSMTP_NO_ERROR: 44 case MAILSMTP_NO_ERROR:
32 return tr( "No error" ); 45 return tr( "No error" );
33 case MAILSMTP_ERROR_UNEXPECTED_CODE: 46 case MAILSMTP_ERROR_UNEXPECTED_CODE:
34 return tr( "Unexpected error code" ); 47 return tr( "Unexpected error code" );
35 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: 48 case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE:
36 return tr( "Service not available" ); 49 return tr( "Service not available" );
37 case MAILSMTP_ERROR_STREAM: 50 case MAILSMTP_ERROR_STREAM:
@@ -239,25 +252,25 @@ mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimety
239 mailmime_parameter * param = 0; 252 mailmime_parameter * param = 0;
240 char*name = 0; 253 char*name = 0;
241 char*file = 0; 254 char*file = 0;
242 int err; 255 int err;
243 256
244 int pos = filename.findRev( '/' ); 257 int pos = filename.findRev( '/' );
245 258
246 if (filename.length()>0) { 259 if (filename.length()>0) {
247 QString tmp = filename.right( filename.length() - ( pos + 1 ) ); 260 QString tmp = filename.right( filename.length() - ( pos + 1 ) );
248 name = strdup( tmp.latin1() ); // just filename 261 name = strdup( tmp.latin1() ); // just filename
249 file = strdup( filename.latin1() ); // full name with path 262 file = strdup( filename.latin1() ); // full name with path
250 } 263 }
251 264
252 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT; 265 int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
253 int mechanism = MAILMIME_MECHANISM_BASE64; 266 int mechanism = MAILMIME_MECHANISM_BASE64;
254 267
255 if ( mimetype.startsWith( "text/" ) ) { 268 if ( mimetype.startsWith( "text/" ) ) {
256 param = mailmime_parameter_new( strdup( "charset" ), 269 param = mailmime_parameter_new( strdup( "charset" ),
257 strdup( "iso-8859-1" ) ); 270 strdup( "iso-8859-1" ) );
258 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE; 271 mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
259 } 272 }
260 273
261 fields = mailmime_fields_new_filename( 274 fields = mailmime_fields_new_filename(
262 disptype, name, 275 disptype, name,
263 mechanism ); 276 mechanism );
@@ -341,25 +354,25 @@ mailmime *SMTPwrapper::createMimeMail(const Mail &mail )
341 mailimf_fields *fields; 354 mailimf_fields *fields;
342 int err; 355 int err;
343 356
344 fields = createImfFields( mail ); 357 fields = createImfFields( mail );
345 if ( fields == NULL ) goto err_free; 358 if ( fields == NULL ) goto err_free;
346 359
347 message = mailmime_new_message_data( NULL ); 360 message = mailmime_new_message_data( NULL );
348 if ( message == NULL ) goto err_free_fields; 361 if ( message == NULL ) goto err_free_fields;
349 362
350 mailmime_set_imf_fields( message, fields ); 363 mailmime_set_imf_fields( message, fields );
351 364
352 txtPart = buildTxtPart( mail.getMessage() ); 365 txtPart = buildTxtPart( mail.getMessage() );
353 366
354 if ( txtPart == NULL ) goto err_free_message; 367 if ( txtPart == NULL ) goto err_free_message;
355 368
356 err = mailmime_smart_add_part( message, txtPart ); 369 err = mailmime_smart_add_part( message, txtPart );
357 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart; 370 if ( err != MAILIMF_NO_ERROR ) goto err_free_txtPart;
358 371
359 addFileParts( message, mail.getAttachments() ); 372 addFileParts( message, mail.getAttachments() );
360 373
361 return message; // Success :) 374 return message; // Success :)
362 375
363err_free_txtPart: 376err_free_txtPart:
364 mailmime_free( txtPart ); 377 mailmime_free( txtPart );
365err_free_message: 378err_free_message:
@@ -480,42 +493,46 @@ void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box)
480} 493}
481 494
482void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) 495void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp )
483{ 496{
484 clist *rcpts = 0; 497 clist *rcpts = 0;
485 char *from, *data; 498 char *from, *data;
486 size_t size; 499 size_t size;
487 500
488 if ( smtp == NULL ) { 501 if ( smtp == NULL ) {
489 return; 502 return;
490 } 503 }
491 from = data = 0; 504 from = data = 0;
492 505
493 mailmessage * msg = 0; 506 mailmessage * msg = 0;
494 msg = mime_message_init(mail); 507 msg = mime_message_init(mail);
495 mime_message_set_tmpdir(msg,getenv( "HOME" )); 508 mime_message_set_tmpdir(msg,getenv( "HOME" ));
496 int r = mailmessage_fetch(msg,&data,&size); 509 int r = mailmessage_fetch(msg,&data,&size);
497 mime_message_detach_mime(msg); 510 mime_message_detach_mime(msg);
498 mailmessage_free(msg); 511 mailmessage_free(msg);
499 if (r != MAIL_NO_ERROR || !data) { 512 if (r != MAIL_NO_ERROR || !data) {
500 if (data) free(data); 513 if (data) free(data);
501 qDebug("Error fetching mime..."); 514 qDebug("Error fetching mime...");
502 return; 515 return;
503 } 516 }
504 QString tmp = data; 517 QString tmp = data;
505 tmp.replace(QRegExp("\r+",true,false),""); 518 tmp.replace(QRegExp("\r+",true,false),"");
506 msg = 0; 519 msg = 0;
507 if (later) { 520 if (later) {
508 storeMail((char*)tmp.data(),tmp.length(),"Outgoing"); 521 storeMail((char*)tmp.data(),tmp.length(),"Outgoing");
509 if (data) free( data ); 522 if (data) free( data );
523 Config cfg( "mail" );
524 cfg.setGroup( "Status" );
525 cfg.writeEntry( "outgoing", ++m_queuedMail );
526 emit queuedMails( m_queuedMail );
510 return; 527 return;
511 } 528 }
512 from = getFrom( mail ); 529 from = getFrom( mail );
513 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); 530 rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
514 smtpSend(from,rcpts,data,size,smtp); 531 smtpSend(from,rcpts,data,size,smtp);
515 if (data) {free(data);} 532 if (data) {free(data);}
516 if (from) {free(from);} 533 if (from) {free(from);}
517 if (rcpts) smtp_address_list_free( rcpts ); 534 if (rcpts) smtp_address_list_free( rcpts );
518} 535}
519 536
520int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ) 537int SMTPwrapper::smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp )
521{ 538{
@@ -644,25 +661,25 @@ int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which)
644 from = getFrom(ffrom); 661 from = getFrom(ffrom);
645 662
646 qDebug("Size: %i vs. %i",length,strlen(data)); 663 qDebug("Size: %i vs. %i",length,strlen(data));
647 if (rcpts && from) { 664 if (rcpts && from) {
648 res = smtpSend(from,rcpts,data,length,smtp ); 665 res = smtpSend(from,rcpts,data,length,smtp );
649 } 666 }
650 if (fields) { 667 if (fields) {
651 mailimf_fields_free(fields); 668 mailimf_fields_free(fields);
652 fields = 0; 669 fields = 0;
653 } 670 }
654 if (data) { 671 if (data) {
655 free(data); 672 free(data);
656 } 673 }
657 if (from) { 674 if (from) {
658 free(from); 675 free(from);
659 } 676 }
660 if (rcpts) { 677 if (rcpts) {
661 smtp_address_list_free( rcpts ); 678 smtp_address_list_free( rcpts );
662 } 679 }
663 return res; 680 return res;
664} 681}
665 682
666/* this is a special fun */ 683/* this is a special fun */
667bool SMTPwrapper::flushOutbox(SMTPaccount*smtp) 684bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
668{ 685{
@@ -691,20 +708,25 @@ bool SMTPwrapper::flushOutbox(SMTPaccount*smtp)
691 708
692 while (mailsToSend.count()>0) { 709 while (mailsToSend.count()>0) {
693 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) { 710 if (sendQueuedMail(wrap,smtp,mailsToSend.at(0))==0) {
694 QMessageBox::critical(0,tr("Error sending mail"), 711 QMessageBox::critical(0,tr("Error sending mail"),
695 tr("Error sending queued mail - breaking")); 712 tr("Error sending queued mail - breaking"));
696 returnValue = false; 713 returnValue = false;
697 break; 714 break;
698 } 715 }
699 mailsToRemove.append(mailsToSend.at(0)); 716 mailsToRemove.append(mailsToSend.at(0));
700 mailsToSend.removeFirst(); 717 mailsToSend.removeFirst();
701 sendProgress->setCurrentMails(mailsToRemove.count()); 718 sendProgress->setCurrentMails(mailsToRemove.count());
702 } 719 }
720 Config cfg( "mail" );
721 cfg.setGroup( "Status" );
722 m_queuedMail = 0;
723 cfg.writeEntry( "outgoing", m_queuedMail );
724 emit queuedMails( m_queuedMail );
703 sendProgress->hide(); 725 sendProgress->hide();
704 delete sendProgress; 726 delete sendProgress;
705 sendProgress = 0; 727 sendProgress = 0;
706 wrap->deleteMails(mbox,mailsToRemove); 728 wrap->deleteMails(mbox,mailsToRemove);
707 mailsToSend.setAutoDelete(true); 729 mailsToSend.setAutoDelete(true);
708 delete wrap; 730 delete wrap;
709 return returnValue; 731 return returnValue;
710} 732}
diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h
index 0535983..05becf2 100644
--- a/noncore/net/mail/smtpwrapper.h
+++ b/noncore/net/mail/smtpwrapper.h
@@ -22,24 +22,28 @@ class progressMailSend;
22 22
23class SMTPwrapper : public QObject 23class SMTPwrapper : public QObject
24{ 24{
25 Q_OBJECT 25 Q_OBJECT
26 26
27public: 27public:
28 SMTPwrapper( Settings *s ); 28 SMTPwrapper( Settings *s );
29 virtual ~SMTPwrapper(){} 29 virtual ~SMTPwrapper(){}
30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false ); 30 void sendMail(const Mail& mail,SMTPaccount*smtp,bool later=false );
31 bool flushOutbox(SMTPaccount*smtp); 31 bool flushOutbox(SMTPaccount*smtp);
32 32
33 static progressMailSend*sendProgress; 33 static progressMailSend*sendProgress;
34
35signals:
36 void queuedMails( int );
37
34protected: 38protected:
35 mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); 39 mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
36 mailimf_fields *createImfFields(const Mail &mail ); 40 mailimf_fields *createImfFields(const Mail &mail );
37 mailmime *createMimeMail(const Mail&mail ); 41 mailmime *createMimeMail(const Mail&mail );
38 42
39 mailimf_address_list *parseAddresses(const QString&addr ); 43 mailimf_address_list *parseAddresses(const QString&addr );
40 void addFileParts( mailmime *message,const QList<Attachment>&files ); 44 void addFileParts( mailmime *message,const QList<Attachment>&files );
41 mailmime *buildTxtPart(const QString&str ); 45 mailmime *buildTxtPart(const QString&str );
42 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); 46 mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
43 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); 47 void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp );
44 clist *createRcptList( mailimf_fields *fields ); 48 clist *createRcptList( mailimf_fields *fields );
45 49
@@ -47,15 +51,21 @@ protected:
47 static QString mailsmtpError( int err ); 51 static QString mailsmtpError( int err );
48 static void progress( size_t current, size_t maximum ); 52 static void progress( size_t current, size_t maximum );
49 static void addRcpts( clist *list, mailimf_address_list *addr_list ); 53 static void addRcpts( clist *list, mailimf_address_list *addr_list );
50 static char *getFrom( mailmime *mail ); 54 static char *getFrom( mailmime *mail );
51 static char *getFrom( mailimf_field *ffrom); 55 static char *getFrom( mailimf_field *ffrom);
52 static mailimf_field *getField( mailimf_fields *fields, int type ); 56 static mailimf_field *getField( mailimf_fields *fields, int type );
53 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 );
54 58
55 void storeMail(mailmime*mail, const QString&box); 59 void storeMail(mailmime*mail, const QString&box);
56 Settings *settings; 60 Settings *settings;
57 61
58 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); 62 int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which);
63
64 int m_queuedMail;
65
66protected slots:
67 void emitQCop( int queued );
68
59}; 69};
60 70
61#endif 71#endif