author | alwin <alwin> | 2003-12-22 02:37:35 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-22 02:37:35 (UTC) |
commit | 9e7aafdb7c76d29fee742d53131a73dd60aded2b (patch) (side-by-side diff) | |
tree | e98f9fe1233455f458738acbfd29bac78dd03342 /noncore | |
parent | 7c016e1a75970cb7c28d70398ad20c708cdb452b (diff) | |
download | opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.zip opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.gz opie-9e7aafdb7c76d29fee742d53131a73dd60aded2b.tar.bz2 |
- storing mails send in outgoing (if queued) or sent (if sent) folder
TODO: flush queue, cleanup SMTP code, select smtp-account if more than
one when flush the outgoing queue
-rw-r--r-- | noncore/net/mail/composemail.cpp | 3 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/mboxwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.cpp | 59 | ||||
-rw-r--r-- | noncore/net/mail/libmailwrapper/smtpwrapper.h | 6 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.cpp | 26 | ||||
-rw-r--r-- | noncore/net/mail/mboxwrapper.h | 2 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.cpp | 59 | ||||
-rw-r--r-- | noncore/net/mail/smtpwrapper.h | 6 |
9 files changed, 160 insertions, 29 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp index f680f5c..f532815 100644 --- a/noncore/net/mail/composemail.cpp +++ b/noncore/net/mail/composemail.cpp @@ -170,2 +170,3 @@ void ComposeMail::accept() SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); + mail->setMail( smtp->getMail() ); @@ -197,3 +198,3 @@ void ComposeMail::accept() SMTPwrapper wrapper( settings ); - wrapper.sendMail( *mail ); + wrapper.sendMail( *mail,checkBoxLater->isChecked() ); diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp index 7581715..8117cef 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.cpp @@ -3,4 +3,4 @@ #include "mailwrapper.h" -#include "libetpan/libetpan.h" -#include "libetpan/mailstorage.h" +#include <libetpan/libetpan.h> +#include <libetpan/mailstorage.h> #include <qdir.h> @@ -69,3 +69,2 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) if (r == MAIL_ERROR_NOT_IMPLEMENTED) { - qDebug("flag fetching not implemented"); mFlags.setBit(FLAG_SEEN); @@ -199 +198,22 @@ void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) } + +void MBOXwrapper::createFolder(const QString&) +{ +} + +void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) +{ + QString p = MBOXPath+"/"; + p+=folder; + mailmbox_folder*f = 0; + int r = mailmbox_init(p.latin1(),0,1,0,&f); + if (r != MAIL_NO_ERROR) { + qDebug("Error init folder"); + return; + } + r = mailmbox_append_message(f,msg,length); + if (r != MAIL_NO_ERROR) { + qDebug("Error writing message folder"); + } + mailmbox_done(f); +} diff --git a/noncore/net/mail/libmailwrapper/mboxwrapper.h b/noncore/net/mail/libmailwrapper/mboxwrapper.h index 779dbc8..1bbaf79 100644 --- a/noncore/net/mail/libmailwrapper/mboxwrapper.h +++ b/noncore/net/mail/libmailwrapper/mboxwrapper.h @@ -21,2 +21,4 @@ public: virtual void answeredMail(const RecMail&mail); + virtual void createFolder(const QString&aFolder); + virtual void storeMessage(const char*msg,size_t length, const QString&folder); diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp index 162b1b9..a6a46ba 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp @@ -8,3 +8,4 @@ -#include <libetpan/mailmime.h> +#include <libetpan/libetpan.h> +#if 0 #include <libetpan/mailimf.h> @@ -13,2 +14,3 @@ #include <libetpan/maildriver.h> +#endif @@ -16,2 +18,3 @@ #include "mailwrapper.h" +#include "mboxwrapper.h" #include "logindialog.h" @@ -467,2 +470,19 @@ 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(); + +#if 0 char *buf; @@ -497,2 +517,3 @@ err_close: close( fd ); +#endif } @@ -504,3 +525,12 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) -void SMTPwrapper::smtpSend( mailmime *mail ) +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 ) { @@ -521,5 +551,2 @@ void SMTPwrapper::smtpSend( mailmime *mail ) } - server = strdup( smtp->getServer().latin1() ); - ssl = smtp->getSSL(); - port = smtp->getPort().toUInt(); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); @@ -528,2 +555,3 @@ void SMTPwrapper::smtpSend( mailmime *mail ) writeToFile( file, mail ); + readFromFile( file, &data, &size ); @@ -532,2 +560,14 @@ void SMTPwrapper::smtpSend( mailmime *mail ) + storeMail(data,size,(later?"Outgoing":"Sent")); + + if (later) { + smtp_address_list_free( rcpts ); + if (data) free( data ); + if (from) free(from); + return; + } + server = strdup( smtp->getServer().latin1() ); + ssl = smtp->getSSL(); + port = smtp->getPort().toUInt(); + session = mailsmtp_new( 20, &progress ); @@ -583,4 +623,5 @@ free_mem: smtp_address_list_free( rcpts ); - free( data ); - free( server ); + if (data) free( data ); + if (from) free(from); + if (server) free( server ); if ( smtp->getLogin() ) { @@ -592,3 +633,3 @@ free_mem: -void SMTPwrapper::sendMail(const Mail&mail ) +void SMTPwrapper::sendMail(const Mail&mail,bool later ) { @@ -600,3 +641,3 @@ void SMTPwrapper::sendMail(const Mail&mail ) } else { - smtpSend( mimeMail ); + smtpSend( mimeMail,later ); mailmime_free( mimeMail ); diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h index 8fdb07d..41e9a8c 100644 --- a/noncore/net/mail/libmailwrapper/smtpwrapper.h +++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h @@ -26,3 +26,3 @@ public: virtual ~SMTPwrapper(){} - void sendMail(const Mail& mail ); + void sendMail(const Mail& mail,bool later=false ); @@ -37,3 +37,3 @@ protected: mailmime *buildFilePart(const QString&filename,const QString&mimetype ); - void smtpSend( mailmime *mail ); + void smtpSend( mailmime *mail,bool later ); mailimf_field *getField( mailimf_fields *fields, int type ); @@ -44,2 +44,3 @@ protected: void readFromFile(const QString&file, char **data, size_t *size ); + void storeMail(char*mail, size_t length, const QString&box); @@ -49,2 +50,3 @@ protected: static void addRcpts( clist *list, mailimf_address_list *addr_list ); + void storeMail(mailmime*mail, const QString&box); Settings *settings; diff --git a/noncore/net/mail/mboxwrapper.cpp b/noncore/net/mail/mboxwrapper.cpp index 7581715..8117cef 100644 --- a/noncore/net/mail/mboxwrapper.cpp +++ b/noncore/net/mail/mboxwrapper.cpp @@ -3,4 +3,4 @@ #include "mailwrapper.h" -#include "libetpan/libetpan.h" -#include "libetpan/mailstorage.h" +#include <libetpan/libetpan.h> +#include <libetpan/mailstorage.h> #include <qdir.h> @@ -69,3 +69,2 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target ) if (r == MAIL_ERROR_NOT_IMPLEMENTED) { - qDebug("flag fetching not implemented"); mFlags.setBit(FLAG_SEEN); @@ -199 +198,22 @@ void MBOXwrapper::mbox_progress( size_t current, size_t maximum ) } + +void MBOXwrapper::createFolder(const QString&) +{ +} + +void MBOXwrapper::storeMessage(const char*msg,size_t length, const QString&folder) +{ + QString p = MBOXPath+"/"; + p+=folder; + mailmbox_folder*f = 0; + int r = mailmbox_init(p.latin1(),0,1,0,&f); + if (r != MAIL_NO_ERROR) { + qDebug("Error init folder"); + return; + } + r = mailmbox_append_message(f,msg,length); + if (r != MAIL_NO_ERROR) { + qDebug("Error writing message folder"); + } + mailmbox_done(f); +} diff --git a/noncore/net/mail/mboxwrapper.h b/noncore/net/mail/mboxwrapper.h index 779dbc8..1bbaf79 100644 --- a/noncore/net/mail/mboxwrapper.h +++ b/noncore/net/mail/mboxwrapper.h @@ -21,2 +21,4 @@ public: virtual void answeredMail(const RecMail&mail); + virtual void createFolder(const QString&aFolder); + virtual void storeMessage(const char*msg,size_t length, const QString&folder); diff --git a/noncore/net/mail/smtpwrapper.cpp b/noncore/net/mail/smtpwrapper.cpp index 162b1b9..a6a46ba 100644 --- a/noncore/net/mail/smtpwrapper.cpp +++ b/noncore/net/mail/smtpwrapper.cpp @@ -8,3 +8,4 @@ -#include <libetpan/mailmime.h> +#include <libetpan/libetpan.h> +#if 0 #include <libetpan/mailimf.h> @@ -13,2 +14,3 @@ #include <libetpan/maildriver.h> +#endif @@ -16,2 +18,3 @@ #include "mailwrapper.h" +#include "mboxwrapper.h" #include "logindialog.h" @@ -467,2 +470,19 @@ 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(); + +#if 0 char *buf; @@ -497,2 +517,3 @@ err_close: close( fd ); +#endif } @@ -504,3 +525,12 @@ void SMTPwrapper::progress( size_t current, size_t maximum ) -void SMTPwrapper::smtpSend( mailmime *mail ) +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 ) { @@ -521,5 +551,2 @@ void SMTPwrapper::smtpSend( mailmime *mail ) } - server = strdup( smtp->getServer().latin1() ); - ssl = smtp->getSSL(); - port = smtp->getPort().toUInt(); rcpts = createRcptList( mail->mm_data.mm_message.mm_fields ); @@ -528,2 +555,3 @@ void SMTPwrapper::smtpSend( mailmime *mail ) writeToFile( file, mail ); + readFromFile( file, &data, &size ); @@ -532,2 +560,14 @@ void SMTPwrapper::smtpSend( mailmime *mail ) + storeMail(data,size,(later?"Outgoing":"Sent")); + + if (later) { + smtp_address_list_free( rcpts ); + if (data) free( data ); + if (from) free(from); + return; + } + server = strdup( smtp->getServer().latin1() ); + ssl = smtp->getSSL(); + port = smtp->getPort().toUInt(); + session = mailsmtp_new( 20, &progress ); @@ -583,4 +623,5 @@ free_mem: smtp_address_list_free( rcpts ); - free( data ); - free( server ); + if (data) free( data ); + if (from) free(from); + if (server) free( server ); if ( smtp->getLogin() ) { @@ -592,3 +633,3 @@ free_mem: -void SMTPwrapper::sendMail(const Mail&mail ) +void SMTPwrapper::sendMail(const Mail&mail,bool later ) { @@ -600,3 +641,3 @@ void SMTPwrapper::sendMail(const Mail&mail ) } else { - smtpSend( mimeMail ); + smtpSend( mimeMail,later ); mailmime_free( mimeMail ); diff --git a/noncore/net/mail/smtpwrapper.h b/noncore/net/mail/smtpwrapper.h index 8fdb07d..41e9a8c 100644 --- a/noncore/net/mail/smtpwrapper.h +++ b/noncore/net/mail/smtpwrapper.h @@ -26,3 +26,3 @@ public: virtual ~SMTPwrapper(){} - void sendMail(const Mail& mail ); + void sendMail(const Mail& mail,bool later=false ); @@ -37,3 +37,3 @@ protected: mailmime *buildFilePart(const QString&filename,const QString&mimetype ); - void smtpSend( mailmime *mail ); + void smtpSend( mailmime *mail,bool later ); mailimf_field *getField( mailimf_fields *fields, int type ); @@ -44,2 +44,3 @@ protected: void readFromFile(const QString&file, char **data, size_t *size ); + void storeMail(char*mail, size_t length, const QString&box); @@ -49,2 +50,3 @@ protected: static void addRcpts( clist *list, mailimf_address_list *addr_list ); + void storeMail(mailmime*mail, const QString&box); Settings *settings; |