author | alwin <alwin> | 2003-12-24 01:29:43 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-24 01:29:43 (UTC) |
commit | 242f7a04e3e4963a5606ac603d54a4f115de4a04 (patch) (side-by-side diff) | |
tree | dd8578fbc812791dd7e5026a28710a8313cf5cf8 | |
parent | 7c720aabcad9b325dbf9910493e3c9fa1d63805e (diff) | |
download | opie-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.
-rw-r--r-- | noncore/net/mail/libmailwrapper/sendmailprogress.cpp | 48 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/sendmailprogress.h | 19 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/sendmailprogressui.ui | 110 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 16 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 4 | ||||
-rw-r--r-- | noncore/net/mail/mail.pro | 9 | ||||
-rw-r--r-- | noncore/net/mail/sendmailprogress.cpp | 48 | ||||
-rw-r--r-- | noncore/net/mail/sendmailprogress.h | 19 | ||||
-rw-r--r-- | noncore/net/mail/sendmailprogressui.ui | 110 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 16 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 4 |
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 @@ +#include "sendmailprogress.h" +#include <qprogressbar.h> +#include <qlabel.h> +#include <qstring.h> + +progressMailSend::progressMailSend(QWidget*parent, const char * name) + :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) +{ +} + +progressMailSend::~progressMailSend() +{ +} + +void progressMailSend::setMaxMails(unsigned int aMaxMails) +{ + m_max_mail = aMaxMails; + allMailProgressBar->setTotalSteps(aMaxMails); + setMails(); +} + +void progressMailSend::setCurrentMails(unsigned int aCurrent) +{ + m_current_mail = aCurrent; + allMailProgressBar->setProgress(aCurrent); + setMails(); +} + +void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) +{ + m_current_single = aCurrent; + m_max_single = aMax; + setSingle(); +} + +void progressMailSend::setSingle() +{ + QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); + singleMailLabel->setText(text); + singleMailProgressBar->setTotalSteps(m_max_single); + singleMailProgressBar->setProgress(m_current_single); +} + +void progressMailSend::setMails() +{ + QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); + allMailLabel->setText(text); +} 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 @@ +#include "sendmailprogressui.h" + +class progressMailSend:public progressMailSendUI +{ + Q_OBJECT +public: + progressMailSend(QWidget*parent = 0, const char * name = 0); + ~progressMailSend(); + + void setMaxMails(unsigned int aMaxMails); + void setCurrentMails(unsigned int aCurrent); + + void setSingleMail(unsigned int aCurrent,unsigned int aMax); + +protected: + unsigned m_current_mail,m_current_single,m_max_mail,m_max_single; + void setSingle(); + void setMails(); +}; 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 @@ +<!DOCTYPE UI><UI> +<class>progressMailSendUI</class> +<widget> + <class>QDialog</class> + <property stdset="1"> + <name>name</name> + <cstring>progressMailSendUI</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>316</width> + <height>266</height> + </rect> + </property> + <property stdset="1"> + <name>caption</name> + <string>Sending mail</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>singleMailLabel</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Progress of mail</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + <widget> + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>singleMailProgressBar</cstring> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>allMailLabel</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Sending mail</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + <widget> + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>allMailProgressBar</cstring> + </property> + </widget> + <spacer> + <property> + <name>name</name> + <cstring>Spacer6</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> +</widget> +</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,41 +1,44 @@ #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <qdir.h> #include <qt.h> #include <libetpan/libetpan.h> #include "smtpwrapper.h" #include "mailwrapper.h" #include "mboxwrapper.h" #include "logindialog.h" #include "mailtypes.h" #include "defines.h" +#include "sendmailprogress.h" + +progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() { settings = s; } QString SMTPwrapper::mailsmtpError( int errnum ) { switch ( errnum ) { case MAILSMTP_NO_ERROR: return tr( "No error" ); case MAILSMTP_ERROR_UNEXPECTED_CODE: return tr( "Unexpected error code" ); case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: return tr( "Service not available" ); case MAILSMTP_ERROR_STREAM: return tr( "Stream error" ); case MAILSMTP_ERROR_HOSTNAME: return tr( "gethostname() failed" ); case MAILSMTP_ERROR_NOT_IMPLEMENTED: return tr( "Not implemented" ); case MAILSMTP_ERROR_ACTION_NOT_TAKEN: return tr( "Error, action not taken" ); @@ -499,49 +502,52 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) fclose( f ); } void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) { QFile msg_cache(file); QString msg = ""; msg_cache.open(IO_ReadOnly); char*message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; *data = (char*)malloc(msg.length()+1*sizeof(char)); memset(*data,0,msg.length()+1); memcpy(*data,msg.ascii(),msg.length()); *size=msg.length(); } void SMTPwrapper::progress( size_t current, size_t maximum ) { -// qDebug( "Current: %i of %i", current, maximum ); + if (SMTPwrapper::sendProgress) { + SMTPwrapper::sendProgress->setSingleMail(current, maximum ); + qDebug("%u of %u",current,maximum); + } } void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) { if (!mail) return; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); wrap->storeMessage(mail,length,box); delete wrap; } void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { clist *rcpts = 0; char *from, *data; size_t size; if ( smtp == NULL ) { return; } from = data = 0; QString file = getTmpFile(); writeToFile( file, mail ); @@ -624,76 +630,84 @@ free_con_session: free_mem_session: mailsmtp_free( session ); free_mem: if (rcpts) smtp_address_list_free( rcpts ); if (data) free( data ); if (server) free( server ); if (from) free( from ); if ( smtp->getLogin() ) { free( user ); free( pass ); } return result; } void SMTPwrapper::sendMail(const Mail&mail,bool later ) { mailmime * mimeMail; SMTPaccount *smtp = getAccount(mail.getName()); mimeMail = createMimeMail(mail ); if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { + sendProgress = new progressMailSend(); + sendProgress->showMaximized(); + sendProgress->show(); + qApp->processEvents(10); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); + sendProgress->hide(); + delete sendProgress; + sendProgress = 0; } } int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) { char*data = 0; size_t length = 0; size_t curTok = 0; mailimf_fields *fields = 0; mailimf_field*ffrom = 0; clist *rcpts = 0; char*from = 0; wrap->fetchRawBody(*which,&data,&length); if (!data) return 0; int err = mailimf_fields_parse( data, length, &curTok, &fields ); if (err != MAILIMF_NO_ERROR) { free(data); delete wrap; return 0; } rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); + qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { return smtpSend(from,rcpts,data,strlen(data),smtp ); } return 0; } /* this is a special fun */ void SMTPwrapper::flushOutbox(SMTPaccount*smtp) { if (!smtp) return; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); if (!wrap) { qDebug("memory error"); return; } QList<RecMail> mailsToSend; QList<RecMail> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; return; 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 @@ #ifndef SMTPwrapper_H #define SMTPwrapper_H #include <qpe/applnk.h> #include <qbitarray.h> #include <qdatetime.h> #include <libetpan/clist.h> #include "settings.h" class Mail; class MBOXwrapper; class RecMail; class Attachment; struct mailimf_fields; struct mailimf_field; struct mailimf_mailbox; struct mailmime; struct mailimf_address_list; +class progressMailSend; class SMTPwrapper : public QObject { Q_OBJECT public: SMTPwrapper( Settings *s ); virtual ~SMTPwrapper(){} void sendMail(const Mail& mail,bool later=false ); void flushOutbox(SMTPaccount*smtp); + static progressMailSend*sendProgress; protected: mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); mailimf_fields *createImfFields(const Mail &mail ); mailmime *createMimeMail(const Mail&mail ); mailimf_address_list *parseAddresses(const QString&addr ); void addFileParts( mailmime *message,const QList<Attachment>&files ); mailmime *buildTxtPart(const QString&str ); mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); clist *createRcptList( mailimf_fields *fields ); SMTPaccount *getAccount(const QString&from ); void writeToFile(const QString&file, mailmime *mail ); void readFromFile(const QString&file, char **data, size_t *size ); static void storeMail(char*mail, size_t length, const QString&box); static QString mailsmtpError( int err ); static QString getTmpFile(); static void progress( size_t current, size_t maximum ); static void addRcpts( clist *list, mailimf_address_list *addr_list ); static char *getFrom( mailmime *mail ); static char *getFrom( mailimf_field *ffrom); static mailimf_field *getField( mailimf_fields *fields, int type ); - static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); + int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); void storeMail(mailmime*mail, const QString&box); Settings *settings; int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); }; #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 @@ CONFIG += qt warn_on debug quick-app HEADERS = defines.h \ logindialog.h \ settings.h \ editaccounts.h \ mailwrapper.h \ composemail.h \ accountview.h \ mainwindow.h \ viewmail.h \ viewmailbase.h \ opiemail.h \ imapwrapper.h \ mailtypes.h \ mailistviewitem.h \ pop3wrapper.h \ abstractmail.h \ settingsdialog.h \ statuswidget.h \ smtpwrapper.h \ genericwrapper.h \ - mboxwrapper.h + mboxwrapper.h \ + sendmailprogress.h SOURCES = main.cpp \ opiemail.cpp \ mainwindow.cpp \ accountview.cpp \ composemail.cpp \ mailwrapper.cpp \ imapwrapper.cpp \ addresspicker.cpp \ editaccounts.cpp \ logindialog.cpp \ viewmail.cpp \ viewmailbase.cpp \ settings.cpp \ mailtypes.cpp \ pop3wrapper.cpp \ abstractmail.cpp \ settingsdialog.cpp \ statuswidget.cpp \ smtpwrapper.cpp \ genericwrapper.cpp \ - mboxwrapper.cpp + mboxwrapper.cpp \ + sendmailprogress.cpp INTERFACES = editaccountsui.ui \ selectmailtypeui.ui \ imapconfigui.ui \ pop3configui.ui \ nntpconfigui.ui \ smtpconfigui.ui \ addresspickerui.ui \ logindialogui.ui \ composemailui.ui \ settingsdialogui.ui \ - statuswidgetui.ui + statuswidgetui.ui \ + sendmailprogressui.ui INCLUDEPATH += $(OPIEDIR)/include CONFTEST = $$system( echo $CONFIG_TARGET_MACOSX ) contains( CONFTEST, y ){ LIBS += -lqpe -letpan -lssl -lcrypto -lopie -liconv }else{ LIBS += -lqpe -letpan -lssl -lcrypto -lopie } TARGET = opiemail include ( $(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 @@ +#include "sendmailprogress.h" +#include <qprogressbar.h> +#include <qlabel.h> +#include <qstring.h> + +progressMailSend::progressMailSend(QWidget*parent, const char * name) + :progressMailSendUI(parent,name,false),m_current_mail(0),m_current_single(0),m_max_mail(0),m_max_single(0) +{ +} + +progressMailSend::~progressMailSend() +{ +} + +void progressMailSend::setMaxMails(unsigned int aMaxMails) +{ + m_max_mail = aMaxMails; + allMailProgressBar->setTotalSteps(aMaxMails); + setMails(); +} + +void progressMailSend::setCurrentMails(unsigned int aCurrent) +{ + m_current_mail = aCurrent; + allMailProgressBar->setProgress(aCurrent); + setMails(); +} + +void progressMailSend::setSingleMail(unsigned int aCurrent,unsigned int aMax) +{ + m_current_single = aCurrent; + m_max_single = aMax; + setSingle(); +} + +void progressMailSend::setSingle() +{ + QString text = QString(tr("%1 of %2 bytes send")).arg(m_current_single).arg(m_max_single); + singleMailLabel->setText(text); + singleMailProgressBar->setTotalSteps(m_max_single); + singleMailProgressBar->setProgress(m_current_single); +} + +void progressMailSend::setMails() +{ + QString text = QString(tr("Sending mail %1 of %2")).arg(m_current_single+1).arg(m_max_single); + allMailLabel->setText(text); +} 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 @@ +#include "sendmailprogressui.h" + +class progressMailSend:public progressMailSendUI +{ + Q_OBJECT +public: + progressMailSend(QWidget*parent = 0, const char * name = 0); + ~progressMailSend(); + + void setMaxMails(unsigned int aMaxMails); + void setCurrentMails(unsigned int aCurrent); + + void setSingleMail(unsigned int aCurrent,unsigned int aMax); + +protected: + unsigned m_current_mail,m_current_single,m_max_mail,m_max_single; + void setSingle(); + void setMails(); +}; 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 @@ +<!DOCTYPE UI><UI> +<class>progressMailSendUI</class> +<widget> + <class>QDialog</class> + <property stdset="1"> + <name>name</name> + <cstring>progressMailSendUI</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>316</width> + <height>266</height> + </rect> + </property> + <property stdset="1"> + <name>caption</name> + <string>Sending mail</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>singleMailLabel</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Progress of mail</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + <widget> + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>singleMailProgressBar</cstring> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>allMailLabel</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Sending mail</string> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + <widget> + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>allMailProgressBar</cstring> + </property> + </widget> + <spacer> + <property> + <name>name</name> + <cstring>Spacer6</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </vbox> +</widget> +</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,41 +1,44 @@ #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <qdir.h> #include <qt.h> #include <libetpan/libetpan.h> #include "smtpwrapper.h" #include "mailwrapper.h" #include "mboxwrapper.h" #include "logindialog.h" #include "mailtypes.h" #include "defines.h" +#include "sendmailprogress.h" + +progressMailSend*SMTPwrapper::sendProgress = 0; SMTPwrapper::SMTPwrapper( Settings *s ) : QObject() { settings = s; } QString SMTPwrapper::mailsmtpError( int errnum ) { switch ( errnum ) { case MAILSMTP_NO_ERROR: return tr( "No error" ); case MAILSMTP_ERROR_UNEXPECTED_CODE: return tr( "Unexpected error code" ); case MAILSMTP_ERROR_SERVICE_NOT_AVAILABLE: return tr( "Service not available" ); case MAILSMTP_ERROR_STREAM: return tr( "Stream error" ); case MAILSMTP_ERROR_HOSTNAME: return tr( "gethostname() failed" ); case MAILSMTP_ERROR_NOT_IMPLEMENTED: return tr( "Not implemented" ); case MAILSMTP_ERROR_ACTION_NOT_TAKEN: return tr( "Error, action not taken" ); @@ -499,49 +502,52 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail ) fclose( f ); } void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size ) { QFile msg_cache(file); QString msg = ""; msg_cache.open(IO_ReadOnly); char*message = new char[4096]; memset(message,0,4096); while (msg_cache.readBlock(message,4095)>0) { msg+=message; memset(message,0,4096); } delete message; *data = (char*)malloc(msg.length()+1*sizeof(char)); memset(*data,0,msg.length()+1); memcpy(*data,msg.ascii(),msg.length()); *size=msg.length(); } void SMTPwrapper::progress( size_t current, size_t maximum ) { -// qDebug( "Current: %i of %i", current, maximum ); + if (SMTPwrapper::sendProgress) { + SMTPwrapper::sendProgress->setSingleMail(current, maximum ); + qDebug("%u of %u",current,maximum); + } } void SMTPwrapper::storeMail(char*mail, size_t length, const QString&box) { if (!mail) return; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); wrap->storeMessage(mail,length,box); delete wrap; } void SMTPwrapper::smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ) { clist *rcpts = 0; char *from, *data; size_t size; if ( smtp == NULL ) { return; } from = data = 0; QString file = getTmpFile(); writeToFile( file, mail ); @@ -624,76 +630,84 @@ free_con_session: free_mem_session: mailsmtp_free( session ); free_mem: if (rcpts) smtp_address_list_free( rcpts ); if (data) free( data ); if (server) free( server ); if (from) free( from ); if ( smtp->getLogin() ) { free( user ); free( pass ); } return result; } void SMTPwrapper::sendMail(const Mail&mail,bool later ) { mailmime * mimeMail; SMTPaccount *smtp = getAccount(mail.getName()); mimeMail = createMimeMail(mail ); if ( mimeMail == NULL ) { qDebug( "sendMail: error creating mime mail" ); } else { + sendProgress = new progressMailSend(); + sendProgress->showMaximized(); + sendProgress->show(); + qApp->processEvents(10); smtpSend( mimeMail,later,smtp); mailmime_free( mimeMail ); qDebug("Clean up done"); + sendProgress->hide(); + delete sendProgress; + sendProgress = 0; } } int SMTPwrapper::sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which) { char*data = 0; size_t length = 0; size_t curTok = 0; mailimf_fields *fields = 0; mailimf_field*ffrom = 0; clist *rcpts = 0; char*from = 0; wrap->fetchRawBody(*which,&data,&length); if (!data) return 0; int err = mailimf_fields_parse( data, length, &curTok, &fields ); if (err != MAILIMF_NO_ERROR) { free(data); delete wrap; return 0; } rcpts = createRcptList( fields ); ffrom = getField(fields, MAILIMF_FIELD_FROM ); from = getFrom(ffrom); + qDebug("Size: %i vs. %i",length,strlen(data)); if (rcpts && from) { return smtpSend(from,rcpts,data,strlen(data),smtp ); } return 0; } /* this is a special fun */ void SMTPwrapper::flushOutbox(SMTPaccount*smtp) { if (!smtp) return; QString localfolders = (QString) getenv( "HOME" ) + QString("/Applications/opiemail/localmail/"); MBOXwrapper*wrap = new MBOXwrapper(localfolders); if (!wrap) { qDebug("memory error"); return; } QList<RecMail> mailsToSend; QList<RecMail> mailsToRemove; QString mbox("Outgoing"); wrap->listMessages(mbox,mailsToSend); if (mailsToSend.count()==0) { delete wrap; return; 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 @@ #ifndef SMTPwrapper_H #define SMTPwrapper_H #include <qpe/applnk.h> #include <qbitarray.h> #include <qdatetime.h> #include <libetpan/clist.h> #include "settings.h" class Mail; class MBOXwrapper; class RecMail; class Attachment; struct mailimf_fields; struct mailimf_field; struct mailimf_mailbox; struct mailmime; struct mailimf_address_list; +class progressMailSend; class SMTPwrapper : public QObject { Q_OBJECT public: SMTPwrapper( Settings *s ); virtual ~SMTPwrapper(){} void sendMail(const Mail& mail,bool later=false ); void flushOutbox(SMTPaccount*smtp); + static progressMailSend*sendProgress; protected: mailimf_mailbox *newMailbox(const QString&name,const QString&mail ); mailimf_fields *createImfFields(const Mail &mail ); mailmime *createMimeMail(const Mail&mail ); mailimf_address_list *parseAddresses(const QString&addr ); void addFileParts( mailmime *message,const QList<Attachment>&files ); mailmime *buildTxtPart(const QString&str ); mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content); void smtpSend( mailmime *mail,bool later, SMTPaccount *smtp ); clist *createRcptList( mailimf_fields *fields ); SMTPaccount *getAccount(const QString&from ); void writeToFile(const QString&file, mailmime *mail ); void readFromFile(const QString&file, char **data, size_t *size ); static void storeMail(char*mail, size_t length, const QString&box); static QString mailsmtpError( int err ); static QString getTmpFile(); static void progress( size_t current, size_t maximum ); static void addRcpts( clist *list, mailimf_address_list *addr_list ); static char *getFrom( mailmime *mail ); static char *getFrom( mailimf_field *ffrom); static mailimf_field *getField( mailimf_fields *fields, int type ); - static int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); + int smtpSend(char*from,clist*rcpts,char*data,size_t size, SMTPaccount *smtp ); void storeMail(mailmime*mail, const QString&box); Settings *settings; int sendQueuedMail(MBOXwrapper*wrap,SMTPaccount*smtp,RecMail*which); }; #endif |