summaryrefslogtreecommitdiffabout
path: root/kmicromail/libmailwrapper/imapwrapper.cpp
Side-by-side diff
Diffstat (limited to 'kmicromail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/libmailwrapper/imapwrapper.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/kmicromail/libmailwrapper/imapwrapper.cpp b/kmicromail/libmailwrapper/imapwrapper.cpp
index 110583f..ae667ec 100644
--- a/kmicromail/libmailwrapper/imapwrapper.cpp
+++ b/kmicromail/libmailwrapper/imapwrapper.cpp
@@ -658,192 +658,193 @@ encodedString*IMAPwrapper::fetchRawPart(const RecMailP&mail,const QValueList<int
int err;
mailimap_fetch_type *fetchType;
mailimap_set *set;
clistcell*current,*cur;
mailimap_section_part * section_part = 0;
mailimap_section_spec * section_spec = 0;
mailimap_section * section = 0;
mailimap_fetch_att * fetch_att = 0;
login();
if (!m_imap) {
return res;
}
if (!internal_call) {
err = selectMbox(mail->getMbox());
if ( err != MAILIMAP_NO_ERROR ) {
return res;
}
}
set = mailimap_set_new_single(mail->getNumber());
clist*id_list = 0;
/* if path == empty then its a request for the whole rfc822 mail and generates
a "fetch <id> (body[])" statement on imap server */
if (path.count()>0 ) {
id_list = clist_new();
for (unsigned j=0; j < path.count();++j) {
uint32_t * p_id = (uint32_t *)malloc(sizeof(*p_id));
*p_id = path[j];
clist_append(id_list,p_id);
}
section_part = mailimap_section_part_new(id_list);
section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL);
}
section = mailimap_section_new(section_spec);
fetch_att = mailimap_fetch_att_new_body_section(section);
fetchType = mailimap_fetch_type_new_fetch_att(fetch_att);
clist*result = 0;
err = mailimap_fetch( m_imap, set, fetchType, &result );
mailimap_set_free( set );
mailimap_fetch_type_free( fetchType );
if (err == MAILIMAP_NO_ERROR && (current=clist_begin(result)) ) {
mailimap_msg_att * msg_att;
msg_att = (mailimap_msg_att*)current->data;
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;
res->setContent(text,msg_att_item->att_data.att_static->att_data.att_body_section->sec_length);
}
}
}
} else {
;//odebug << "error fetching text: " << m_imap->imap_response << "" << oendl;
}
if (result) mailimap_fetch_list_free(result);
return res;
}
/* current_recursion is for recursive calls.
current_count means the position inside the internal loop! */
void IMAPwrapper::traverseBody(const RecMailP&mail,mailimap_body*body,RecBodyP&target_body,
int current_recursion,QValueList<int>recList,int current_count)
{
if (!body || current_recursion>=10) {
return;
}
switch (body->bd_type) {
case MAILIMAP_BODY_1PART:
{
QValueList<int>countlist = recList;
countlist.append(current_count);
RecPartP currentPart = new RecPart();
mailimap_body_type_1part*part1 = body->bd_data.bd_body_1part;
QString id("");
currentPart->setPositionlist(countlist);
for (unsigned int j = 0; j < countlist.count();++j) {
id+=(j>0?" ":"");
id+=QString("%1").arg(countlist[j]);
}
//odebug << "ID = " << id.latin1() << "" << oendl;
currentPart->setIdentifier(id);
fillSinglePart(currentPart,part1);
/* important: Check for is NULL 'cause a body can be empty!
And we put it only into the mail if it is the FIRST part */
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_TEXT && target_body->Bodytext().isNull() && countlist[0]==1) {
QString body_text = fetchTextPart(mail,countlist,true,currentPart->Encoding());
+ //qDebug("encoding %d text %s ",currentPart->Encoding().latin1(), body_text.latin1() );
target_body->setDescription(currentPart);
target_body->setBodytext(body_text);
if (countlist.count()>1) {
target_body->addPart(currentPart);
}
} else {
target_body->addPart(currentPart);
}
if (part1->bd_type==MAILIMAP_BODY_TYPE_1PART_MSG) {
traverseBody(mail,part1->bd_data.bd_type_msg->bd_body,target_body,current_recursion+1,countlist);
}
}
break;
case MAILIMAP_BODY_MPART:
{
QValueList<int>countlist = recList;
clistcell*current=0;
mailimap_body*current_body=0;
unsigned int ccount = 1;
mailimap_body_type_mpart*mailDescription = body->bd_data.bd_body_mpart;
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) {
RecPartP targetPart = new RecPart();
targetPart->setType("multipart");
fillMultiPart(targetPart,mailDescription);
countlist.append(current_count);
targetPart->setPositionlist(countlist);
target_body->addPart(targetPart);
QString id("");
for (unsigned int j = 0; j < countlist.count();++j) {
id+=(j>0?" ":"");
id+=QString("%1").arg(countlist[j]);
}
// odebug << "ID(mpart) = " << id.latin1() << "" << oendl;
}
traverseBody(mail,current_body,target_body,current_recursion+1,countlist,ccount);
if (current_body->bd_type==MAILIMAP_BODY_MPART) {
countlist = recList;
}
++ccount;
}
}
break;
default:
break;
}
}
void IMAPwrapper::fillSinglePart(RecPartP&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;
case MAILIMAP_BODY_TYPE_1PART_MSG:
target_part->setType("message");
fillSingleMsgPart(target_part,Description->bd_data.bd_type_msg);
break;
default:
break;
}
}
void IMAPwrapper::fillSingleTextPart(RecPartP&target_part,mailimap_body_type_text*which)
{
if (!which) {
return;
}
QString sub;
sub = which->bd_media_text;
//odebug << "Type= text/" << which->bd_media_text << "" << oendl;
target_part->setSubtype(sub.lower());
target_part->setLines(which->bd_lines);
fillBodyFields(target_part,which->bd_fields);
}
void IMAPwrapper::fillSingleMsgPart(RecPartP&target_part,mailimap_body_type_msg*which)
{
if (!which) {
return;
}
target_part->setSubtype("rfc822");
//odebug << "Message part" << oendl;
/* we set this type to text/plain */
target_part->setLines(which->bd_lines);
fillBodyFields(target_part,which->bd_fields);
}