author | alwin <alwin> | 2003-12-16 13:14:05 (UTC) |
---|---|---|
committer | alwin <alwin> | 2003-12-16 13:14:05 (UTC) |
commit | 49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838 (patch) (side-by-side diff) | |
tree | 710393582789ed1db97592fed5bb88ad4d56550d /noncore/net/mail/imapwrapper.cpp | |
parent | f42c15f884d4377bc99d73e16fa1722b0fb2a4d3 (diff) | |
download | opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.zip opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.gz opie-49c02bbbb7a0aeee933d58ba1d3d3e86e6bc7838.tar.bz2 |
saving of attachments implemented.
Diffstat (limited to 'noncore/net/mail/imapwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/imapwrapper.cpp | 78 |
1 files changed, 46 insertions, 32 deletions
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); +} |