summaryrefslogtreecommitdiff
path: root/noncore
authoralwin <alwin>2003-12-16 13:14:05 (UTC)
committer alwin <alwin>2003-12-16 13:14:05 (UTC)
commit49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838 (patch) (side-by-side diff)
tree710393582789ed1db97592fed5bb88ad4d56550d /noncore
parentf42c15f884d4377bc99d73e16fa1722b0fb2a4d3 (diff)
downloadopie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.zip
opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.gz
opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.bz2
saving of attachments implemented.
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/abstractmail.cpp28
-rw-r--r--noncore/net/mail/abstractmail.h8
-rw-r--r--noncore/net/mail/imapwrapper.cpp78
-rw-r--r--noncore/net/mail/imapwrapper.h12
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.cpp28
-rw-r--r--noncore/net/mail/libmailwrapper/abstractmail.h8
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp78
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h12
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp90
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h47
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/libmailwrapper/pop3wrapper.h6
-rw-r--r--noncore/net/mail/mailtypes.cpp90
-rw-r--r--noncore/net/mail/mailtypes.h47
-rw-r--r--noncore/net/mail/pop3wrapper.cpp11
-rw-r--r--noncore/net/mail/pop3wrapper.h6
-rw-r--r--noncore/net/mail/viewmail.cpp13
17 files changed, 477 insertions, 96 deletions
diff --git a/noncore/net/mail/abstractmail.cpp b/noncore/net/mail/abstractmail.cpp
index 0bb2525..92a46f1 100644
--- a/noncore/net/mail/abstractmail.cpp
+++ b/noncore/net/mail/abstractmail.cpp
@@ -1,9 +1,10 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
+#include "mailtypes.h"
#include <qstring.h>
#include <stdlib.h>
#include <libetpan/mailmime_content.h>
AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
@@ -13,22 +14,35 @@ AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
AbstractMail* AbstractMail::getWrapper(POP3account *a)
{
return new POP3wrapper(a);
}
-QString AbstractMail::decode_quoted_printable(const char*text)
+encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
{
+ qDebug("Decode string start");
char*result_text;
size_t index = 0;
- QString result = "";
/* reset for recursive use! */
size_t target_length = 0;
result_text = 0;
- int err = mailmime_quoted_printable_body_parse(text,strlen(text),
- &index,&result_text,&target_length,0);
- if (result_text) {
- result = result_text;
- free(result_text);
+ int mimetype = MAILMIME_MECHANISM_7BIT;
+ if (enc.lower()=="quoted-printable") {
+ mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
+ } else if (enc.lower()=="base64") {
+ mimetype = MAILMIME_MECHANISM_BASE64;
+ } else if (enc.lower()=="8bit") {
+ mimetype = MAILMIME_MECHANISM_8BIT;
+ } else if (enc.lower()=="binary") {
+ mimetype = MAILMIME_MECHANISM_BINARY;
}
+
+ int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
+ &result_text,&target_length);
+
+ encodedString* result = new encodedString();
+ if (err == MAILIMF_NO_ERROR) {
+ result->setContent(result_text,target_length);
+ }
+ qDebug("Decode string finished");
return result;
}
diff --git a/noncore/net/mail/abstractmail.h b/noncore/net/mail/abstractmail.h
index 4473ad2..f1a8468 100644
--- a/noncore/net/mail/abstractmail.h
+++ b/noncore/net/mail/abstractmail.h
@@ -7,25 +7,29 @@
class RecMail;
class RecBody;
class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
+class encodedString;
class AbstractMail:public QObject
{
Q_OBJECT
public:
AbstractMail(){};
virtual ~AbstractMail(){}
virtual QList<Folder>* listFolders()=0;
virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
virtual RecBody fetchBody(const RecMail&mail)=0;
- virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
+
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
static AbstractMail* getWrapper(IMAPaccount *a);
static AbstractMail* getWrapper(POP3account *a);
- static QString decode_quoted_printable(const char*text);
+ static encodedString*decode_String(const encodedString*text,const QString&enc);
};
#endif
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index a4e6228..d56d7f9 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -299,14 +299,15 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
if (addresslist.count()) {
m->setReplyto(addresslist.first());
}
}
m->setMsgid(QString(head->env_message_id));
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
- mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
#if 0
+
+ mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
qDebug(da.toString());
#endif
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
size = item->att_data.att_static->att_data.att_rfc822_size;
@@ -388,26 +389,20 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
RecPart singlePart;
QValueList<int> path;
fillSinglePart(singlePart,mailDescription);
switch (mailDescription->bd_type) {
case MAILIMAP_BODY_TYPE_1PART_MSG:
path.append(1);
- body_text = fetchPart(mail,path,true);
- if (singlePart.Encoding()=="quoted-printable") {
- body_text = decode_quoted_printable(body_text.latin1());
- }
+ body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
target_body.setBodytext(body_text);
target_body.setDescription(singlePart);
break;
case MAILIMAP_BODY_TYPE_1PART_TEXT:
qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
path.append(1);
- body_text = fetchPart(mail,path,true);
- if (singlePart.Encoding()=="quoted-printable") {
- body_text = decode_quoted_printable(body_text.latin1());
- }
+ body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
target_body.setBodytext(body_text);
target_body.setDescription(singlePart);
break;
case MAILIMAP_BODY_TYPE_1PART_BASIC:
qDebug("Single attachment");
target_body.setBodytext("");
@@ -458,31 +453,31 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
break;
}
}
return l;
}
-QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
+encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
{
- QString body("");
+ encodedString*res=new encodedString;
const char*mb;
int err;
mailimap_fetch_type *fetchType;
mailimap_set *set;
clistcell*current,*cur;
login();
if (!m_imap) {
- return body;
+ return res;
}
if (!internal_call) {
mb = mail.getMbox().latin1();
err = mailimap_select( m_imap, (char*)mb);
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- return body;
+ return res;
}
}
set = mailimap_set_new_single(mail.getNumber());
clist*id_list=clist_new();
for (unsigned j=0; j < path.count();++j) {
uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
@@ -508,32 +503,23 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
mailimap_msg_att_item*msg_att_item;
for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
+ /* detach - we take over the content */
msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
- if (text) {
- if (enc=="quoted-printable") {
- body = decode_quoted_printable(text);
- } else {
- body = QString(text);
- }
- free(text);
- } else {
- body = "";
- }
+ res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
}
}
- }
-
+ }
} else {
qDebug("error fetching text: %s",m_imap->imap_response);
}
mailimap_fetch_list_free(result);
- return body;
+ return res;
}
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
{
/* current_recursion is for avoiding ugly mails which has a to deep body-structure */
if (!mailDescription||current_recursion==10) {
@@ -554,13 +540,13 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
RecPart currentPart;
fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
QValueList<int>clist = recList;
clist.append(count);
/* important: Check for is NULL 'cause a body can be empty! */
if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
- QString body_text = fetchPart(mail,clist,true,currentPart.Encoding());
+ QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
target_body.setDescription(currentPart);
target_body.setBodytext(body_text);
} else {
QString id("");
for (unsigned int j = 0; j < clist.count();++j) {
id+=(j>0?" ":"");
@@ -710,17 +696,12 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
target_part.setDescription(QString(which->bd_description));
}
target_part.setEncoding(encoding);
target_part.setSize(which->bd_size);
}
-QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
-{
- return fetchPart(mail,part.Positionlist(),false,part.Encoding());
-}
-
void IMAPwrapper::deleteMail(const RecMail&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
@@ -781,6 +762,39 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
if (err != MAILIMAP_NO_ERROR) {
qDebug("error marking mail: %s",m_imap->imap_response);
return;
}
}
+
+QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
+{
+ QString body("");
+ encodedString*res = fetchRawPart(mail,path,internal_call);
+ encodedString*r = decode_String(res,enc);
+ delete res;
+ if (r) {
+ if (r->Length()>0) {
+ body = r->Content();
+ }
+ delete r;
+ }
+ return body;
+}
+
+QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
+{
+ return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
+}
+
+encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
+{
+ encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
+ encodedString*r = decode_String(res,part.Encoding());
+ delete res;
+ return r;
+}
+
+encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
+{
+ return fetchRawPart(mail,part.Positionlist(),false);
+}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 768a517..aeebda8 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -10,34 +10,40 @@ struct mailimap_body_type_1part;
struct mailimap_body_type_text;
struct mailimap_body_type_basic;
struct mailimap_body_type_msg;
struct mailimap_body_type_mpart;
struct mailimap_body_fields;
struct mailimap_msg_att;
+class encodedString;
class IMAPwrapper : public AbstractMail
{
Q_OBJECT
public:
IMAPwrapper( IMAPaccount *a );
virtual ~IMAPwrapper();
virtual QList<Folder>* listFolders();
virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
- virtual RecBody fetchBody(const RecMail&mail);
- virtual QString fetchPart(const RecMail&mail,const RecPart&part);
+
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual RecBody fetchBody(const RecMail&mail);
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
+
static void imap_progress( size_t current, size_t maximum );
protected:
RecMail*parse_list_result(mailimap_msg_att*);
void login();
void logout();
- virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
+ virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
+ virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.cpp b/noncore/net/mail/libmailwrapper/abstractmail.cpp
index 0bb2525..92a46f1 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.cpp
+++ b/noncore/net/mail/libmailwrapper/abstractmail.cpp
@@ -1,9 +1,10 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
+#include "mailtypes.h"
#include <qstring.h>
#include <stdlib.h>
#include <libetpan/mailmime_content.h>
AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
@@ -13,22 +14,35 @@ AbstractMail* AbstractMail::getWrapper(IMAPaccount *a)
AbstractMail* AbstractMail::getWrapper(POP3account *a)
{
return new POP3wrapper(a);
}
-QString AbstractMail::decode_quoted_printable(const char*text)
+encodedString* AbstractMail::decode_String(const encodedString*text,const QString&enc)
{
+ qDebug("Decode string start");
char*result_text;
size_t index = 0;
- QString result = "";
/* reset for recursive use! */
size_t target_length = 0;
result_text = 0;
- int err = mailmime_quoted_printable_body_parse(text,strlen(text),
- &index,&result_text,&target_length,0);
- if (result_text) {
- result = result_text;
- free(result_text);
+ int mimetype = MAILMIME_MECHANISM_7BIT;
+ if (enc.lower()=="quoted-printable") {
+ mimetype = MAILMIME_MECHANISM_QUOTED_PRINTABLE;
+ } else if (enc.lower()=="base64") {
+ mimetype = MAILMIME_MECHANISM_BASE64;
+ } else if (enc.lower()=="8bit") {
+ mimetype = MAILMIME_MECHANISM_8BIT;
+ } else if (enc.lower()=="binary") {
+ mimetype = MAILMIME_MECHANISM_BINARY;
}
+
+ int err = mailmime_part_parse(text->Content(),text->Length(),&index,mimetype,
+ &result_text,&target_length);
+
+ encodedString* result = new encodedString();
+ if (err == MAILIMF_NO_ERROR) {
+ result->setContent(result_text,target_length);
+ }
+ qDebug("Decode string finished");
return result;
}
diff --git a/noncore/net/mail/libmailwrapper/abstractmail.h b/noncore/net/mail/libmailwrapper/abstractmail.h
index 4473ad2..f1a8468 100644
--- a/noncore/net/mail/libmailwrapper/abstractmail.h
+++ b/noncore/net/mail/libmailwrapper/abstractmail.h
@@ -7,25 +7,29 @@
class RecMail;
class RecBody;
class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
+class encodedString;
class AbstractMail:public QObject
{
Q_OBJECT
public:
AbstractMail(){};
virtual ~AbstractMail(){}
virtual QList<Folder>* listFolders()=0;
virtual void listMessages(const QString & mailbox,QList<RecMail>&target )=0;
virtual RecBody fetchBody(const RecMail&mail)=0;
- virtual QString fetchPart(const RecMail&mail,const RecPart&part)=0;
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part)=0;
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part)=0;
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part)=0;
+
virtual void deleteMail(const RecMail&mail)=0;
virtual void answeredMail(const RecMail&mail)=0;
static AbstractMail* getWrapper(IMAPaccount *a);
static AbstractMail* getWrapper(POP3account *a);
- static QString decode_quoted_printable(const char*text);
+ static encodedString*decode_String(const encodedString*text,const QString&enc);
};
#endif
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index a4e6228..d56d7f9 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -299,14 +299,15 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
if (addresslist.count()) {
m->setReplyto(addresslist.first());
}
}
m->setMsgid(QString(head->env_message_id));
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_INTERNALDATE) {
- mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
#if 0
+
+ mailimap_date_time*d = item->att_data.att_static->att_data.att_internal_date;
QDateTime da(QDate(d->dt_year,d->dt_month,d->dt_day),QTime(d->dt_hour,d->dt_min,d->dt_sec));
qDebug("%i %i %i - %i %i %i",d->dt_year,d->dt_month,d->dt_day,d->dt_hour,d->dt_min,d->dt_sec);
qDebug(da.toString());
#endif
} else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_RFC822_SIZE) {
size = item->att_data.att_static->att_data.att_rfc822_size;
@@ -388,26 +389,20 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
RecPart singlePart;
QValueList<int> path;
fillSinglePart(singlePart,mailDescription);
switch (mailDescription->bd_type) {
case MAILIMAP_BODY_TYPE_1PART_MSG:
path.append(1);
- body_text = fetchPart(mail,path,true);
- if (singlePart.Encoding()=="quoted-printable") {
- body_text = decode_quoted_printable(body_text.latin1());
- }
+ body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
target_body.setBodytext(body_text);
target_body.setDescription(singlePart);
break;
case MAILIMAP_BODY_TYPE_1PART_TEXT:
qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
path.append(1);
- body_text = fetchPart(mail,path,true);
- if (singlePart.Encoding()=="quoted-printable") {
- body_text = decode_quoted_printable(body_text.latin1());
- }
+ body_text = fetchTextPart(mail,path,true,singlePart.Encoding());
target_body.setBodytext(body_text);
target_body.setDescription(singlePart);
break;
case MAILIMAP_BODY_TYPE_1PART_BASIC:
qDebug("Single attachment");
target_body.setBodytext("");
@@ -458,31 +453,31 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
break;
}
}
return l;
}
-QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
+encodedString*IMAPwrapper::fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call)
{
- QString body("");
+ encodedString*res=new encodedString;
const char*mb;
int err;
mailimap_fetch_type *fetchType;
mailimap_set *set;
clistcell*current,*cur;
login();
if (!m_imap) {
- return body;
+ return res;
}
if (!internal_call) {
mb = mail.getMbox().latin1();
err = mailimap_select( m_imap, (char*)mb);
if ( err != MAILIMAP_NO_ERROR ) {
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- return body;
+ return res;
}
}
set = mailimap_set_new_single(mail.getNumber());
clist*id_list=clist_new();
for (unsigned j=0; j < path.count();++j) {
uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
@@ -508,32 +503,23 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
mailimap_msg_att_item*msg_att_item;
for(cur = clist_begin(msg_att->att_list) ; cur != NULL ; cur = clist_next(cur)) {
msg_att_item = (mailimap_msg_att_item*)clist_content(cur);
if (msg_att_item->att_type == MAILIMAP_MSG_ATT_ITEM_STATIC) {
if (msg_att_item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_BODY_SECTION) {
char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
+ /* detach - we take over the content */
msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
- if (text) {
- if (enc=="quoted-printable") {
- body = decode_quoted_printable(text);
- } else {
- body = QString(text);
- }
- free(text);
- } else {
- body = "";
- }
+ res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
}
}
- }
-
+ }
} else {
qDebug("error fetching text: %s",m_imap->imap_response);
}
mailimap_fetch_list_free(result);
- return body;
+ return res;
}
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion,QValueList<int>recList)
{
/* current_recursion is for avoiding ugly mails which has a to deep body-structure */
if (!mailDescription||current_recursion==10) {
@@ -554,13 +540,13 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
RecPart currentPart;
fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
QValueList<int>clist = recList;
clist.append(count);
/* important: Check for is NULL 'cause a body can be empty! */
if (currentPart.Type()=="text" && target_body.Bodytext().isNull() ) {
- QString body_text = fetchPart(mail,clist,true,currentPart.Encoding());
+ QString body_text = fetchTextPart(mail,clist,true,currentPart.Encoding());
target_body.setDescription(currentPart);
target_body.setBodytext(body_text);
} else {
QString id("");
for (unsigned int j = 0; j < clist.count();++j) {
id+=(j>0?" ":"");
@@ -710,17 +696,12 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
target_part.setDescription(QString(which->bd_description));
}
target_part.setEncoding(encoding);
target_part.setSize(which->bd_size);
}
-QString IMAPwrapper::fetchPart(const RecMail&mail,const RecPart&part)
-{
- return fetchPart(mail,part.Positionlist(),false,part.Encoding());
-}
-
void IMAPwrapper::deleteMail(const RecMail&mail)
{
mailimap_flag_list*flist;
mailimap_set *set;
mailimap_store_att_flags * store_flags;
int err;
@@ -781,6 +762,39 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
if (err != MAILIMAP_NO_ERROR) {
qDebug("error marking mail: %s",m_imap->imap_response);
return;
}
}
+
+QString IMAPwrapper::fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call,const QString&enc)
+{
+ QString body("");
+ encodedString*res = fetchRawPart(mail,path,internal_call);
+ encodedString*r = decode_String(res,enc);
+ delete res;
+ if (r) {
+ if (r->Length()>0) {
+ body = r->Content();
+ }
+ delete r;
+ }
+ return body;
+}
+
+QString IMAPwrapper::fetchTextPart(const RecMail&mail,const RecPart&part)
+{
+ return fetchTextPart(mail,part.Positionlist(),false,part.Encoding());
+}
+
+encodedString* IMAPwrapper::fetchDecodedPart(const RecMail&mail,const RecPart&part)
+{
+ encodedString*res = fetchRawPart(mail,part.Positionlist(),false);
+ encodedString*r = decode_String(res,part.Encoding());
+ delete res;
+ return r;
+}
+
+encodedString* IMAPwrapper::fetchRawPart(const RecMail&mail,const RecPart&part)
+{
+ return fetchRawPart(mail,part.Positionlist(),false);
+}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 768a517..aeebda8 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -10,34 +10,40 @@ struct mailimap_body_type_1part;
struct mailimap_body_type_text;
struct mailimap_body_type_basic;
struct mailimap_body_type_msg;
struct mailimap_body_type_mpart;
struct mailimap_body_fields;
struct mailimap_msg_att;
+class encodedString;
class IMAPwrapper : public AbstractMail
{
Q_OBJECT
public:
IMAPwrapper( IMAPaccount *a );
virtual ~IMAPwrapper();
virtual QList<Folder>* listFolders();
virtual void listMessages(const QString & mailbox,QList<RecMail>&target );
- virtual RecBody fetchBody(const RecMail&mail);
- virtual QString fetchPart(const RecMail&mail,const RecPart&part);
+
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
+ virtual RecBody fetchBody(const RecMail&mail);
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
+
static void imap_progress( size_t current, size_t maximum );
protected:
RecMail*parse_list_result(mailimap_msg_att*);
void login();
void logout();
- virtual QString fetchPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
+ virtual QString fetchTextPart(const RecMail&mail,const QValueList<int>&path,bool internal_call=false,const QString&enc="");
+ virtual encodedString*fetchRawPart(const RecMail&mail,const QValueList<int>&path,bool internal_call);
void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion=0,QValueList<int>recList=QValueList<int>());
void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index 8d9b247..d8a36e7 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -1,8 +1,8 @@
#include "mailtypes.h"
-
+#include <stdlib.h>
RecMail::RecMail()
:subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
{
init();
}
@@ -242,6 +242,94 @@ void RecBody::setDescription(const RecPart&des)
}
const RecPart& RecBody::Description()const
{
return m_description;
}
+
+/* handling encoded content */
+encodedString::encodedString()
+{
+ init();
+}
+
+encodedString::encodedString(const char*nContent,unsigned int nSize)
+{
+ init();
+ setContent(nContent,nSize);
+}
+
+encodedString::encodedString(char*nContent,unsigned int nSize)
+{
+ init();
+ setContent(nContent,nSize);
+}
+
+encodedString::encodedString(const encodedString&old)
+{
+ init();
+ copy_old(old);
+ qDebug("encodedeString: copy constructor!");
+}
+
+encodedString& encodedString::operator=(const encodedString&old)
+{
+ init();
+ copy_old(old);
+ qDebug("encodedString: assign operator!");
+ return *this;
+}
+
+encodedString::~encodedString()
+{
+ clean();
+}
+
+void encodedString::init()
+{
+ content = 0;
+ size = 0;
+}
+
+void encodedString::clean()
+{
+ if (content) {
+ free(content);
+ }
+ content = 0;
+ size = 0;
+}
+
+void encodedString::copy_old(const encodedString&old)
+{
+ clean();
+ if (old.size>0 && old.content) {
+ content = (char*)malloc(old.size*sizeof(char));
+ memcpy(content,old.content,size);
+ size = old.size;
+ }
+}
+
+const char*encodedString::Content()const
+{
+ return content;
+}
+
+const int encodedString::Length()const
+{
+ return size;
+}
+
+void encodedString::setContent(const char*nContent,int nSize)
+{
+ if (nSize>0 && nContent) {
+ content = (char*)malloc(nSize*sizeof(char));
+ memcpy(content,nContent,nSize);
+ size = nSize;
+ }
+}
+
+void encodedString::setContent(char*nContent,int nSize)
+{
+ content = nContent;
+ size = nSize;
+}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 7d7bebc..abfbe65 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -132,7 +132,54 @@ public:
void setParts(const QValueList<RecPart>&parts);
const QValueList<RecPart>& Parts()const;
void addPart(const RecPart&part);
};
+class encodedString
+{
+public:
+ encodedString();
+ /*
+ creates an new content string.
+ it makes a deep copy of it!
+ */
+ encodedString(const char*nContent,unsigned int length);
+ /*
+ Take over the nContent. Means: it will just copy the pointer, not the content.
+ so make sure: No one else frees the string, the string has allocated with
+ malloc for compatibility with c-based libs
+ */
+ encodedString(char*nContent,unsigned int nSize);
+ /* copy construkor - makes ALWAYS a deep copy!!!! */
+ encodedString(const encodedString&old);
+ /* assign operator - makes ALWAYS a deep copy!!!! */
+ encodedString& operator=(const encodedString&old);
+ /* destructor - cleans the content */
+ virtual ~encodedString();
+
+ /* returns a pointer to the content - do not delete yoursel! */
+ const char*Content()const;
+ /* returns the lengths of the content 'cause it must not be a null-terminated string! */
+ const int Length()const;
+
+ /*
+ makes a deep copy of nContent!
+ */
+ void setContent(const char*nContent,int nSize);
+ /*
+ Take over the nContent. Means: it will just copy the pointer, not the content.
+ so make sure: No one else frees the string, the string has allocated with
+ malloc for compatibility with c-based libs
+ */
+ void setContent(char*nContent,int nSize);
+
+protected:
+ char * content;
+ unsigned int size;
+
+ void init();
+ void copy_old(const encodedString&old);
+ void clean();
+};
+
#endif
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
index a33a16b..075d8c7 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.cpp
@@ -325,13 +325,13 @@ QList<Folder>* POP3wrapper::listFolders()
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
-QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
+QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
@@ -344,6 +344,15 @@ void POP3wrapper::deleteMail(const RecMail&mail)
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
+encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
+{
+ return new encodedString();
+}
+
+encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
+{
+ return new encodedString();
+}
diff --git a/noncore/net/mail/libmailwrapper/pop3wrapper.h b/noncore/net/mail/libmailwrapper/pop3wrapper.h
index 6ff8d62..8d3adda 100644
--- a/noncore/net/mail/libmailwrapper/pop3wrapper.h
+++ b/noncore/net/mail/libmailwrapper/pop3wrapper.h
@@ -3,25 +3,29 @@
#include "mailwrapper.h"
#include "abstractmail.h"
class RecMail;
class RecBody;
+class encodedString;
struct mailpop3;
class POP3wrapper : public AbstractMail
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
- virtual QString fetchPart(const RecMail&mail,const RecPart&part);
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
+
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index 8d9b247..d8a36e7 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -1,8 +1,8 @@
#include "mailtypes.h"
-
+#include <stdlib.h>
RecMail::RecMail()
:subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
{
init();
}
@@ -242,6 +242,94 @@ void RecBody::setDescription(const RecPart&des)
}
const RecPart& RecBody::Description()const
{
return m_description;
}
+
+/* handling encoded content */
+encodedString::encodedString()
+{
+ init();
+}
+
+encodedString::encodedString(const char*nContent,unsigned int nSize)
+{
+ init();
+ setContent(nContent,nSize);
+}
+
+encodedString::encodedString(char*nContent,unsigned int nSize)
+{
+ init();
+ setContent(nContent,nSize);
+}
+
+encodedString::encodedString(const encodedString&old)
+{
+ init();
+ copy_old(old);
+ qDebug("encodedeString: copy constructor!");
+}
+
+encodedString& encodedString::operator=(const encodedString&old)
+{
+ init();
+ copy_old(old);
+ qDebug("encodedString: assign operator!");
+ return *this;
+}
+
+encodedString::~encodedString()
+{
+ clean();
+}
+
+void encodedString::init()
+{
+ content = 0;
+ size = 0;
+}
+
+void encodedString::clean()
+{
+ if (content) {
+ free(content);
+ }
+ content = 0;
+ size = 0;
+}
+
+void encodedString::copy_old(const encodedString&old)
+{
+ clean();
+ if (old.size>0 && old.content) {
+ content = (char*)malloc(old.size*sizeof(char));
+ memcpy(content,old.content,size);
+ size = old.size;
+ }
+}
+
+const char*encodedString::Content()const
+{
+ return content;
+}
+
+const int encodedString::Length()const
+{
+ return size;
+}
+
+void encodedString::setContent(const char*nContent,int nSize)
+{
+ if (nSize>0 && nContent) {
+ content = (char*)malloc(nSize*sizeof(char));
+ memcpy(content,nContent,nSize);
+ size = nSize;
+ }
+}
+
+void encodedString::setContent(char*nContent,int nSize)
+{
+ content = nContent;
+ size = nSize;
+}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 7d7bebc..abfbe65 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -132,7 +132,54 @@ public:
void setParts(const QValueList<RecPart>&parts);
const QValueList<RecPart>& Parts()const;
void addPart(const RecPart&part);
};
+class encodedString
+{
+public:
+ encodedString();
+ /*
+ creates an new content string.
+ it makes a deep copy of it!
+ */
+ encodedString(const char*nContent,unsigned int length);
+ /*
+ Take over the nContent. Means: it will just copy the pointer, not the content.
+ so make sure: No one else frees the string, the string has allocated with
+ malloc for compatibility with c-based libs
+ */
+ encodedString(char*nContent,unsigned int nSize);
+ /* copy construkor - makes ALWAYS a deep copy!!!! */
+ encodedString(const encodedString&old);
+ /* assign operator - makes ALWAYS a deep copy!!!! */
+ encodedString& operator=(const encodedString&old);
+ /* destructor - cleans the content */
+ virtual ~encodedString();
+
+ /* returns a pointer to the content - do not delete yoursel! */
+ const char*Content()const;
+ /* returns the lengths of the content 'cause it must not be a null-terminated string! */
+ const int Length()const;
+
+ /*
+ makes a deep copy of nContent!
+ */
+ void setContent(const char*nContent,int nSize);
+ /*
+ Take over the nContent. Means: it will just copy the pointer, not the content.
+ so make sure: No one else frees the string, the string has allocated with
+ malloc for compatibility with c-based libs
+ */
+ void setContent(char*nContent,int nSize);
+
+protected:
+ char * content;
+ unsigned int size;
+
+ void init();
+ void copy_old(const encodedString&old);
+ void clean();
+};
+
#endif
diff --git a/noncore/net/mail/pop3wrapper.cpp b/noncore/net/mail/pop3wrapper.cpp
index a33a16b..075d8c7 100644
--- a/noncore/net/mail/pop3wrapper.cpp
+++ b/noncore/net/mail/pop3wrapper.cpp
@@ -325,13 +325,13 @@ QList<Folder>* POP3wrapper::listFolders()
folders->setAutoDelete( false );
Folder*inb=new Folder("INBOX");
folders->append(inb);
return folders;
}
-QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
+QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
void POP3wrapper::deleteMail(const RecMail&mail)
{
@@ -344,6 +344,15 @@ void POP3wrapper::deleteMail(const RecMail&mail)
}
void POP3wrapper::answeredMail(const RecMail&)
{
}
+encodedString* POP3wrapper::fetchDecodedPart(const RecMail&,const RecPart&)
+{
+ return new encodedString();
+}
+
+encodedString* POP3wrapper::fetchRawPart(const RecMail&,const RecPart&)
+{
+ return new encodedString();
+}
diff --git a/noncore/net/mail/pop3wrapper.h b/noncore/net/mail/pop3wrapper.h
index 6ff8d62..8d3adda 100644
--- a/noncore/net/mail/pop3wrapper.h
+++ b/noncore/net/mail/pop3wrapper.h
@@ -3,25 +3,29 @@
#include "mailwrapper.h"
#include "abstractmail.h"
class RecMail;
class RecBody;
+class encodedString;
struct mailpop3;
class POP3wrapper : public AbstractMail
{
Q_OBJECT
public:
POP3wrapper( POP3account *a );
virtual ~POP3wrapper();
/* mailbox will be ignored */
virtual void listMessages(const QString & mailbox, QList<RecMail> &target );
virtual QList<Folder>* listFolders();
- virtual QString fetchPart(const RecMail&mail,const RecPart&part);
+ virtual QString fetchTextPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchDecodedPart(const RecMail&mail,const RecPart&part);
+ virtual encodedString* fetchRawPart(const RecMail&mail,const RecPart&part);
+
virtual void deleteMail(const RecMail&mail);
virtual void answeredMail(const RecMail&mail);
RecBody fetchBody( const RecMail &mail );
static void pop3_progress( size_t current, size_t maximum );
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp
index 48b71eb..0947879 100644
--- a/noncore/net/mail/viewmail.cpp
+++ b/noncore/net/mail/viewmail.cpp
@@ -1,20 +1,22 @@
#include <qtextbrowser.h>
#include <qmessagebox.h>
#include <qtextstream.h>
#include <qaction.h>
#include <qpopupmenu.h>
+#include <qfile.h>
#include <qapplication.h>
#include <opie/ofiledialog.h>
#include "settings.h"
#include "composemail.h"
#include "viewmail.h"
#include "abstractmail.h"
#include "accountview.h"
+#include "mailtypes.h"
AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&desc,const QString&file,
const QString&fsize,int num)
: QListViewItem(parent,after),_partNum(num)
{
setText(0, mime);
@@ -131,23 +133,30 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
{ MimeTypes types;
types.insert( "all", "*" );
QString str = OFileDialog::getSaveFileName( 1,
"/", item->text( 2 ) , types, 0 );
if( !str.isEmpty() ) {
- qDebug( "first we will need a MIME wrapper" );
+ encodedString*content = m_recMail.Wrapper()->fetchDecodedPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] );
+ if (content) {
+ QFile output(str);
+ output.open(IO_WriteOnly);
+ output.writeBlock(content->Content(),content->Length());
+ output.close();
+ delete content;
+ }
}
}
break ;
case 1:
if ( ( ( AttachItem* )item )->Partnumber() == -1 ) {
setText();
} else {
if ( m_recMail.Wrapper() != 0l ) { // make sure that there is a wrapper , even after delete or simular actions
- browser->setText( m_recMail.Wrapper()->fetchPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
+ browser->setText( m_recMail.Wrapper()->fetchTextPart( m_recMail, m_body.Parts()[ ( ( AttachItem* )item )->Partnumber() ] ) );
}
}
break;
}
delete menu;
}