Diffstat (limited to 'noncore/net/mail/libmailwrapper/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/libmailwrapper/imapwrapper.cpp | 78 |
1 files changed, 46 insertions, 32 deletions
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 @@ -293,26 +293,27 @@ RecMail*IMAPwrapper::parse_list_result(mailimap_msg_att* m_att) if (head->env_bcc!=NULL) { addresslist = address_list_to_stringlist(head->env_bcc->bcc_list); m->setBcc(addresslist); } if (head->env_reply_to!=NULL) { addresslist = address_list_to_stringlist(head->env_reply_to->rt_list); 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; } } /* msg is already deleted */ if (mFlags.testBit(FLAG_DELETED) && m) { delete m; m = 0; @@ -382,38 +383,32 @@ RecBody IMAPwrapper::fetchBody(const RecMail&mail) void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_1part*mailDescription,RecBody&target_body) { if (!mailDescription) { return; } QString sub,body_text; 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(""); target_body.addPart(singlePart); break; default: break; } @@ -452,43 +447,43 @@ QStringList IMAPwrapper::address_list_to_stringlist(clist*list) } if (named_from && (current_address->ad_mailbox_name || current_address->ad_host_name)) { from+=">"; } l.append(QString(from)); if (++count > 99) { 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)); *p_id = path[j]; clist_append(id_list,p_id); } mailimap_section_part * section_part = mailimap_section_part_new(id_list); mailimap_section_spec * section_spec = mailimap_section_spec_new(MAILIMAP_SECTION_SPEC_SECTION_PART, NULL, section_part, NULL); mailimap_section * section = mailimap_section_new(section_spec); @@ -502,44 +497,35 @@ QString IMAPwrapper::fetchPart(const RecMail&mail,const QValueList<int>&path,boo 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; - 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) { return; } clistcell*current; mailimap_body*current_body; unsigned int count = 0; for (current=clist_begin(mailDescription->bd_list);current!=0;current=clist_next(current)) { @@ -548,25 +534,25 @@ void IMAPwrapper::searchBodyText(const RecMail&mail,mailimap_body_type_mpart*mai current_body = (mailimap_body*)current->data; if (current_body->bd_type==MAILIMAP_BODY_MPART) { QValueList<int>clist = recList; clist.append(count); searchBodyText(mail,current_body->bd_data.bd_body_mpart,target_body,current_recursion+1,clist); } else if (current_body->bd_type==MAILIMAP_BODY_1PART){ 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?" ":""); id+=QString("%1").arg(clist[j]); } qDebug("ID= %s",id.latin1()); currentPart.setIdentifier(id); currentPart.setPositionlist(clist); target_body.addPart(currentPart); @@ -704,29 +690,24 @@ void IMAPwrapper::fillBodyFields(RecPart&target_part,mailimap_body_fields*which) encoding=QString(enc->enc_value); enc->enc_value=0L; free(t); } } if (which->bd_description) { 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; login(); if (!m_imap) { return; } const char *mb = mail.getMbox().latin1(); err = mailimap_select( m_imap, (char*)mb); @@ -775,12 +756,45 @@ void IMAPwrapper::answeredMail(const RecMail&mail) mailimap_flag_list_add(flist,mailimap_flag_new_answered()); store_flags = mailimap_store_att_flags_new_add_flags(flist); set = mailimap_set_new_single(mail.getNumber()); err = mailimap_store(m_imap,set,store_flags); mailimap_set_free( set ); mailimap_store_att_flags_free(store_flags); 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); +} |