text
stringlengths
0
357
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
if (mailmime_get_mime_type(childmime, NULL, NULL)==DC_MIMETYPE_TEXT_PLAIN) {
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
break;
}
}
}
if (!any_part_added) { /* `text/plain` not found - use the first part */
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
if (dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(cur))) {
any_part_added = 1;
break; /* out of for() */
}
}
}
break;
case DC_MIMETYPE_MP_RELATED: /* add the "root part" - the other parts may be referenced which is not interesting for us (eg. embedded images) */
/* we assume he "root part" being the first one, which may not be always true ... however, most times it seems okay. */
cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list);
if (cur) {
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(cur));
}
break;
case DC_MIMETYPE_MP_NOT_DECRYPTABLE:
{
dc_mimepart_t* part = dc_mimepart_new();
part->type = DC_MSG_TEXT;
char* msg_body = dc_stock_str(mimeparser->context, DC_STR_CANTDECRYPT_MSG_BODY);
part->msg = dc_mprintf(DC_EDITORIAL_OPEN "%s" DC_EDITORIAL_CLOSE, msg_body);
part->msg_raw = dc_strdup(part->msg);
free(msg_body);
carray_add(mimeparser->parts, (void*)part, NULL);
any_part_added = 1;
mimeparser->decrypting_failed = 1;
}
break;
case DC_MIMETYPE_MP_SIGNED:
/* RFC 1847: "The multipart/signed content type contains exactly two body parts.
The first body part is the body part over which the digital signature was created [...]
The second body part contains the control information necessary to verify the digital signature."
We simpliy take the first body part and skip the rest.
(see https://k9mail.github.io/2016/11/24/OpenPGP-Considerations-Part-I.html for background information why we use encrypted+signed) */
if ((cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list))!=NULL)
{
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(cur));
}
break;
case DC_MIMETYPE_MP_REPORT:
if (clist_count(mime->mm_data.mm_multipart.mm_mp_list) >= 2) /* RFC 6522: the first part is for humans, the second for machines */
{
struct mailmime_parameter* report_type = mailmime_find_ct_parameter(mime, "report-type");
if (report_type && report_type->pa_value
&& strcmp(report_type->pa_value, "disposition-notification")==0)
{
carray_add(mimeparser->reports, (void*)mime, NULL);
}
else
{
/* eg. `report-type=delivery-status`; maybe we should show them as a little error icon */
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, (struct mailmime*)clist_content(clist_begin(mime->mm_data.mm_multipart.mm_mp_list)));
}
}
break;
default: /* eg. DC_MIMETYPE_MP_MIXED - add all parts (in fact, AddSinglePartIfKnown() later check if the parts are really supported) */
{
/* HACK: the following lines are a hack for clients who use multipart/mixed instead of multipart/alternative for
combined text/html messages (eg. Stock Android "Mail" does so). So, if I detect such a message below, I skip the HTML part.
However, I'm not sure, if there are useful situations to use plain+html in multipart/mixed - if so, we should disable the hack. */
struct mailmime* skip_part = NULL;
{
struct mailmime* html_part = NULL;
int plain_cnt = 0, html_cnt = 0;
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
struct mailmime* childmime = (struct mailmime*)clist_content(cur);
if (mailmime_get_mime_type(childmime, NULL, NULL)==DC_MIMETYPE_TEXT_PLAIN) {
plain_cnt++;
}
else if (mailmime_get_mime_type(childmime, NULL, NULL)==DC_MIMETYPE_TEXT_HTML) {
html_part = childmime;
html_cnt++;
}
}
if (plain_cnt==1 && html_cnt==1) {
dc_log_warning(mimeparser->context, 0, "HACK: multipart/mixed message found with PLAIN and HTML, we'll skip the HTML part as this seems to be unwanted.");
skip_part = html_part;
}
}
/* /HACK */
for (cur=clist_begin(mime->mm_data.mm_multipart.mm_mp_list); cur!=NULL; cur=clist_next(cur)) {
struct mailmime* childmime = (struct mailmime*)clist_content(cur);