author | zautrix <zautrix> | 2005-03-31 23:55:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-31 23:55:51 (UTC) |
commit | b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c (patch) (side-by-side diff) | |
tree | b0b3d0eb7a3d29981c183275aadeed0cbbef0007 /kmicromail/libmailwrapper/genericwrapper.cpp | |
parent | c0fa26aa3b33c293853bdd7d028ddb0545e33c85 (diff) | |
download | kdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.zip kdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.tar.gz kdepimpi-b76ad1e7e329051a47e28c9d132ce3fcd0b25c5c.tar.bz2 |
fixes
Diffstat (limited to 'kmicromail/libmailwrapper/genericwrapper.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kmicromail/libmailwrapper/genericwrapper.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/kmicromail/libmailwrapper/genericwrapper.cpp b/kmicromail/libmailwrapper/genericwrapper.cpp index 1ed9f34..0b6adf7 100644 --- a/kmicromail/libmailwrapper/genericwrapper.cpp +++ b/kmicromail/libmailwrapper/genericwrapper.cpp @@ -267,282 +267,283 @@ void Genericwrapper::traverseBody(RecBodyP&target,mailmessage*message,mailmime*m ++ccount; } } break; case MAILMIME_MESSAGE: { QValueList<int>countlist = recList; countlist.append(current_count); /* the own header is always at recursion 0 - we don't need that */ if (current_rec > 0) { part->setPositionlist(countlist); r = mailmessage_fetch_section(message,mime,&data,&len); part->setSize(len); part->setPositionlist(countlist); b = gen_attachment_id(); part->setIdentifier(b); part->setType("message"); part->setSubtype("rfc822"); bodyCache[b]=new encodedString(data,len); target->addPart(part); } if (mime->mm_data.mm_message.mm_msg_mime != NULL) { traverseBody(target,message,mime->mm_data.mm_message.mm_msg_mime,countlist,current_rec+1); } } break; } } RecBodyP Genericwrapper::parseMail( mailmessage * msg ) { int err = MAILIMF_NO_ERROR; //mailmime_single_fields fields; /* is bound to msg and will be freed there */ mailmime * mime=0; RecBodyP body = new RecBody(); //memset(&fields, 0, sizeof(struct mailmime_single_fields)); err = mailmessage_get_bodystructure(msg,&mime); QValueList<int>recList; traverseBody(body,msg,mime,recList); return body; } QString Genericwrapper::parseAddressList( mailimf_address_list *list ) { QString result( "" ); bool first = true; if (list == 0) return result; for ( clistiter *current = clist_begin( list->ad_list ); current != NULL; current = current->next ) { mailimf_address *addr = (mailimf_address *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } switch ( addr->ad_type ) { case MAILIMF_ADDRESS_MAILBOX: result.append( parseMailbox( addr->ad_data.ad_mailbox ) ); break; case MAILIMF_ADDRESS_GROUP: result.append( parseGroup( addr->ad_data.ad_group ) ); break; default: ; // odebug << "Generic: unkown mailimf address type" << oendl; break; } } return result; } QString Genericwrapper::parseGroup( mailimf_group *group ) { QString result( "" ); result.append( group->grp_display_name ); result.append( ": " ); if ( group->grp_mb_list != NULL ) { result.append( parseMailboxList( group->grp_mb_list ) ); } result.append( ";" ); return result; } QString Genericwrapper::parseMailbox( mailimf_mailbox *box ) { QString result( "" ); if ( box->mb_display_name == NULL ) { - result.append( box->mb_addr_spec ); + result.append( convert_String(box->mb_addr_spec) ); } else { result.append( convert_String(box->mb_display_name) ); result.append( " <" ); - result.append( box->mb_addr_spec ); + result.append( convert_String( box->mb_addr_spec) ); result.append( ">" ); } return result; } QString Genericwrapper::parseMailboxList( mailimf_mailbox_list *list ) { QString result( "" ); bool first = true; for ( clistiter *current = clist_begin( list->mb_list ); current != NULL; current = current->next ) { mailimf_mailbox *box = (mailimf_mailbox *) current->data; if ( !first ) { result.append( "," ); } else { first = false; } result.append( parseMailbox( box ) ); } return result; } encodedString* Genericwrapper::fetchDecodedPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = decode_String(it.data(),part->Encoding()); return t; } encodedString* Genericwrapper::fetchRawPart(const RecMailP&,const RecPartP&part) { QMap<QString,encodedString*>::ConstIterator it = bodyCache.find(part->Identifier()); if (it==bodyCache.end()) return new encodedString(); encodedString*t = it.data(); return t; } QString Genericwrapper::fetchTextPart(const RecMailP&mail,const RecPartP&part) { encodedString*t = fetchDecodedPart(mail,part); QString text=t->Content(); delete t; return text; } void Genericwrapper::cleanMimeCache() { QMap<QString,encodedString*>::Iterator it = bodyCache.begin(); for (;it!=bodyCache.end();++it) { encodedString*t = it.data(); //it.setValue(0); if (t) delete t; } bodyCache.clear(); ; // odebug << "Genericwrapper: cache cleaned" << oendl; } QStringList Genericwrapper::parseInreplies(mailimf_in_reply_to * in_replies) { QStringList res; if (!in_replies || !in_replies->mid_list) return res; clistiter * current = 0; for ( current = clist_begin( in_replies->mid_list ); current != NULL; current = current->next ) { QString h((char*)current->data); while (h.length()>0 && h[0]=='<') { h.remove(0,1); } while (h.length()>0 && h[h.length()-1]=='>') { h.remove(h.length()-1,1); } if (h.length()>0) { res.append(h); } } return res; } void Genericwrapper::parseList(QValueList<Opie::Core::OSmartPointer<RecMail> > &target,mailsession*session,const QString&mailbox,bool mbox_as_to, int maxSizeInKb) { int r; mailmessage_list * env_list = 0; r = mailsession_get_messages_list(session,&env_list); if (r != MAIL_NO_ERROR) { ; // odebug << "Error message list" << oendl; return; } r = mailsession_get_envelopes_list(session, env_list); if (r != MAIL_NO_ERROR) { ; // odebug << "Error filling message list" << oendl; if (env_list) { mailmessage_list_free(env_list); } return; } mailimf_references * refs = 0; mailimf_in_reply_to * in_replies = 0; uint32_t i = 0; for(; i < carray_count(env_list->msg_tab) ; ++i) { mailmessage * msg; QBitArray mFlags(7); msg = (mailmessage*)carray_get(env_list->msg_tab, i); if (msg->msg_fields == NULL) { //; // odebug << "could not fetch envelope of message " << i << "" << oendl; continue; } RecMailP mail = new RecMail(); mail->setWrapper(this); mail_flags * flag_result = 0; r = mailmessage_get_flags(msg,&flag_result); if (r == MAIL_ERROR_NOT_IMPLEMENTED) { mFlags.setBit(FLAG_SEEN); } mailimf_single_fields single_fields; mailimf_single_fields_init(&single_fields, msg->msg_fields); mail->setMsgsize(msg->msg_size); mail->setFlags(mFlags); mail->setMbox(mailbox); mail->setNumber(msg->msg_index); if (single_fields.fld_subject) mail->setSubject( convert_String(single_fields.fld_subject->sbj_value)); - if (single_fields.fld_from) + if (single_fields.fld_from) { mail->setFrom(parseMailboxList(single_fields.fld_from->frm_mb_list)); + } if (!mbox_as_to) { if (single_fields.fld_to) mail->setTo( parseAddressList( single_fields.fld_to->to_addr_list ) ); } else { mail->setTo(mailbox); } if (single_fields.fld_cc) mail->setCC( parseAddressList( single_fields.fld_cc->cc_addr_list ) ); if (single_fields.fld_bcc) mail->setBcc( parseAddressList( single_fields.fld_bcc->bcc_addr_list ) ); if (single_fields.fld_orig_date) { QDateTime dt = Genericwrapper::parseDateTime( single_fields.fld_orig_date->dt_date_time ); QString ret; if ( dt.date() == QDate::currentDate () ) ret = KGlobal::locale()->formatTime( dt.time(),true); else { ret = KGlobal::locale()->formatDateTime( dt,true,true); } mail->setDate( ret ); char tmp[20]; snprintf( tmp, 20, "%04i-%02i-%02i %02i:%02i:%02i", dt.date().year(),dt.date().month(), dt.date().day(), dt.time().hour(), dt.time().minute(), dt.time().second() ); //qDebug(" iso %s ", tmp); mail->setIsoDate( QString( tmp ) ); } // crashes when accessing pop3 account? if (single_fields.fld_message_id) { mail->setMsgid(QString(single_fields.fld_message_id->mid_value)); ; // odebug << "Msgid == " << mail->Msgid().latin1() << "" << oendl; } if (single_fields.fld_reply_to) { QStringList t = parseAddressList(single_fields.fld_reply_to->rt_addr_list); if (t.count()>0) { mail->setReplyto(t[0]); } } #if 0 refs = single_fields.fld_references; if (refs && refs->mid_list && clist_count(refs->mid_list)) { char * text = (char*)refs->mid_list->first->data; mail->setReplyto(QString(text)); } #endif if (single_fields.fld_in_reply_to && single_fields.fld_in_reply_to->mid_list && clist_count(single_fields.fld_in_reply_to->mid_list)) { mail->setInreply(parseInreplies(single_fields.fld_in_reply_to)); } if ( maxSizeInKb == 0 || mail->Msgsize()<=maxSizeInKb*1024 ) target.append(mail); } if (env_list) { mailmessage_list_free(env_list); } } |