summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/composemail.cpp3
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.cpp26
-rw-r--r--noncore/net/mail/libmailwrapper/mboxwrapper.h2
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp61
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h6
-rw-r--r--noncore/net/mail/mboxwrapper.cpp26
-rw-r--r--noncore/net/mail/mboxwrapper.h2
-rw-r--r--noncore/net/mail/smtpwrapper.cpp61
-rw-r--r--noncore/net/mail/smtpwrapper.h6
9 files changed, 162 insertions, 31 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
@@ -167,8 +167,9 @@ void ComposeMail::accept()
qDebug( "Sending Mail with " +
smtpAccounts.at( fromBox->currentItem() )->getAccountName() );
Mail *mail = new Mail();
SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() );
+
mail->setMail( smtp->getMail() );
mail->setName( smtp->getName() );
if ( !toLine->text().isEmpty() ) {
@@ -194,9 +195,9 @@ void ComposeMail::accept()
it = (AttachViewItem *) it->itemBelow();
}
SMTPwrapper wrapper( settings );
- wrapper.sendMail( *mail );
+ wrapper.sendMail( *mail,checkBoxLater->isChecked() );
QDialog::accept();
}
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
@@ -1,9 +1,9 @@
#include "mboxwrapper.h"
#include "mailtypes.h"
#include "mailwrapper.h"
-#include "libetpan/libetpan.h"
-#include "libetpan/mailstorage.h"
+#include <libetpan/libetpan.h>
+#include <libetpan/mailstorage.h>
#include <qdir.h>
MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
: Genericwrapper(),MBOXPath(mbox_dir)
@@ -66,9 +66,8 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
mail->setWrapper(this);
mail_flags * flag_result = 0;
r = mailmessage_get_flags(msg,&flag_result);
if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
- qDebug("flag fetching not implemented");
mFlags.setBit(FLAG_SEEN);
}
mailimf_single_fields single_fields;
mailimf_single_fields_init(&single_fields, msg->msg_fields);
@@ -196,4 +195,25 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail )
void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
{
qDebug("MBOX %i von %i",current,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
@@ -18,8 +18,10 @@ public:
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual void createFolder(const QString&aFolder);
+ virtual void storeMessage(const char*msg,size_t length, const QString&folder);
virtual RecBody fetchBody( const RecMail &mail );
static void mbox_progress( size_t current, size_t maximum );
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
@@ -5,16 +5,19 @@
#include <fcntl.h>
#include <string.h>
#include <qdir.h>
-#include <libetpan/mailmime.h>
+#include <libetpan/libetpan.h>
+#if 0
#include <libetpan/mailimf.h>
#include <libetpan/mailsmtp.h>
#include <libetpan/mailstorage.h>
#include <libetpan/maildriver.h>
+#endif
#include "smtpwrapper.h"
#include "mailwrapper.h"
+#include "mboxwrapper.h"
#include "logindialog.h"
#include "defines.h"
SMTPwrapper::SMTPwrapper( Settings *s )
@@ -464,8 +467,25 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
}
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;
struct stat st;
int fd, count = 0, total = 0;
@@ -494,16 +514,26 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
err_free:
free( buf );
err_close:
close( fd );
+#endif
}
void SMTPwrapper::progress( size_t current, size_t maximum )
{
qDebug( "Current: %i of %i", current, 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 )
{
mailsmtp *session;
clist *rcpts;
char *from, *data, *server, *user = NULL, *pass = NULL;
@@ -518,19 +548,29 @@ void SMTPwrapper::smtpSend( mailmime *mail )
if ( smtp == NULL ) {
free(from);
return;
}
- server = strdup( smtp->getServer().latin1() );
- ssl = smtp->getSSL();
- port = smtp->getPort().toUInt();
rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
QString file = getTmpFile();
writeToFile( file, mail );
+
readFromFile( file, &data, &size );
QFile f( file );
f.remove();
+
+ 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 );
if ( session == NULL ) goto free_mem;
qDebug( "Servername %s at port %i", server, port );
@@ -580,25 +620,26 @@ free_con_session:
free_mem_session:
mailsmtp_free( session );
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() ) {
free( user );
free( pass );
}
free( from );
}
-void SMTPwrapper::sendMail(const Mail&mail )
+void SMTPwrapper::sendMail(const Mail&mail,bool later )
{
- mailmime *mimeMail;
+ mailmime * mimeMail;
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "sendMail: error creating mime 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
@@ -23,9 +23,9 @@ class SMTPwrapper : public QObject
public:
SMTPwrapper( Settings *s );
virtual ~SMTPwrapper(){}
- void sendMail(const Mail& mail );
+ void sendMail(const Mail& mail,bool later=false );
protected:
mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
mailimf_fields *createImfFields(const Mail &mail );
@@ -34,20 +34,22 @@ protected:
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 );
- void smtpSend( mailmime *mail );
+ void smtpSend( mailmime *mail,bool later );
mailimf_field *getField( mailimf_fields *fields, int type );
clist *createRcptList( mailimf_fields *fields );
char *getFrom( mailmime *mail );
SMTPaccount *getAccount(const QString&from );
void writeToFile(const QString&file, mailmime *mail );
void readFromFile(const QString&file, char **data, size_t *size );
+ 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 );
+ void storeMail(mailmime*mail, const QString&box);
Settings *settings;
};
#endif
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
@@ -1,9 +1,9 @@
#include "mboxwrapper.h"
#include "mailtypes.h"
#include "mailwrapper.h"
-#include "libetpan/libetpan.h"
-#include "libetpan/mailstorage.h"
+#include <libetpan/libetpan.h>
+#include <libetpan/mailstorage.h>
#include <qdir.h>
MBOXwrapper::MBOXwrapper(const QString & mbox_dir)
: Genericwrapper(),MBOXPath(mbox_dir)
@@ -66,9 +66,8 @@ void MBOXwrapper::listMessages(const QString & mailbox, QList<RecMail> &target )
mail->setWrapper(this);
mail_flags * flag_result = 0;
r = mailmessage_get_flags(msg,&flag_result);
if (r == MAIL_ERROR_NOT_IMPLEMENTED) {
- qDebug("flag fetching not implemented");
mFlags.setBit(FLAG_SEEN);
}
mailimf_single_fields single_fields;
mailimf_single_fields_init(&single_fields, msg->msg_fields);
@@ -196,4 +195,25 @@ RecBody MBOXwrapper::fetchBody( const RecMail &mail )
void MBOXwrapper::mbox_progress( size_t current, size_t maximum )
{
qDebug("MBOX %i von %i",current,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
@@ -18,8 +18,10 @@ public:
virtual QList<Folder>* listFolders();
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual void createFolder(const QString&aFolder);
+ virtual void storeMessage(const char*msg,size_t length, const QString&folder);
virtual RecBody fetchBody( const RecMail &mail );
static void mbox_progress( size_t current, size_t maximum );
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
@@ -5,16 +5,19 @@
#include <fcntl.h>
#include <string.h>
#include <qdir.h>
-#include <libetpan/mailmime.h>
+#include <libetpan/libetpan.h>
+#if 0
#include <libetpan/mailimf.h>
#include <libetpan/mailsmtp.h>
#include <libetpan/mailstorage.h>
#include <libetpan/maildriver.h>
+#endif
#include "smtpwrapper.h"
#include "mailwrapper.h"
+#include "mboxwrapper.h"
#include "logindialog.h"
#include "defines.h"
SMTPwrapper::SMTPwrapper( Settings *s )
@@ -464,8 +467,25 @@ void SMTPwrapper::writeToFile(const QString&file, mailmime *mail )
}
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;
struct stat st;
int fd, count = 0, total = 0;
@@ -494,16 +514,26 @@ void SMTPwrapper::readFromFile(const QString&file, char **data, size_t *size )
err_free:
free( buf );
err_close:
close( fd );
+#endif
}
void SMTPwrapper::progress( size_t current, size_t maximum )
{
qDebug( "Current: %i of %i", current, 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 )
{
mailsmtp *session;
clist *rcpts;
char *from, *data, *server, *user = NULL, *pass = NULL;
@@ -518,19 +548,29 @@ void SMTPwrapper::smtpSend( mailmime *mail )
if ( smtp == NULL ) {
free(from);
return;
}
- server = strdup( smtp->getServer().latin1() );
- ssl = smtp->getSSL();
- port = smtp->getPort().toUInt();
rcpts = createRcptList( mail->mm_data.mm_message.mm_fields );
QString file = getTmpFile();
writeToFile( file, mail );
+
readFromFile( file, &data, &size );
QFile f( file );
f.remove();
+
+ 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 );
if ( session == NULL ) goto free_mem;
qDebug( "Servername %s at port %i", server, port );
@@ -580,25 +620,26 @@ free_con_session:
free_mem_session:
mailsmtp_free( session );
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() ) {
free( user );
free( pass );
}
free( from );
}
-void SMTPwrapper::sendMail(const Mail&mail )
+void SMTPwrapper::sendMail(const Mail&mail,bool later )
{
- mailmime *mimeMail;
+ mailmime * mimeMail;
mimeMail = createMimeMail(mail );
if ( mimeMail == NULL ) {
qDebug( "sendMail: error creating mime 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
@@ -23,9 +23,9 @@ class SMTPwrapper : public QObject
public:
SMTPwrapper( Settings *s );
virtual ~SMTPwrapper(){}
- void sendMail(const Mail& mail );
+ void sendMail(const Mail& mail,bool later=false );
protected:
mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
mailimf_fields *createImfFields(const Mail &mail );
@@ -34,20 +34,22 @@ protected:
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 );
- void smtpSend( mailmime *mail );
+ void smtpSend( mailmime *mail,bool later );
mailimf_field *getField( mailimf_fields *fields, int type );
clist *createRcptList( mailimf_fields *fields );
char *getFrom( mailmime *mail );
SMTPaccount *getAccount(const QString&from );
void writeToFile(const QString&file, mailmime *mail );
void readFromFile(const QString&file, char **data, size_t *size );
+ 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 );
+ void storeMail(mailmime*mail, const QString&box);
Settings *settings;
};
#endif