Skip to content

Commit 549ad3b

Browse files
committed
oxcmail: split FIND_RTF off oxcmail_load_mime_skeleton
1 parent be01513 commit 549ad3b

File tree

1 file changed

+44
-37
lines changed

1 file changed

+44
-37
lines changed

lib/mapi/oxcmail.cpp

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,9 +3053,44 @@ static bool skel_use_rtf(const MESSAGE_CONTENT &msg)
30533053
return flag == nullptr || *flag == 0;
30543054
}
30553055

3056+
static bool skel_find_rtf(mime_skeleton &skel, const message_content &msg,
3057+
const char *charset) try
3058+
{
3059+
auto rtf = msg.proplist.get<const BINARY>(PR_RTF_COMPRESSED);
3060+
if (rtf == nullptr)
3061+
return true;
3062+
ssize_t unc_size = rtfcp_uncompressed_size(rtf);
3063+
std::string buf;
3064+
if (unc_size >= 0)
3065+
buf.resize(unc_size);
3066+
size_t rtf_len = unc_size;
3067+
if (unc_size < 0 || !rtfcp_uncompress(rtf, buf.data(), &rtf_len)) {
3068+
skel.mail_type = oxcmail_type::tnef;
3069+
return true;
3070+
}
3071+
buf.resize(rtf_len);
3072+
skel.pattachments = attachment_list_init();
3073+
if (skel.pattachments == nullptr)
3074+
return false;
3075+
if (!rtf_to_html(buf.data(), buf.size(), charset,
3076+
skel.rtf, skel.pattachments)) {
3077+
skel.mail_type = oxcmail_type::tnef;
3078+
return true;
3079+
}
3080+
skel.rtf_bin.pv = skel.rtf.data();
3081+
skel.rtf_bin.cb = skel.rtf.size();
3082+
skel.phtml = &skel.rtf_bin;
3083+
if (skel.pattachments->count > 0)
3084+
skel.b_inline = TRUE;
3085+
return true;
3086+
} catch (const std::bad_alloc &) {
3087+
mlog(LV_ERR, "E-2263: ENOMEM");
3088+
return false;
3089+
}
3090+
30563091
static BOOL oxcmail_load_mime_skeleton(const MESSAGE_CONTENT *pmsg,
30573092
const char *pcharset, BOOL b_tnef, enum oxcmail_body body_type,
3058-
MIME_SKELETON *pskeleton) try
3093+
MIME_SKELETON *pskeleton)
30593094
{
30603095
pskeleton->clear();
30613096
pskeleton->charset = pcharset;
@@ -3081,39 +3116,14 @@ static BOOL oxcmail_load_mime_skeleton(const MESSAGE_CONTENT *pmsg,
30813116
pskeleton->mail_type == oxcmail_type::tnef) {
30823117
/* do nothing */
30833118
} else if (skel_use_rtf(*pmsg)) {
3084-
FIND_RTF:
3085-
auto prtf = pmsg->proplist.get<const BINARY>(PR_RTF_COMPRESSED);
3086-
if (NULL != prtf) {
3087-
ssize_t unc_size = rtfcp_uncompressed_size(prtf);
3088-
std::string pbuff;
3089-
if (unc_size >= 0)
3090-
pbuff.resize(unc_size);
3091-
size_t rtf_len = unc_size;
3092-
if (unc_size >= 0 && rtfcp_uncompress(prtf, pbuff.data(), &rtf_len)) {
3093-
pbuff.resize(rtf_len);
3094-
pskeleton->pattachments = attachment_list_init();
3095-
if (pskeleton->pattachments == nullptr)
3096-
return FALSE;
3097-
if (rtf_to_html(pbuff.data(), pbuff.size(),
3098-
pcharset, pskeleton->rtf,
3099-
pskeleton->pattachments)) {
3100-
pskeleton->rtf_bin.pv = pskeleton->rtf.data();
3101-
pskeleton->rtf_bin.cb = pskeleton->rtf.size();
3102-
pskeleton->phtml = &pskeleton->rtf_bin;
3103-
if (pskeleton->pattachments->count > 0)
3104-
pskeleton->b_inline = TRUE;
3105-
} else {
3106-
pskeleton->mail_type = oxcmail_type::tnef;
3107-
}
3108-
} else {
3109-
pskeleton->mail_type = oxcmail_type::tnef;
3110-
}
3111-
}
3112-
} else {
3113-
pskeleton->phtml = pmsg->proplist.get<BINARY>(PR_HTML);
3114-
if (pskeleton->phtml == nullptr)
3115-
goto FIND_RTF;
3116-
}
3119+
if (!skel_find_rtf(*pskeleton, *pmsg, pcharset))
3120+
return false;
3121+
} else {
3122+
pskeleton->phtml = pmsg->proplist.get<BINARY>(PR_HTML);
3123+
if (pskeleton->phtml == nullptr &&
3124+
!skel_find_rtf(*pskeleton, *pmsg, pcharset))
3125+
return false;
3126+
}
31173127
if (pmsg->children.pattachments == nullptr)
31183128
return TRUE;
31193129
for (auto &attachment : *pmsg->children.pattachments) {
@@ -3133,9 +3143,6 @@ static BOOL oxcmail_load_mime_skeleton(const MESSAGE_CONTENT *pmsg,
31333143
pskeleton->b_attachment = TRUE;
31343144
}
31353145
return TRUE;
3136-
} catch (const std::bad_alloc &) {
3137-
mlog(LV_ERR, "E-2263: ENOMEM");
3138-
return false;
31393146
}
31403147

31413148
void mime_skeleton::clear()

0 commit comments

Comments
 (0)