summaryrefslogtreecommitdiff
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
parentf42c15f884d4377bc99d73e16fa1722b0fb2a4d3 (diff)
downloadopie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.zip
opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.gz
opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.bz2
saving of attachments implemented.
Diffstat (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,6 +1,7 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
+#include "mailtypes.h"
#include <qstring.h>
#include <stdlib.h>
@@ -16,19 +17,32 @@ 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
@@ -10,6 +10,7 @@ class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
+class encodedString;
class AbstractMail:public QObject
{
@@ -20,12 +21,15 @@ public:
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
@@ -302,8 +302,9 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
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());
@@ -391,20 +392,14 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
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;
@@ -461,9 +456,9 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
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;
@@ -472,14 +467,14 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
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());
@@ -511,26 +506,17 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
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)
@@ -557,7 +543,7 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
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 {
@@ -713,11 +699,6 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
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;
@@ -784,3 +765,36 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
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
@@ -13,6 +13,7 @@ struct mailimap_body_type_msg;
struct mailimap_body_type_mpart;
struct mailimap_body_fields;
struct mailimap_msg_att;
+class encodedString;
class IMAPwrapper : public AbstractMail
{
@@ -22,11 +23,15 @@ public:
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:
@@ -34,7 +39,8 @@ protected:
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>());
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,6 +1,7 @@
#include "abstractmail.h"
#include "imapwrapper.h"
#include "pop3wrapper.h"
+#include "mailtypes.h"
#include <qstring.h>
#include <stdlib.h>
@@ -16,19 +17,32 @@ 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
@@ -10,6 +10,7 @@ class RecPart;
class IMAPwrapper;
class POP3wrapper;
class Folder;
+class encodedString;
class AbstractMail:public QObject
{
@@ -20,12 +21,15 @@ public:
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
@@ -302,8 +302,9 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
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());
@@ -391,20 +392,14 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
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;
@@ -461,9 +456,9 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
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;
@@ -472,14 +467,14 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
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());
@@ -511,26 +506,17 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo
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)
@@ -557,7 +543,7 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai
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 {
@@ -713,11 +699,6 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
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;
@@ -784,3 +765,36 @@ void IMAPwrapper::answeredMail(const RecMail&mail)
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
@@ -13,6 +13,7 @@ struct mailimap_body_type_msg;
struct mailimap_body_type_mpart;
struct mailimap_body_fields;
struct mailimap_msg_att;
+class encodedString;
class IMAPwrapper : public AbstractMail
{
@@ -22,11 +23,15 @@ public:
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:
@@ -34,7 +39,8 @@ protected:
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>());
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,5 +1,5 @@
#include "mailtypes.h"
-
+#include <stdlib.h>
RecMail::RecMail()
:subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
@@ -245,3 +245,91 @@ 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
@@ -135,4 +135,51 @@ public:
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
@@ -328,7 +328,7 @@ QList<Folder>* POP3wrapper::listFolders()
return folders;
}
-QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
+QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
@@ -347,3 +347,12 @@ 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
@@ -6,6 +6,7 @@
class RecMail;
class RecBody;
+class encodedString;
struct mailpop3;
class POP3wrapper : public AbstractMail
@@ -18,7 +19,10 @@ public:
/* 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);
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,5 +1,5 @@
#include "mailtypes.h"
-
+#include <stdlib.h>
RecMail::RecMail()
:subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
@@ -245,3 +245,91 @@ 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
@@ -135,4 +135,51 @@ public:
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
@@ -328,7 +328,7 @@ QList<Folder>* POP3wrapper::listFolders()
return folders;
}
-QString POP3wrapper::fetchPart(const RecMail&,const RecPart&)
+QString POP3wrapper::fetchTextPart(const RecMail&,const RecPart&)
{
return "";
}
@@ -347,3 +347,12 @@ 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
@@ -6,6 +6,7 @@
class RecMail;
class RecBody;
+class encodedString;
struct mailpop3;
class POP3wrapper : public AbstractMail
@@ -18,7 +19,10 @@ public:
/* 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);
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
@@ -3,6 +3,7 @@
#include <qtextstream.h>
#include <qaction.h>
#include <qpopupmenu.h>
+#include <qfile.h>
#include <qapplication.h>
#include <opie/ofiledialog.h>
@@ -12,6 +13,7 @@
#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)
@@ -134,7 +136,14 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
"/", 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 ;
@@ -144,7 +153,7 @@ void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int
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;