summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/imapwrapper.cpp214
-rw-r--r--noncore/net/mail/imapwrapper.h15
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.cpp214
-rw-r--r--noncore/net/mail/libmailwrapper/imapwrapper.h15
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.cpp39
-rw-r--r--noncore/net/mail/libmailwrapper/mailtypes.h16
-rw-r--r--noncore/net/mail/mailtypes.cpp39
-rw-r--r--noncore/net/mail/mailtypes.h16
8 files changed, 456 insertions, 112 deletions
diff --git a/noncore/net/mail/imapwrapper.cpp b/noncore/net/mail/imapwrapper.cpp
index e6e9fc9..27f1410 100644
--- a/noncore/net/mail/imapwrapper.cpp
+++ b/noncore/net/mail/imapwrapper.cpp
@@ -25,3 +25,2 @@ void IMAPwrapper::login()
{
- logout();
const char *server, *user, *pass;
@@ -30,2 +29,7 @@ void IMAPwrapper::login()
+ /* we are connected this moment */
+ /* TODO: setup a timer holding the line or if connection closed - delete the value */
+ if (m_imap) {
+ return;
+ }
server = account->getServer().latin1();
@@ -37,4 +41,3 @@ void IMAPwrapper::login()
/* connect */
- // err = mailimap_socket_connect( m_imap, (char*)server, port );
- if (account->getSSL()) {
+ if (account->getSSL()) {
err = mailimap_ssl_connect( m_imap, (char*)server, port );
@@ -79,3 +82,3 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
clistcell *current;
- mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
+// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
mailimap_fetch_type *fetchType;
@@ -92,3 +95,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- logout();
return;
@@ -100,3 +102,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("mailbox has no mails");
- logout();
return;
@@ -107,11 +108,7 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
set = mailimap_set_new_interval( 1, last );
- fetchAtt = mailimap_fetch_att_new_envelope();
- fetchAttFlags = mailimap_fetch_att_new_flags();
- fetchAttDate = mailimap_fetch_att_new_internaldate();
-
- //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
@@ -119,3 +116,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
mailimap_set_free( set );
- /* cleans up the fetch_att's too! */
mailimap_fetch_type_free( fetchType );
@@ -125,6 +121,6 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
if ( err == MAILIMAP_NO_ERROR ) {
- current = clist_begin(result);
+
mailimap_msg_att * msg_att;
int i = 0;
- while ( current != 0 ) {
+ for (current = clist_begin(result); current != 0; current=clist_next(current)) {
++i;
@@ -137,3 +133,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
}
- current = current->next;
}
@@ -142,4 +137,3 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
}
- logout();
- clist_free(result);
+ mailimap_fetch_list_free(result);
}
@@ -221,2 +215,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
mailimap_flag_fetch*cflag;
+ int size;
QBitArray mFlags(7);
@@ -227,7 +222,6 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
-
- c = clist_begin(m_att->att_list);
- while ( c ) {
+ m = new RecMail();
+ for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
current = c;
- c = c->next;
+ size = 0;
item = (mailimap_msg_att_item*)current->data;
@@ -239,3 +233,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
cf = flist->att_list->first;
- while (cf) {
+ for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
cflag = (mailimap_flag_fetch*)cf->data;
@@ -268,3 +262,2 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
- cf = cf->next;
}
@@ -272,7 +265,4 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
- if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
- qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
- } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
+ if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
- m = new RecMail();
m->setDate(head->env_date);
@@ -309,4 +299,4 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
qDebug(da.toString());
- } else {
- qDebug("Another type");
+ } 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;
}
@@ -320,2 +310,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
m->setFlags(mFlags);
+ m->setMsgsize(size);
}
@@ -346,5 +337,5 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- logout();
return body;
}
+
result = clist_new();
@@ -352,3 +343,3 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
- fetchAtt = mailimap_fetch_att_new_body();
+ fetchAtt = mailimap_fetch_att_new_bodystructure();
fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
@@ -365,5 +356,6 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
- } else {
+ } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
+ qDebug("Mulitpart mail");
+ searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0);
}
-
} else {
@@ -371,5 +363,3 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
}
-
- clist_free(result);
- logout();
+ mailimap_fetch_list_free(result);
return body;
@@ -377,2 +367,5 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
+/* this routine is just called when the mail has only ONE part.
+ for filling the parts of a multi-part-message there are other
+ routines 'cause we can not simply fetch the whole body. */
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
@@ -382,5 +375,16 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
}
+ QString sub;
switch (mailDescription->bd_type) {
+ case MAILIMAP_BODY_TYPE_1PART_MSG:
+ target_body.setType("text");
+ sub = mailDescription->bd_data.bd_type_text->bd_media_text;
+ target_body.setSubtype(sub.lower());
+ fillPlainBody(mail,target_body);
+ break;
case MAILIMAP_BODY_TYPE_1PART_TEXT:
- fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text);
+ qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
+ target_body.setType("text");
+ sub = mailDescription->bd_data.bd_type_text->bd_media_text;
+ target_body.setSubtype(sub.lower());
+ fillPlainBody(mail,target_body);
break;
@@ -392,3 +396,3 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
-void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd)
+void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
{
@@ -428,6 +432,9 @@ void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap
char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
- int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
- body = QString(text);
- free(text);
+ if (text) {
+ body = QString(text);
+ free(text);
+ } else {
+ body = "";
+ }
}
@@ -439,3 +446,2 @@ void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap
}
- //clist_free(result);
mailimap_fetch_list_free(result);
@@ -455,5 +461,4 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
}
- current = clist_begin(list);
unsigned int count = 0;
- while (current!= NULL) {
+ for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
from = "";
@@ -461,3 +466,2 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
current_address=(mailimap_address*)current->data;
- current = current->next;
if (current_address->ad_personal_name){
@@ -487 +491,115 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
}
+
+void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion)
+{
+ /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
+ if (!mailDescription||current_recursion==2) {
+ return;
+ }
+ qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
+ clistcell*current;
+ mailimap_body*current_body;
+ for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
+ current_body = (mailimap_body*)current->data;
+ if (current_body->bd_type==MAILIMAP_BODY_MPART) {
+ searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1);
+ } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
+ RecPart currentPart;
+ fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
+ target_body.addPart(currentPart);
+ }
+ }
+ if (current_recursion==0) {
+
+ }
+}
+
+void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
+{
+ if (!Description) {
+ return;
+ }
+ switch (Description->bd_type) {
+ case MAILIMAP_BODY_TYPE_1PART_TEXT:
+ target_part.setType("text");
+ fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
+ break;
+ case MAILIMAP_BODY_TYPE_1PART_BASIC:
+ fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
+ break;
+ default:
+ break;
+ }
+}
+
+void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
+{
+ if (!which) {
+ return;
+ }
+ QString sub;
+ sub = which->bd_media_text;
+ target_part.setSubtype(sub.lower());
+ target_part.setLines(which->bd_lines);
+ fillBodyFields(target_part,which->bd_fields);
+}
+
+void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
+{
+ if (!which) {
+ return;
+ }
+ QString type,sub;
+ switch (which->bd_media_basic->med_type) {
+ case MAILIMAP_MEDIA_BASIC_APPLICATION:
+ type = "application";
+ break;
+ case MAILIMAP_MEDIA_BASIC_AUDIO:
+ type = "audio";
+ break;
+ case MAILIMAP_MEDIA_BASIC_IMAGE:
+ type = "image";
+ break;
+ case MAILIMAP_MEDIA_BASIC_MESSAGE:
+ type = "message";
+ break;
+ case MAILIMAP_MEDIA_BASIC_VIDEO:
+ type = "video";
+ break;
+ case MAILIMAP_MEDIA_BASIC_OTHER:
+ default:
+ if (which->bd_media_basic->med_basic_type) {
+ type = which->bd_media_basic->med_basic_type;
+ } else {
+ type = "";
+ }
+ break;
+ }
+ if (which->bd_media_basic->med_subtype) {
+ sub = which->bd_media_basic->med_subtype;
+ } else {
+ sub = "";
+ }
+ qDebug("Type = %s/%s",type.latin1(),sub.latin1());
+ target_part.setType(type.lower());
+ target_part.setSubtype(sub.lower());
+ fillBodyFields(target_part,which->bd_fields);
+}
+
+void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
+{
+ if (!which) return;
+ if (which->bd_id) {
+ qDebug("Part ID = %s",which->bd_id);
+ target_part.setIdentifier(which->bd_id);
+ } else {
+ qDebug("ID empty");
+ target_part.setIdentifier("");
+ }
+
+ clistcell*cur;
+ mailimap_single_body_fld_param*param;
+ for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
+ param = (mailimap_single_body_fld_param*)cur->data;
+ }
+}
diff --git a/noncore/net/mail/imapwrapper.h b/noncore/net/mail/imapwrapper.h
index 90f3004..f809edb 100644
--- a/noncore/net/mail/imapwrapper.h
+++ b/noncore/net/mail/imapwrapper.h
@@ -9,2 +9,5 @@ struct mailimap_body_type_1part;
struct mailimap_body_type_text;
+struct mailimap_body_type_basic;
+struct mailimap_body_type_mpart;
+struct mailimap_body_fields;
struct mailimap_msg_att;
@@ -12,2 +15,3 @@ class RecMail;
class RecBody;
+class RecPart;
@@ -29,4 +33,13 @@ protected:
void logout();
+
void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
- void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body);
+ void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion);
+
+ void fillPlainBody(const RecMail&mail,RecBody&target_body);
+ void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
+ void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
+ void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
+
+ /* just helpers */
+ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
static QStringList address_list_to_stringlist(clist*list);
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.cpp b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
index e6e9fc9..27f1410 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.cpp
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.cpp
@@ -25,3 +25,2 @@ void IMAPwrapper::login()
{
- logout();
const char *server, *user, *pass;
@@ -30,2 +29,7 @@ void IMAPwrapper::login()
+ /* we are connected this moment */
+ /* TODO: setup a timer holding the line or if connection closed - delete the value */
+ if (m_imap) {
+ return;
+ }
server = account->getServer().latin1();
@@ -37,4 +41,3 @@ void IMAPwrapper::login()
/* connect */
- // err = mailimap_socket_connect( m_imap, (char*)server, port );
- if (account->getSSL()) {
+ if (account->getSSL()) {
err = mailimap_ssl_connect( m_imap, (char*)server, port );
@@ -79,3 +82,3 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
clistcell *current;
- mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate;
+// mailimap_fetch_att *fetchAtt,*fetchAttFlags,*fetchAttDate,*fetchAttSize;
mailimap_fetch_type *fetchType;
@@ -92,3 +95,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- logout();
return;
@@ -100,3 +102,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
qDebug("mailbox has no mails");
- logout();
return;
@@ -107,11 +108,7 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
set = mailimap_set_new_interval( 1, last );
- fetchAtt = mailimap_fetch_att_new_envelope();
- fetchAttFlags = mailimap_fetch_att_new_flags();
- fetchAttDate = mailimap_fetch_att_new_internaldate();
-
- //fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
fetchType = mailimap_fetch_type_new_fetch_att_list_empty();
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAtt);
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttFlags);
- mailimap_fetch_type_new_fetch_att_list_add(fetchType,fetchAttDate);
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_envelope());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_flags());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_internaldate());
+ mailimap_fetch_type_new_fetch_att_list_add(fetchType,mailimap_fetch_att_new_rfc822_size());
@@ -119,3 +116,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
mailimap_set_free( set );
- /* cleans up the fetch_att's too! */
mailimap_fetch_type_free( fetchType );
@@ -125,6 +121,6 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
if ( err == MAILIMAP_NO_ERROR ) {
- current = clist_begin(result);
+
mailimap_msg_att * msg_att;
int i = 0;
- while ( current != 0 ) {
+ for (current = clist_begin(result); current != 0; current=clist_next(current)) {
++i;
@@ -137,3 +133,2 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
}
- current = current->next;
}
@@ -142,4 +137,3 @@ void IMAPwrapper::listMessages(const QString&mailbox,QList<RecMail> &target )
}
- logout();
- clist_free(result);
+ mailimap_fetch_list_free(result);
}
@@ -221,2 +215,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
mailimap_flag_fetch*cflag;
+ int size;
QBitArray mFlags(7);
@@ -227,7 +222,6 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
-
- c = clist_begin(m_att->att_list);
- while ( c ) {
+ m = new RecMail();
+ for (c = clist_begin(m_att->att_list); c!=NULL;c=clist_next(c) ) {
current = c;
- c = c->next;
+ size = 0;
item = (mailimap_msg_att_item*)current->data;
@@ -239,3 +233,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
cf = flist->att_list->first;
- while (cf) {
+ for (cf = clist_begin(flist->att_list); cf!=NULL; cf = clist_next(cf)) {
cflag = (mailimap_flag_fetch*)cf->data;
@@ -268,3 +262,2 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
- cf = cf->next;
}
@@ -272,7 +265,4 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
}
- if ( item->att_data.att_static->att_type == MAILIMAP_MSG_ATT_RFC822_HEADER ) {
- qDebug( "header: \n%s", item->att_data.att_static->att_data.att_rfc822_header );
- } else if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
+ if (item->att_data.att_static->att_type==MAILIMAP_MSG_ATT_ENVELOPE) {
mailimap_envelope * head = item->att_data.att_static->att_data.att_env;
- m = new RecMail();
m->setDate(head->env_date);
@@ -309,4 +299,4 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
qDebug(da.toString());
- } else {
- qDebug("Another type");
+ } 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;
}
@@ -320,2 +310,3 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att)
m->setFlags(mFlags);
+ m->setMsgsize(size);
}
@@ -346,5 +337,5 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
qDebug("error selecting mailbox: %s",m_imap->imap_response);
- logout();
return body;
}
+
result = clist_new();
@@ -352,3 +343,3 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
set = mailimap_set_new_interval( mail.getNumber(),mail.getNumber() );
- fetchAtt = mailimap_fetch_att_new_body();
+ fetchAtt = mailimap_fetch_att_new_bodystructure();
fetchType = mailimap_fetch_type_new_fetch_att(fetchAtt);
@@ -365,5 +356,6 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
searchBodyText(mail,body_desc->bd_data.bd_body_1part,body);
- } else {
+ } else if (body_desc->bd_type==MAILIMAP_BODY_MPART) {
+ qDebug("Mulitpart mail");
+ searchBodyText(mail,body_desc->bd_data.bd_body_mpart,body,0);
}
-
} else {
@@ -371,5 +363,3 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
}
-
- clist_free(result);
- logout();
+ mailimap_fetch_list_free(result);
return body;
@@ -377,2 +367,5 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail)
+/* this routine is just called when the mail has only ONE part.
+ for filling the parts of a multi-part-message there are other
+ routines 'cause we can not simply fetch the whole body. */
void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body)
@@ -382,5 +375,16 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
}
+ QString sub;
switch (mailDescription->bd_type) {
+ case MAILIMAP_BODY_TYPE_1PART_MSG:
+ target_body.setType("text");
+ sub = mailDescription->bd_data.bd_type_text->bd_media_text;
+ target_body.setSubtype(sub.lower());
+ fillPlainBody(mail,target_body);
+ break;
case MAILIMAP_BODY_TYPE_1PART_TEXT:
- fillPlainBody(mail,target_body,mailDescription->bd_data.bd_type_text);
+ qDebug("Mediatype single: %s",mailDescription->bd_data.bd_type_text->bd_media_text);
+ target_body.setType("text");
+ sub = mailDescription->bd_data.bd_type_text->bd_media_text;
+ target_body.setSubtype(sub.lower());
+ fillPlainBody(mail,target_body);
break;
@@ -392,3 +396,3 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mai
-void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * bd)
+void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body)
{
@@ -428,6 +432,9 @@ void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap
char*text = msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part;
- int length = msg_att_item->att_data.att_static->att_data.att_body_section->sec_length;
msg_att_item->att_data.att_static->att_data.att_body_section->sec_body_part = 0L;
- body = QString(text);
- free(text);
+ if (text) {
+ body = QString(text);
+ free(text);
+ } else {
+ body = "";
+ }
}
@@ -439,3 +446,2 @@ void IMAPwrapper::fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap
}
- //clist_free(result);
mailimap_fetch_list_free(result);
@@ -455,5 +461,4 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
}
- current = clist_begin(list);
unsigned int count = 0;
- while (current!= NULL) {
+ for (current=clist_begin(list);current!= NULL;current=clist_next(current)) {
from = "";
@@ -461,3 +466,2 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
current_address=(mailimap_address*)current->data;
- current = current->next;
if (current_address->ad_personal_name){
@@ -487 +491,115 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list)
}
+
+void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion)
+{
+ /* current_recursion is for avoiding ugly mails which has a to deep body-structure */
+ if (!mailDescription||current_recursion==2) {
+ return;
+ }
+ qDebug("Mediatype: %s",mailDescription->bd_media_subtype);
+ clistcell*current;
+ mailimap_body*current_body;
+ for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) {
+ current_body = (mailimap_body*)current->data;
+ if (current_body->bd_type==MAILIMAP_BODY_MPART) {
+ searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1);
+ } else if (current_body->bd_type==MAILIMAP_BODY_1PART){
+ RecPart currentPart;
+ fillSinglePart(currentPart,current_body->bd_data.bd_body_1part);
+ target_body.addPart(currentPart);
+ }
+ }
+ if (current_recursion==0) {
+
+ }
+}
+
+void IMAPwrapper::fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description)
+{
+ if (!Description) {
+ return;
+ }
+ switch (Description->bd_type) {
+ case MAILIMAP_BODY_TYPE_1PART_TEXT:
+ target_part.setType("text");
+ fillSingleTextPart(target_part,Description->bd_data.bd_type_text);
+ break;
+ case MAILIMAP_BODY_TYPE_1PART_BASIC:
+ fillSingleBasicPart(target_part,Description->bd_data.bd_type_basic);
+ break;
+ default:
+ break;
+ }
+}
+
+void IMAPwrapper::fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which)
+{
+ if (!which) {
+ return;
+ }
+ QString sub;
+ sub = which->bd_media_text;
+ target_part.setSubtype(sub.lower());
+ target_part.setLines(which->bd_lines);
+ fillBodyFields(target_part,which->bd_fields);
+}
+
+void IMAPwrapper::fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which)
+{
+ if (!which) {
+ return;
+ }
+ QString type,sub;
+ switch (which->bd_media_basic->med_type) {
+ case MAILIMAP_MEDIA_BASIC_APPLICATION:
+ type = "application";
+ break;
+ case MAILIMAP_MEDIA_BASIC_AUDIO:
+ type = "audio";
+ break;
+ case MAILIMAP_MEDIA_BASIC_IMAGE:
+ type = "image";
+ break;
+ case MAILIMAP_MEDIA_BASIC_MESSAGE:
+ type = "message";
+ break;
+ case MAILIMAP_MEDIA_BASIC_VIDEO:
+ type = "video";
+ break;
+ case MAILIMAP_MEDIA_BASIC_OTHER:
+ default:
+ if (which->bd_media_basic->med_basic_type) {
+ type = which->bd_media_basic->med_basic_type;
+ } else {
+ type = "";
+ }
+ break;
+ }
+ if (which->bd_media_basic->med_subtype) {
+ sub = which->bd_media_basic->med_subtype;
+ } else {
+ sub = "";
+ }
+ qDebug("Type = %s/%s",type.latin1(),sub.latin1());
+ target_part.setType(type.lower());
+ target_part.setSubtype(sub.lower());
+ fillBodyFields(target_part,which->bd_fields);
+}
+
+void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which)
+{
+ if (!which) return;
+ if (which->bd_id) {
+ qDebug("Part ID = %s",which->bd_id);
+ target_part.setIdentifier(which->bd_id);
+ } else {
+ qDebug("ID empty");
+ target_part.setIdentifier("");
+ }
+
+ clistcell*cur;
+ mailimap_single_body_fld_param*param;
+ for (cur = clist_begin(which->bd_parameter->pa_list);cur!=NULL;cur=clist_next(cur)) {
+ param = (mailimap_single_body_fld_param*)cur->data;
+ }
+}
diff --git a/noncore/net/mail/libmailwrapper/imapwrapper.h b/noncore/net/mail/libmailwrapper/imapwrapper.h
index 90f3004..f809edb 100644
--- a/noncore/net/mail/libmailwrapper/imapwrapper.h
+++ b/noncore/net/mail/libmailwrapper/imapwrapper.h
@@ -9,2 +9,5 @@ struct mailimap_body_type_1part;
struct mailimap_body_type_text;
+struct mailimap_body_type_basic;
+struct mailimap_body_type_mpart;
+struct mailimap_body_fields;
struct mailimap_msg_att;
@@ -12,2 +15,3 @@ class RecMail;
class RecBody;
+class RecPart;
@@ -29,4 +33,13 @@ protected:
void logout();
+
void searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body);
- void fillPlainBody(const RecMail&mail,RecBody&target_body, mailimap_body_type_text * text_body);
+ void searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mailDescription,RecBody&target_body,int current_recursion);
+
+ void fillPlainBody(const RecMail&mail,RecBody&target_body);
+ void fillSinglePart(RecPart&target_part,mailimap_body_type_1part*Description);
+ void fillSingleTextPart(RecPart&target_part,mailimap_body_type_text*which);
+ void fillSingleBasicPart(RecPart&target_part,mailimap_body_type_basic*which);
+
+ /* just helpers */
+ static void fillBodyFields(RecPart&target_part,mailimap_body_fields*which);
static QStringList address_list_to_stringlist(clist*list);
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.cpp b/noncore/net/mail/libmailwrapper/mailtypes.cpp
index f9e5794..0e3174d 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.cpp
+++ b/noncore/net/mail/libmailwrapper/mailtypes.cpp
@@ -4,3 +4,3 @@
RecMail::RecMail()
- :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
+ :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
{
@@ -23,2 +23,3 @@ void RecMail::copy_old(const RecMail&old)
msg_id = old.msg_id;
+ msg_size = old.msg_size;
msg_number = old.msg_number;
@@ -69,3 +70,3 @@ const QStringList& RecMail::Bcc()const
RecPart::RecPart()
- : m_type(""),m_subtype(""),m_identifier(""),m_encoding("")
+ : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0)
{
@@ -73,4 +74,4 @@ RecPart::RecPart()
-RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding)
- : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding)
+RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding,unsigned int lines)
+ : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding),m_lines(lines)
{
@@ -82,2 +83,12 @@ RecPart::~RecPart()
+void RecPart::setLines(unsigned int lines)
+{
+ m_lines = lines;
+}
+
+const unsigned int RecPart::Lines()const
+{
+ return m_lines;
+}
+
const QString& RecPart::Type()const
@@ -158 +169,21 @@ void RecBody::addPart(const RecPart& part)
}
+
+void RecBody::setType(const QString&type)
+{
+ m_type = type;
+}
+
+const QString& RecBody::Type()const
+{
+ return m_type;
+}
+
+void RecBody::setSubtype(const QString&type)
+{
+ m_subtype = type;
+}
+
+const QString& RecBody::Subtype()const
+{
+ return m_subtype;
+}
diff --git a/noncore/net/mail/libmailwrapper/mailtypes.h b/noncore/net/mail/libmailwrapper/mailtypes.h
index 6d6b080..900f10a 100644
--- a/noncore/net/mail/libmailwrapper/mailtypes.h
+++ b/noncore/net/mail/libmailwrapper/mailtypes.h
@@ -48,2 +48,4 @@ public:
const QString&Replyto()const{return replyto;}
+ void setMsgsize(int size){msg_size = size;}
+ const int Msgsize()const{return msg_size;}
@@ -61,3 +63,3 @@ protected:
QString subject,date,from,mbox,msg_id,replyto;
- int msg_number;
+ int msg_number,msg_size;
QBitArray msg_flags;
@@ -72,5 +74,6 @@ protected:
QString m_type,m_subtype,m_identifier,m_encoding;
+ unsigned int m_lines;
public:
RecPart();
- RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
+ RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64",unsigned int lines=0);
virtual ~RecPart();
@@ -85,2 +88,4 @@ public:
void setEncoding(const QString&encoding);
+ void setLines(unsigned int lines);
+ const unsigned int Lines()const;
};
@@ -90,3 +95,3 @@ class RecBody
protected:
- QString m_BodyText;
+ QString m_BodyText,m_type,m_subtype;
QList<RecPart> m_PartsList;
@@ -98,2 +103,7 @@ public:
const QString& Bodytext()const;
+ void setType(const QString&);
+ const QString&Type()const;
+ void setSubtype(const QString&);
+ const QString&Subtype()const;
+
diff --git a/noncore/net/mail/mailtypes.cpp b/noncore/net/mail/mailtypes.cpp
index f9e5794..0e3174d 100644
--- a/noncore/net/mail/mailtypes.cpp
+++ b/noncore/net/mail/mailtypes.cpp
@@ -4,3 +4,3 @@
RecMail::RecMail()
- :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_flags(7)
+ :subject(""),date(""),from(""),mbox(""),msg_id(""),msg_number(0),msg_size(0),msg_flags(7)
{
@@ -23,2 +23,3 @@ void RecMail::copy_old(const RecMail&old)
msg_id = old.msg_id;
+ msg_size = old.msg_size;
msg_number = old.msg_number;
@@ -69,3 +70,3 @@ const QStringList& RecMail::Bcc()const
RecPart::RecPart()
- : m_type(""),m_subtype(""),m_identifier(""),m_encoding("")
+ : m_type(""),m_subtype(""),m_identifier(""),m_encoding(""),m_lines(0)
{
@@ -73,4 +74,4 @@ RecPart::RecPart()
-RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding)
- : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding)
+RecPart::RecPart(const QString&identifier,const QString&type,const QString&subtype,const QString&encoding,unsigned int lines)
+ : m_type(type),m_subtype(subtype),m_identifier(identifier),m_encoding(encoding),m_lines(lines)
{
@@ -82,2 +83,12 @@ RecPart::~RecPart()
+void RecPart::setLines(unsigned int lines)
+{
+ m_lines = lines;
+}
+
+const unsigned int RecPart::Lines()const
+{
+ return m_lines;
+}
+
const QString& RecPart::Type()const
@@ -158 +169,21 @@ void RecBody::addPart(const RecPart& part)
}
+
+void RecBody::setType(const QString&type)
+{
+ m_type = type;
+}
+
+const QString& RecBody::Type()const
+{
+ return m_type;
+}
+
+void RecBody::setSubtype(const QString&type)
+{
+ m_subtype = type;
+}
+
+const QString& RecBody::Subtype()const
+{
+ return m_subtype;
+}
diff --git a/noncore/net/mail/mailtypes.h b/noncore/net/mail/mailtypes.h
index 6d6b080..900f10a 100644
--- a/noncore/net/mail/mailtypes.h
+++ b/noncore/net/mail/mailtypes.h
@@ -48,2 +48,4 @@ public:
const QString&Replyto()const{return replyto;}
+ void setMsgsize(int size){msg_size = size;}
+ const int Msgsize()const{return msg_size;}
@@ -61,3 +63,3 @@ protected:
QString subject,date,from,mbox,msg_id,replyto;
- int msg_number;
+ int msg_number,msg_size;
QBitArray msg_flags;
@@ -72,5 +74,6 @@ protected:
QString m_type,m_subtype,m_identifier,m_encoding;
+ unsigned int m_lines;
public:
RecPart();
- RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64");
+ RecPart(const QString&identifier,const QString&type="",const QString&subtype="",const QString&encoding="BASE64",unsigned int lines=0);
virtual ~RecPart();
@@ -85,2 +88,4 @@ public:
void setEncoding(const QString&encoding);
+ void setLines(unsigned int lines);
+ const unsigned int Lines()const;
};
@@ -90,3 +95,3 @@ class RecBody
protected:
- QString m_BodyText;
+ QString m_BodyText,m_type,m_subtype;
QList<RecPart> m_PartsList;
@@ -98,2 +103,7 @@ public:
const QString& Bodytext()const;
+ void setType(const QString&);
+ const QString&Type()const;
+ void setSubtype(const QString&);
+ const QString&Subtype()const;
+