summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.cpp454
-rw-r--r--noncore/net/mail/libmailwrapper/generatemail.h44
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.cpp52
-rw-r--r--noncore/net/mail/libmailwrapper/genericwrapper.h4
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp49
-rw-r--r--noncore/net/mail/libmailwrapper/libmailwrapper.pro16
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp19
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h25
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.cpp464
-rw-r--r--noncore/net/mail/libmailwrapper/smtpwrapper.h32
10 files changed, 625 insertions, 534 deletions
diff --git a/noncore/net/mail/libmailwrapper/generatemail.cpp b/noncore/net/mail/libmailwrapper/generatemail.cpp
new file mode 100644
index 0000000..9272d0c
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/generatemail.cpp
@@ -0,0 +1,454 @@
+#include "generatemail.h"
+#include "mailwrapper.h"
+
+#include <libetpan/libetpan.h>
+
+#include <qt.h>
+
+const char* Generatemail::USER_AGENT="OpieMail v0.5";
+
+Generatemail::Generatemail()
+{
+}
+
+Generatemail::~Generatemail()
+{
+}
+
+void Generatemail::addRcpts( clist *list, mailimf_address_list *addr_list ) {
+ clistiter *it, *it2;
+
+ for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
+ mailimf_address *addr;
+ addr = (mailimf_address *) it->data;
+
+ if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
+ esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
+ } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
+ clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
+ for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
+ mailimf_mailbox *mbox;
+ mbox = (mailimf_mailbox *) it2->data;
+ esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
+ }
+ }
+ }
+}
+
+char *Generatemail::getFrom( mailimf_field *ffrom) {
+ char *from = NULL;
+ if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
+ && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
+ clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
+ clistiter *it;
+ for ( it = clist_begin( cl ); it; it = it->next ) {
+ mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
+ from = strdup( mb->mb_addr_spec );
+ }
+ }
+
+ return from;
+}
+
+char *Generatemail::getFrom( mailmime *mail ) {
+ /* no need to delete - its just a pointer to structure content */
+ mailimf_field *ffrom = 0;
+ ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
+ return getFrom(ffrom);
+}
+
+mailimf_field *Generatemail::getField( mailimf_fields *fields, int type ) {
+ mailimf_field *field;
+ clistiter *it;
+
+ it = clist_begin( fields->fld_list );
+ while ( it ) {
+ field = (mailimf_field *) it->data;
+ if ( field->fld_type == type ) {
+ return field;
+ }
+ it = it->next;
+ }
+
+ return NULL;
+}
+
+mailimf_address_list *Generatemail::parseAddresses(const QString&addr ) {
+ mailimf_address_list *addresses;
+
+ if ( addr.isEmpty() )
+ return NULL;
+
+ addresses = mailimf_address_list_new_empty();
+
+ bool literal_open = false;
+ unsigned int startpos = 0;
+ QStringList list;
+ QString s;
+ unsigned int i = 0;
+ for (; i < addr.length();++i) {
+ switch (addr[i]) {
+ case '\"':
+ literal_open = !literal_open;
+ break;
+ case ',':
+ if (!literal_open) {
+ s = addr.mid(startpos,i-startpos);
+ if (!s.isEmpty()) {
+ list.append(s);
+ qDebug("Appended %s",s.latin1());
+ }
+ // !!!! this is a MUST BE!
+ startpos = ++i;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ s = addr.mid(startpos,i-startpos);
+ if (!s.isEmpty()) {
+ list.append(s);
+ qDebug("Appended %s",s.latin1());
+ }
+ QStringList::Iterator it;
+ for ( it = list.begin(); it != list.end(); it++ ) {
+ int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
+ if ( err != MAILIMF_NO_ERROR ) {
+ qDebug( "Error parsing" );
+ qDebug( *it );
+ } else {
+ qDebug( "Parse success! %s",(*it).latin1());
+ }
+ }
+ return addresses;
+}
+
+mailmime *Generatemail::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
+ mailmime * filePart = 0;
+ mailmime_fields * fields = 0;
+ mailmime_content * content = 0;
+ mailmime_parameter * param = 0;
+ char*name = 0;
+ char*file = 0;
+ int err;
+
+ int pos = filename.findRev( '/' );
+
+ if (filename.length()>0) {
+ QString tmp = filename.right( filename.length() - ( pos + 1 ) );
+ name = strdup( tmp.latin1() ); // just filename
+ file = strdup( filename.latin1() ); // full name with path
+ }
+
+ int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
+ int mechanism = MAILMIME_MECHANISM_BASE64;
+
+ if ( mimetype.startsWith( "text/" ) ) {
+ param = mailmime_parameter_new( strdup( "charset" ),
+ strdup( "iso-8859-1" ) );
+ mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
+ }
+
+ fields = mailmime_fields_new_filename(
+ disptype, name,
+ mechanism );
+ content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
+ if (content!=0 && fields != 0) {
+ if (param) {
+ clist_append(content->ct_parameters,param);
+ param = 0;
+ }
+ if (filename.length()>0) {
+ QFileInfo f(filename);
+ param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
+ clist_append(content->ct_parameters,param);
+ param = 0;
+ }
+ filePart = mailmime_new_empty( content, fields );
+ }
+ if (filePart) {
+ if (filename.length()>0) {
+ err = mailmime_set_body_file( filePart, file );
+ } else {
+ err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
+ }
+ if (err != MAILIMF_NO_ERROR) {
+ qDebug("Error setting body with file %s",file);
+ mailmime_free( filePart );
+ filePart = 0;
+ }
+ }
+
+ if (!filePart) {
+ if ( param != NULL ) {
+ mailmime_parameter_free( param );
+ }
+ if (content) {
+ mailmime_content_free( content );
+ }
+ if (fields) {
+ mailmime_fields_free( fields );
+ } else {
+ if (name) {
+ free( name );
+ }
+ if (file) {
+ free( file );
+ }
+ }
+ }
+ return filePart; // Success :)
+
+}
+
+void Generatemail::addFileParts( mailmime *message,const QList<Attachment>&files ) {
+ const Attachment *it;
+ unsigned int count = files.count();
+ qDebug("List contains %i values",count);
+ for ( unsigned int i = 0; i < count; ++i ) {
+ qDebug( "Adding file" );
+ mailmime *filePart;
+ int err;
+ it = ((QList<Attachment>)files).at(i);
+
+ filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
+ if ( filePart == NULL ) {
+ qDebug( "addFileParts: error adding file:" );
+ qDebug( it->getFileName() );
+ continue;
+ }
+ err = mailmime_smart_add_part( message, filePart );
+ if ( err != MAILIMF_NO_ERROR ) {
+ mailmime_free( filePart );
+ qDebug("error smart add");
+ }
+ }
+}
+
+mailmime *Generatemail::buildTxtPart(const QString&str ) {
+ mailmime *txtPart;
+ mailmime_fields *fields;
+ mailmime_content *content;
+ mailmime_parameter *param;
+ int err;
+
+ param = mailmime_parameter_new( strdup( "charset" ),
+ strdup( "iso-8859-1" ) );
+ if ( param == NULL )
+ goto err_free;
+
+ content = mailmime_content_new_with_str( "text/plain" );
+ if ( content == NULL )
+ goto err_free_param;
+
+ err = clist_append( content->ct_parameters, param );
+ if ( err != MAILIMF_NO_ERROR )
+ goto err_free_content;
+
+ fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
+ if ( fields == NULL )
+ goto err_free_content;
+
+ txtPart = mailmime_new_empty( content, fields );
+ if ( txtPart == NULL )
+ goto err_free_fields;
+
+ err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
+ if ( err != MAILIMF_NO_ERROR )
+ goto err_free_txtPart;
+
+ return txtPart; // Success :)
+
+err_free_txtPart:
+ mailmime_free( txtPart );
+err_free_fields:
+ mailmime_fields_free( fields );
+err_free_content:
+ mailmime_content_free( content );
+err_free_param:
+ mailmime_parameter_free( param );
+err_free:
+ qDebug( "buildTxtPart - error" );
+
+ return NULL; // Error :(
+}
+
+mailimf_mailbox *Generatemail::newMailbox(const QString&name, const QString&mail ) {
+ return mailimf_mailbox_new( strdup( name.latin1() ),
+ strdup( mail.latin1() ) );
+}
+
+mailimf_fields *Generatemail::createImfFields(const Mail&mail ) {
+ mailimf_fields *fields;
+ mailimf_field *xmailer;
+ mailimf_mailbox *sender=0,*fromBox=0;
+ mailimf_mailbox_list *from=0;
+ mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
+ clist*in_reply_to = 0;
+ char *subject = strdup( mail.getSubject().latin1() );
+ int err;
+
+ sender = newMailbox( mail.getName(), mail.getMail() );
+ if ( sender == NULL )
+ goto err_free;
+
+ fromBox = newMailbox( mail.getName(), mail.getMail() );
+ if ( fromBox == NULL )
+ goto err_free_sender;
+
+ from = mailimf_mailbox_list_new_empty();
+ if ( from == NULL )
+ goto err_free_fromBox;
+
+ err = mailimf_mailbox_list_add( from, fromBox );
+ if ( err != MAILIMF_NO_ERROR )
+ goto err_free_from;
+
+ to = parseAddresses( mail.getTo() );
+ if ( to == NULL )
+ goto err_free_from;
+
+ cc = parseAddresses( mail.getCC() );
+ bcc = parseAddresses( mail.getBCC() );
+ reply = parseAddresses( mail.getReply() );
+
+ if (mail.Inreply().count()>0) {
+ in_reply_to = clist_new();
+ char*c_reply;
+ unsigned int nsize = 0;
+ for (QStringList::ConstIterator it=mail.Inreply().begin();
+ it != mail.Inreply().end();++it) {
+ if ((*it).isEmpty())
+ continue;
+ QString h((*it));
+ while (h.length()>0 && h[0]=='<') {
+ h.remove(0,1);
+ }
+ while (h.length()>0 && h[h.length()-1]=='>') {
+ h.remove(h.length()-1,1);
+ }
+ if (h.isEmpty()) continue;
+ nsize = strlen(h.latin1());
+ /* yes! must be malloc! */
+ c_reply = (char*)malloc( (nsize+1)*sizeof(char));
+ memset(c_reply,0,nsize+1);
+ memcpy(c_reply,h.latin1(),nsize);
+ clist_append(in_reply_to,c_reply);
+ qDebug("In reply to: %s",c_reply);
+ }
+ }
+
+ fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
+ in_reply_to, NULL, subject );
+ if ( fields == NULL )
+ goto err_free_reply;
+
+ xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
+ strdup( USER_AGENT ) );
+ if ( xmailer == NULL )
+ goto err_free_fields;
+
+ err = mailimf_fields_add( fields, xmailer );
+ if ( err != MAILIMF_NO_ERROR )
+ goto err_free_xmailer;
+
+ return fields; // Success :)
+
+err_free_xmailer:
+ if (xmailer)
+ mailimf_field_free( xmailer );
+err_free_fields:
+ if (fields)
+ mailimf_fields_free( fields );
+err_free_reply:
+ if (reply)
+ mailimf_address_list_free( reply );
+ if (bcc)
+ mailimf_address_list_free( bcc );
+ if (cc)
+ mailimf_address_list_free( cc );
+ if (to)
+ mailimf_address_list_free( to );
+err_free_from:
+ if (from)
+ mailimf_mailbox_list_free( from );
+err_free_fromBox:
+ mailimf_mailbox_free( fromBox );
+err_free_sender:
+ if (sender)
+ mailimf_mailbox_free( sender );
+err_free:
+ if (subject)
+ free( subject );
+ qDebug( "createImfFields - error" );
+
+ return NULL; // Error :(
+}
+
+mailmime *Generatemail::createMimeMail(const Mail &mail ) {
+ mailmime *message, *txtPart;
+ mailimf_fields *fields;
+ int err;
+
+ fields = createImfFields( mail );
+ if ( fields == NULL )
+ goto err_free;
+
+ message = mailmime_new_message_data( NULL );
+ if ( message == NULL )
+ goto err_free_fields;
+
+ mailmime_set_imf_fields( message, fields );
+
+ txtPart = buildTxtPart( mail.getMessage() );
+
+ if ( txtPart == NULL )
+ goto err_free_message;
+
+ err = mailmime_smart_add_part( message, txtPart );
+ if ( err != MAILIMF_NO_ERROR )
+ goto err_free_txtPart;
+
+ addFileParts( message, mail.getAttachments() );
+
+ return message; // Success :)
+
+err_free_txtPart:
+ mailmime_free( txtPart );
+err_free_message:
+ mailmime_free( message );
+err_free_fields:
+ mailimf_fields_free( fields );
+err_free:
+ qDebug( "createMimeMail: error" );
+
+ return NULL; // Error :(
+}
+
+clist *Generatemail::createRcptList( mailimf_fields *fields ) {
+ clist *rcptList;
+ mailimf_field *field;
+
+ rcptList = esmtp_address_list_new();
+
+ field = getField( fields, MAILIMF_FIELD_TO );
+ if ( field && (field->fld_type == MAILIMF_FIELD_TO)
+ && field->fld_data.fld_to->to_addr_list ) {
+ addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
+ }
+
+ field = getField( fields, MAILIMF_FIELD_CC );
+ if ( field && (field->fld_type == MAILIMF_FIELD_CC)
+ && field->fld_data.fld_cc->cc_addr_list ) {
+ addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
+ }
+
+ field = getField( fields, MAILIMF_FIELD_BCC );
+ if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
+ && field->fld_data.fld_bcc->bcc_addr_list ) {
+ addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
+ }
+
+ return rcptList;
+}
diff --git a/noncore/net/mail/libmailwrapper/generatemail.h b/noncore/net/mail/libmailwrapper/generatemail.h
new file mode 100644
index 0000000..8be5a2b
--- a/dev/null
+++ b/noncore/net/mail/libmailwrapper/generatemail.h
@@ -0,0 +1,44 @@
+#ifndef __GENERATE_MAIL_H
+#define __GENERATE_MAIL_H
+
+#include <qpe/applnk.h>
+
+#include <qobject.h>
+#include <libetpan/clist.h>
+
+class Mail;
+class RecMail;
+class Attachment;
+struct mailimf_fields;
+struct mailimf_field;
+struct mailimf_mailbox;
+struct mailmime;
+struct mailimf_address_list;
+class progressMailSend;
+struct mailsmtp;
+
+class Generatemail : public QObject
+{
+ Q_OBJECT
+public:
+ Generatemail();
+ virtual ~Generatemail();
+
+protected:
+ 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 );
+ mailimf_address_list *parseAddresses(const QString&addr );
+ void addFileParts( mailmime *message,const QList<Attachment>&files );
+ mailmime *buildFilePart(const QString&filename,const QString&mimetype,const QString&content);
+ mailmime *buildTxtPart(const QString&str );
+ mailimf_mailbox *newMailbox(const QString&name,const QString&mail );
+ mailimf_fields *createImfFields(const Mail &mail );
+ mailmime *createMimeMail(const Mail&mail );
+ clist *createRcptList( mailimf_fields *fields );
+
+ static const char* USER_AGENT;
+};
+
+#endif
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.cpp b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
index eb2c031..137a6ef 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.cpp
@@ -35,3 +35,3 @@ void Genericwrapper::fillSingleBody(RecPart&target,mailmessage*,mailmime*mime)
}
-
+
mailmime_content*type = fields.fld_content;
@@ -147,3 +147,3 @@ void Genericwrapper::traverseBody(RecBody&target,mailmessage*message,mailmime*mi
RecPart part;
-
+
switch (mime->mm_type) {
@@ -243,6 +243,6 @@ QString Genericwrapper::parseDateTime( mailimf_date_time *date )
char tmp[23];
-
- snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
+
+ snprintf( tmp, 23, "%02i.%02i.%04i %02i:%02i:%02i %+05i",
date->dt_day, date->dt_month, date->dt_year, date->dt_hour, date->dt_min, date->dt_sec, date->dt_zone );
-
+
return QString( tmp );
@@ -258,3 +258,3 @@ QString Genericwrapper::parseAddressList( mailimf_address_list *list )
mailimf_address *addr = (mailimf_address *) current->data;
-
+
if ( !first ) {
@@ -277,3 +277,3 @@ QString Genericwrapper::parseAddressList( mailimf_address_list *list )
}
-
+
return result;
@@ -293,3 +293,3 @@ QString Genericwrapper::parseGroup( mailimf_group *group )
result.append( ";" );
-
+
return result;
@@ -309,3 +309,3 @@ QString Genericwrapper::parseMailbox( mailimf_mailbox *box )
}
-
+
return result;
@@ -326,6 +326,6 @@ QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list )
}
-
+
result.append( parseMailbox( box ) );
}
-
+
return result;
@@ -369,2 +369,22 @@ void Genericwrapper::cleanMimeCache()
+QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies)
+{
+ QStringList res;
+ if (!in_replies || !in_replies->mid_list) return res;
+ clistiter * current = 0;
+ for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) {
+ QString h((char*)current->data);
+ while (h.length()>0 && h[0]=='<') {
+ h.remove(0,1);
+ }
+ while (h.length()>0 && h[h.length()-1]=='>') {
+ h.remove(h.length()-1,1);
+ }
+ if (h.length()>0) {
+ res.append(h);
+ }
+ }
+ return res;
+}
+
void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to)
@@ -386,3 +406,4 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const
}
- mailimf_references * refs;
+ mailimf_references * refs = 0;
+ mailimf_in_reply_to * in_replies = 0;
uint32_t i = 0;
@@ -428,4 +449,5 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const
mail->setMsgid(QString(single_fields.fld_message_id->mid_value));
- qDebug("Msqgid == %s",mail->Msgid().latin1());
+ qDebug("Msgid == %s",mail->Msgid().latin1());
}
+
refs = single_fields.fld_references;
@@ -435,2 +457,6 @@ void Genericwrapper::parseList(QList<RecMail> &target,mailsession*session,const
}
+ if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list &&
+ clist_count(single_fields.fld_in_reply_to->mid_list)) {
+ mail->setInreply(parseInreplies(single_fields.fld_in_reply_to));
+ }
target.append(mail);
diff --git a/noncore/net/mail/libmailwrapper/genericwrapper.h b/noncore/net/mail/libmailwrapper/genericwrapper.h
index 0870912..b3cd4fe 100644
--- a/noncore/net/mail/libmailwrapper/genericwrapper.h
+++ b/noncore/net/mail/libmailwrapper/genericwrapper.h
@@ -23,2 +23,3 @@ struct mailstorage;
struct mailfolder;
+struct mailimf_in_reply_to;
@@ -50,3 +51,3 @@ protected:
QString parseDateTime( mailimf_date_time *date );
-
+
void traverseBody(RecBody&target,mailmessage*message,mailmime*mime,QValueList<int>recList,unsigned int current_rek=0,int current_count=1);
@@ -56,2 +57,3 @@ protected:
virtual void parseList(QList<RecMail> &target,mailsession*session,const QString&mailbox,bool mbox_as_to=false);
+ QStringList parseInreplies(mailimf_in_reply_to * in_replies);
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index 3375e69..e29a0a0 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -115,18 +115,18 @@ void IMAPwrapper::login()
port = account->getPort().toUInt();
- if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
- LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
- login.show();
- if ( QDialog::Accepted == login.exec() ) {
- // ok
- user = login.getUser().latin1();
- pass = login.getPassword().latin1();
- } else {
- // cancel
- qDebug( "IMAP: Login canceled" );
- return;
- }
- } else {
- user = account->getUser().latin1();
- pass = account->getPassword().latin1();
- }
+ if ( account->getUser().isEmpty() || account->getPassword().isEmpty() ) {
+ LoginDialog login( account->getUser(), account->getPassword(), NULL, 0, true );
+ login.show();
+ if ( QDialog::Accepted == login.exec() ) {
+ // ok
+ user = login.getUser().latin1();
+ pass = login.getPassword().latin1();
+ } else {
+ // cancel
+ qDebug( "IMAP: Login canceled" );
+ return;
+ }
+ } else {
+ user = account->getUser().latin1();
+ pass = account->getPassword().latin1();
+ }
@@ -440,2 +440,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
+ /* reply to address, eg. email. */
if (head->env_reply_to!=NULL) {
@@ -446,3 +447,17 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
- m->setMsgid(QString(head->env_message_id));
+ if (head->env_in_reply_to!=NULL) {
+ QString h(head->env_in_reply_to);
+ while (h.length()>0 && h[0]=='<') {
+ h.remove(0,1);
+ }
+ while (h.length()>0 && h[h.length()-1]=='>') {
+ h.remove(h.length()-1,1);
+ }
+ if (h.length()>0) {
+ m->setInreply(QStringList(h));
+ }
+ }
+ if (head->env_message_id) {
+ m->setMsgid(QString(head->env_message_id));
+ }
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
diff --git a/noncore/net/mail/libmailwrapper/libmailwrapper.pro b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
index 8ea04a4..cb1e573 100644
--- a/noncore/net/mail/libmailwrapper/libmailwrapper.pro
+++ b/noncore/net/mail/libmailwrapper/libmailwrapper.pro
@@ -1,3 +1,3 @@
TEMPLATE = lib
-CONFIG += qt warn_on debug
+CONFIG += qt warn_on debug
@@ -16,4 +16,5 @@ HEADERS = mailwrapper.h \
mhwrapper.h \
- nntpwrapper.h
-
+ nntpwrapper.h \
+ generatemail.h
+
SOURCES = imapwrapper.cpp \
@@ -31,7 +32,8 @@ SOURCES = imapwrapper.cpp \
mhwrapper.cpp \
- nntpwrapper.cpp
+ nntpwrapper.cpp \
+ generatemail.cpp
-INTERFACES = logindialogui.ui \
+INTERFACES = logindialogui.ui \
sendmailprogressui.ui
-
+
@@ -43,3 +45,3 @@ contains( CONFTEST, y ){
}else{
- LIBS += -lqpe -letpan -lssl -lcrypto
+ LIBS += -lqpe -letpan -lssl -lcrypto
}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 96e0fd5..e4646d9 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -37,2 +37,3 @@ void RecMail::copy_old(const RecMail&old)
in_reply_to = old.in_reply_to;
+ references = old.references;
}
@@ -45,2 +46,3 @@ void RecMail::init()
in_reply_to.clear();
+ references.clear();
wrapper = 0;
@@ -98,2 +100,11 @@ const QStringList& RecMail::Inreply()const
+void RecMail::setReferences(const QStringList&list)
+{
+ references = list;
+}
+
+const QStringList& RecMail::References()const
+{
+ return references;
+}
@@ -114,3 +125,3 @@ void RecPart::setSize(unsigned int size)
}
-
+
const unsigned int RecPart::Size()const
@@ -124,3 +135,3 @@ void RecPart::setLines(unsigned int lines)
}
-
+
const unsigned int RecPart::Lines()const
@@ -179,3 +190,3 @@ void RecPart::setDescription(const QString&desc)
}
-
+
void RecPart::setParameters(const part_plist_t&list)
@@ -339,3 +350,3 @@ void encodedString::setContent(const char*nContent,int nSize)
memcpy(content,nContent,nSize);
- size = nSize;
+ size = nSize;
}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 1420f79..17c6db9 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -22,4 +22,4 @@ class AbstractMail;
store the mail body into this class, too.
- But: not from the point of view of the device.
- Mailbodies can be real large. So we request them when
+ But: not from the point of view of the device.
+ Mailbodies can be real large. So we request them when
needed from the mail-wrapper class direct from the server itself
@@ -63,5 +63,8 @@ public:
const QStringList&Inreply()const;
+ void setReferences(const QStringList&list);
+ const QStringList&References()const;
+
const QBitArray&getFlags()const{return msg_flags;}
void setFlags(const QBitArray&flags){msg_flags = flags;}
-
+
void setWrapper(AbstractMail*wrapper);
@@ -73,3 +76,3 @@ protected:
QBitArray msg_flags;
- QStringList to,cc,bcc,in_reply_to;
+ QStringList to,cc,bcc,in_reply_to,references;
AbstractMail*wrapper;
@@ -93,3 +96,3 @@ public:
virtual ~RecPart();
-
+
const QString&Type()const;
@@ -109,3 +112,3 @@ public:
-
+
void setParameters(const part_plist_t&list);
@@ -133,3 +136,3 @@ public:
const RecPart& Description()const;
-
+
void setParts(const QValueList<RecPart>&parts);
@@ -144,3 +147,3 @@ public:
/*
- creates an new content string.
+ creates an new content string.
it makes a deep copy of it!
@@ -160,3 +163,3 @@ public:
virtual ~encodedString();
-
+
/* returns a pointer to the content - do not delete yoursel! */
@@ -165,3 +168,3 @@ public:
const int Length()const;
-
+
/*
@@ -180,3 +183,3 @@ protected:
unsigned int size;
-
+
void init();
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
index 63acfd5..a4e0beb 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.cpp
@@ -1,14 +1 @@
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <qt.h>
-
-#include <qpe/config.h>
-#include <qpe/qcopenvelope_qws.h>
-
-#include <libetpan/libetpan.h>
-
#include "smtpwrapper.h"
@@ -20,3 +7,9 @@
-const char* SMTPwrapper::USER_AGENT="OpieMail v0.4";
+#include <qt.h>
+
+#include <qpe/config.h>
+#include <qpe/qcopenvelope_qws.h>
+
+#include <libetpan/libetpan.h>
+
@@ -25,3 +18,3 @@ progressMailSend*SMTPwrapper::sendProgress = 0;
SMTPwrapper::SMTPwrapper(SMTPaccount * aSmtp )
- : QObject()
+ : Generatemail()
{
@@ -89,439 +82,2 @@ QString SMTPwrapper::mailsmtpError( int errnum ) {
-mailimf_mailbox *SMTPwrapper::newMailbox(const QString&name, const QString&mail ) {
- return mailimf_mailbox_new( strdup( name.latin1() ),
- strdup( mail.latin1() ) );
-}
-
-mailimf_address_list *SMTPwrapper::parseAddresses(const QString&addr ) {
- mailimf_address_list *addresses;
-
- if ( addr.isEmpty() )
- return NULL;
-
- addresses = mailimf_address_list_new_empty();
-
- bool literal_open = false;
- unsigned int startpos = 0;
- QStringList list;
- QString s;
- unsigned int i = 0;
- for (; i < addr.length();++i) {
- switch (addr[i]) {
- case '\"':
- literal_open = !literal_open;
- break;
- case ',':
- if (!literal_open) {
- s = addr.mid(startpos,i-startpos);
- if (!s.isEmpty()) {
- list.append(s);
- qDebug("Appended %s",s.latin1());
- }
- // !!!! this is a MUST BE!
- startpos = ++i;
- }
- break;
- default:
- break;
- }
- }
- s = addr.mid(startpos,i-startpos);
- if (!s.isEmpty()) {
- list.append(s);
- qDebug("Appended %s",s.latin1());
- }
- QStringList::Iterator it;
- for ( it = list.begin(); it != list.end(); it++ ) {
- int err = mailimf_address_list_add_parse( addresses, (char*)(*it).latin1() );
- if ( err != MAILIMF_NO_ERROR ) {
- qDebug( "Error parsing" );
- qDebug( *it );
- } else {
- qDebug( "Parse success! %s",(*it).latin1());
- }
- }
- return addresses;
-}
-
-mailimf_fields *SMTPwrapper::createImfFields(const Mail&mail ) {
- mailimf_fields *fields;
- mailimf_field *xmailer;
- mailimf_mailbox *sender=0,*fromBox=0;
- mailimf_mailbox_list *from=0;
- mailimf_address_list *to=0, *cc=0, *bcc=0, *reply=0;
- clist*in_reply_to = 0;
- char *subject = strdup( mail.getSubject().latin1() );
- int err;
-
- sender = newMailbox( mail.getName(), mail.getMail() );
- if ( sender == NULL )
- goto err_free;
-
- fromBox = newMailbox( mail.getName(), mail.getMail() );
- if ( fromBox == NULL )
- goto err_free_sender;
-
- from = mailimf_mailbox_list_new_empty();
- if ( from == NULL )
- goto err_free_fromBox;
-
- err = mailimf_mailbox_list_add( from, fromBox );
- if ( err != MAILIMF_NO_ERROR )
- goto err_free_from;
-
- to = parseAddresses( mail.getTo() );
- if ( to == NULL )
- goto err_free_from;
-
- cc = parseAddresses( mail.getCC() );
- bcc = parseAddresses( mail.getBCC() );
- reply = parseAddresses( mail.getReply() );
-
- if (mail.Inreply().count()>0) {
- in_reply_to = clist_new();
- char*c_reply;
- unsigned int nsize = 0;
- for (QStringList::ConstIterator it=mail.Inreply().begin();
- it != mail.Inreply().end();++it) {
- /* yes! must be malloc! */
- if ((*it).isEmpty())
- continue;
- QString h((*it));
- while (h.length()>0 && h[0]=='<') {
- h.remove(0,1);
- }
- while (h.length()>0 && h[h.length()-1]=='>') {
- h.remove(h.length()-1,1);
- }
- if (h.isEmpty()) continue;
- nsize = strlen(h.latin1());
- c_reply = (char*)malloc( (nsize+1)*sizeof(char));
- memset(c_reply,0,nsize+1);
- memcpy(c_reply,h.latin1(),nsize);
- clist_append(in_reply_to,c_reply);
- qDebug("In reply to: %s",c_reply);
- }
- }
-
- fields = mailimf_fields_new_with_data( from, sender, reply, to, cc, bcc,
- in_reply_to, NULL, subject );
- if ( fields == NULL )
- goto err_free_reply;
-
- xmailer = mailimf_field_new_custom( strdup( "User-Agent" ),
- strdup( USER_AGENT ) );
- if ( xmailer == NULL )
- goto err_free_fields;
-
- err = mailimf_fields_add( fields, xmailer );
- if ( err != MAILIMF_NO_ERROR )
- goto err_free_xmailer;
-
- return fields; // Success :)
-
-err_free_xmailer:
- if (xmailer)
- mailimf_field_free( xmailer );
-err_free_fields:
- if (fields)
- mailimf_fields_free( fields );
-err_free_reply:
- if (reply)
- mailimf_address_list_free( reply );
- if (bcc)
- mailimf_address_list_free( bcc );
- if (cc)
- mailimf_address_list_free( cc );
- if (to)
- mailimf_address_list_free( to );
-err_free_from:
- if (from)
- mailimf_mailbox_list_free( from );
-err_free_fromBox:
- mailimf_mailbox_free( fromBox );
-err_free_sender:
- if (sender)
- mailimf_mailbox_free( sender );
-err_free:
- if (subject)
- free( subject );
- qDebug( "createImfFields - error" );
-
- return NULL; // Error :(
-}
-
-mailmime *SMTPwrapper::buildTxtPart(const QString&str ) {
- mailmime *txtPart;
- mailmime_fields *fields;
- mailmime_content *content;
- mailmime_parameter *param;
- int err;
-
- param = mailmime_parameter_new( strdup( "charset" ),
- strdup( "iso-8859-1" ) );
- if ( param == NULL )
- goto err_free;
-
- content = mailmime_content_new_with_str( "text/plain" );
- if ( content == NULL )
- goto err_free_param;
-
- err = clist_append( content->ct_parameters, param );
- if ( err != MAILIMF_NO_ERROR )
- goto err_free_content;
-
- fields = mailmime_fields_new_encoding(MAILMIME_MECHANISM_8BIT);
- if ( fields == NULL )
- goto err_free_content;
-
- txtPart = mailmime_new_empty( content, fields );
- if ( txtPart == NULL )
- goto err_free_fields;
-
- err = mailmime_set_body_text( txtPart, (char*)str.data(), str.length() );
- if ( err != MAILIMF_NO_ERROR )
- goto err_free_txtPart;
-
- return txtPart; // Success :)
-
-err_free_txtPart:
- mailmime_free( txtPart );
-err_free_fields:
- mailmime_fields_free( fields );
-err_free_content:
- mailmime_content_free( content );
-err_free_param:
- mailmime_parameter_free( param );
-err_free:
- qDebug( "buildTxtPart - error" );
-
- return NULL; // Error :(
-}
-
-mailmime *SMTPwrapper::buildFilePart(const QString&filename,const QString&mimetype,const QString&TextContent ) {
- mailmime * filePart = 0;
- mailmime_fields * fields = 0;
- mailmime_content * content = 0;
- mailmime_parameter * param = 0;
- char*name = 0;
- char*file = 0;
- int err;
-
- int pos = filename.findRev( '/' );
-
- if (filename.length()>0) {
- QString tmp = filename.right( filename.length() - ( pos + 1 ) );
- name = strdup( tmp.latin1() ); // just filename
- file = strdup( filename.latin1() ); // full name with path
- }
-
- int disptype = MAILMIME_DISPOSITION_TYPE_ATTACHMENT;
- int mechanism = MAILMIME_MECHANISM_BASE64;
-
- if ( mimetype.startsWith( "text/" ) ) {
- param = mailmime_parameter_new( strdup( "charset" ),
- strdup( "iso-8859-1" ) );
- mechanism = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
- }
-
- fields = mailmime_fields_new_filename(
- disptype, name,
- mechanism );
- content = mailmime_content_new_with_str( (char*)mimetype.latin1() );
- if (content!=0 && fields != 0) {
- if (param) {
- clist_append(content->ct_parameters,param);
- param = 0;
- }
- if (filename.length()>0) {
- QFileInfo f(filename);
- param = mailmime_parameter_new(strdup("name"),strdup(f.fileName().latin1()));
- clist_append(content->ct_parameters,param);
- param = 0;
- }
- filePart = mailmime_new_empty( content, fields );
- }
- if (filePart) {
- if (filename.length()>0) {
- err = mailmime_set_body_file( filePart, file );
- } else {
- err = mailmime_set_body_text(filePart,strdup(TextContent.data()),TextContent.length());
- }
- if (err != MAILIMF_NO_ERROR) {
- qDebug("Error setting body with file %s",file);
- mailmime_free( filePart );
- filePart = 0;
- }
- }
-
- if (!filePart) {
- if ( param != NULL ) {
- mailmime_parameter_free( param );
- }
- if (content) {
- mailmime_content_free( content );
- }
- if (fields) {
- mailmime_fields_free( fields );
- } else {
- if (name) {
- free( name );
- }
- if (file) {
- free( file );
- }
- }
- }
- return filePart; // Success :)
-
-}
-
-void SMTPwrapper::addFileParts( mailmime *message,const QList<Attachment>&files ) {
- const Attachment *it;
- unsigned int count = files.count();
- qDebug("List contains %i values",count);
- for ( unsigned int i = 0; i < count; ++i ) {
- qDebug( "Adding file" );
- mailmime *filePart;
- int err;
- it = ((QList<Attachment>)files).at(i);
-
- filePart = buildFilePart( it->getFileName(), it->getMimeType(),"" );
- if ( filePart == NULL ) {
- qDebug( "addFileParts: error adding file:" );
- qDebug( it->getFileName() );
- continue;
- }
- err = mailmime_smart_add_part( message, filePart );
- if ( err != MAILIMF_NO_ERROR ) {
- mailmime_free( filePart );
- qDebug("error smart add");
- }
- }
-}
-
-mailmime *SMTPwrapper::createMimeMail(const Mail &mail ) {
- mailmime *message, *txtPart;
- mailimf_fields *fields;
- int err;
-
- fields = createImfFields( mail );
- if ( fields == NULL )
- goto err_free;
-
- message = mailmime_new_message_data( NULL );
- if ( message == NULL )
- goto err_free_fields;
-
- mailmime_set_imf_fields( message, fields );
-
- txtPart = buildTxtPart( mail.getMessage() );
-
- if ( txtPart == NULL )
- goto err_free_message;
-
- err = mailmime_smart_add_part( message, txtPart );
- if ( err != MAILIMF_NO_ERROR )
- goto err_free_txtPart;
-
- addFileParts( message, mail.getAttachments() );
-
- return message; // Success :)
-
-err_free_txtPart:
- mailmime_free( txtPart );
-err_free_message:
- mailmime_free( message );
-err_free_fields:
- mailimf_fields_free( fields );
-err_free:
- qDebug( "createMimeMail: error" );
-
- return NULL; // Error :(
-}
-
-mailimf_field *SMTPwrapper::getField( mailimf_fields *fields, int type ) {
- mailimf_field *field;
- clistiter *it;
-
- it = clist_begin( fields->fld_list );
- while ( it ) {
- field = (mailimf_field *) it->data;
- if ( field->fld_type == type ) {
- return field;
- }
- it = it->next;
- }
-
- return NULL;
-}
-
-void SMTPwrapper::addRcpts( clist *list, mailimf_address_list *addr_list ) {
- clistiter *it, *it2;
-
- for ( it = clist_begin( addr_list->ad_list ); it; it = it->next ) {
- mailimf_address *addr;
- addr = (mailimf_address *) it->data;
-
- if ( addr->ad_type == MAILIMF_ADDRESS_MAILBOX ) {
- esmtp_address_list_add( list, addr->ad_data.ad_mailbox->mb_addr_spec, 0, NULL );
- } else if ( addr->ad_type == MAILIMF_ADDRESS_GROUP ) {
- clist *l = addr->ad_data.ad_group->grp_mb_list->mb_list;
- for ( it2 = clist_begin( l ); it2; it2 = it2->next ) {
- mailimf_mailbox *mbox;
- mbox = (mailimf_mailbox *) it2->data;
- esmtp_address_list_add( list, mbox->mb_addr_spec, 0, NULL );
- }
- }
- }
-}
-
-clist *SMTPwrapper::createRcptList( mailimf_fields *fields ) {
- clist *rcptList;
- mailimf_field *field;
-
- rcptList = esmtp_address_list_new();
-
- field = getField( fields, MAILIMF_FIELD_TO );
- if ( field && (field->fld_type == MAILIMF_FIELD_TO)
- && field->fld_data.fld_to->to_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_to->to_addr_list );
- }
-
- field = getField( fields, MAILIMF_FIELD_CC );
- if ( field && (field->fld_type == MAILIMF_FIELD_CC)
- && field->fld_data.fld_cc->cc_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_cc->cc_addr_list );
- }
-
- field = getField( fields, MAILIMF_FIELD_BCC );
- if ( field && (field->fld_type == MAILIMF_FIELD_BCC)
- && field->fld_data.fld_bcc->bcc_addr_list ) {
- addRcpts( rcptList, field->fld_data.fld_bcc->bcc_addr_list );
- }
-
- return rcptList;
-}
-
-char *SMTPwrapper::getFrom( mailimf_field *ffrom) {
- char *from = NULL;
- if ( ffrom && (ffrom->fld_type == MAILIMF_FIELD_FROM)
- && ffrom->fld_data.fld_from->frm_mb_list && ffrom->fld_data.fld_from->frm_mb_list->mb_list ) {
- clist *cl = ffrom->fld_data.fld_from->frm_mb_list->mb_list;
- clistiter *it;
- for ( it = clist_begin( cl ); it; it = it->next ) {
- mailimf_mailbox *mb = (mailimf_mailbox *) it->data;
- from = strdup( mb->mb_addr_spec );
- }
- }
-
- return from;
-}
-
-char *SMTPwrapper::getFrom( mailmime *mail ) {
- /* no need to delete - its just a pointer to structure content */
- mailimf_field *ffrom = 0;
- ffrom = getField( mail->mm_data.mm_message.mm_fields, MAILIMF_FIELD_FROM );
- return getFrom(ffrom);
-}
@@ -631,3 +187,3 @@ void SMTPwrapper::connect_server()
QString failuretext = "";
-
+
if (m_smtp || !m_SmtpAccount) {
@@ -694,3 +250,3 @@ void SMTPwrapper::connect_server()
// get'em
- LoginDialog login( m_SmtpAccount->getUser(),
+ LoginDialog login( m_SmtpAccount->getUser(),
m_SmtpAccount->getPassword(), NULL, 0, true );
diff --git a/noncore/net/mail/libmailwrapper/smtpwrapper.h b/noncore/net/mail/libmailwrapper/smtpwrapper.h
index 7f6aac1..1796df7 100644
--- a/noncore/net/mail/libmailwrapper/smtpwrapper.h
+++ b/noncore/net/mail/libmailwrapper/smtpwrapper.h
@@ -11,17 +11,8 @@
#include "settings.h"
+#include "generatemail.h"
-class Mail;
-class AbstractMail;
-class RecMail;
-class Attachment;
-struct mailimf_fields;
-struct mailimf_field;
-struct mailimf_mailbox;
-struct mailmime;
-struct mailimf_address_list;
-class progressMailSend;
-struct mailsmtp;
class SMTPaccount;
+class AbstractMail;
-class SMTPwrapper : public QObject
+class SMTPwrapper : public Generatemail
{
@@ -47,13 +38,5 @@ protected:
int start_smtp_tls();
-
- 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);
- clist *createRcptList( mailimf_fields *fields );
@@ -62,6 +45,2 @@ protected:
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 );
@@ -75,3 +54,2 @@ protected:
int m_queuedMail;
- static const char* USER_AGENT;