text
stringlengths
0
357
goto cleanup;
}
}
if (strncmp(desired_filename, "location", 8)==0
&& strncmp(desired_filename+strlen(desired_filename)-4, ".kml", 4)==0) {
mimeparser->location_kml = dc_kml_parse(mimeparser->context,
decoded_data, decoded_data_bytes);
goto cleanup;
}
if (strncmp(desired_filename, "message", 7)==0
&& strncmp(desired_filename+strlen(desired_filename)-4, ".kml", 4)==0) {
mimeparser->message_kml = dc_kml_parse(mimeparser->context,
decoded_data, decoded_data_bytes);
goto cleanup;
}
dc_replace_bad_utf8_chars(desired_filename);
do_add_single_file_part(mimeparser, msg_type, mime_type, raw_mime, decoded_data, decoded_data_bytes, desired_filename);
}
break;
default:
break;
}
/* add object? (we do not add all objetcs, eg. signatures etc. are ignored) */
cleanup:
dc_simplify_unref(simplifier);
if (charset_buffer) { charconv_buffer_free(charset_buffer); }
if (transfer_decoding_buffer) { mmap_string_unref(transfer_decoding_buffer); }
free(file_suffix);
free(desired_filename);
dc_mimepart_unref(part);
free(raw_mime);
return carray_count(mimeparser->parts)>old_part_count? 1 : 0; /* any part added? */
}
static int dc_mimeparser_parse_mime_recursive(dc_mimeparser_t* mimeparser, struct mailmime* mime)
{
int any_part_added = 0;
clistiter* cur = NULL;
if (mimeparser==NULL || mime==NULL) {
return 0;
}
if (mailmime_find_ct_parameter(mime, "protected-headers"))
{
if (mime->mm_type==MAILMIME_SINGLE
&& mime->mm_content_type->ct_type->tp_type==MAILMIME_TYPE_DISCRETE_TYPE
&& mime->mm_content_type->ct_type->tp_data.tp_discrete_type->dt_type==MAILMIME_DISCRETE_TYPE_TEXT
&& mime->mm_content_type->ct_subtype
&& strcmp(mime->mm_content_type->ct_subtype, "rfc822-headers")==0) {
dc_log_info(mimeparser->context, 0, "Protected headers found in text/rfc822-headers attachment: Will be ignored."); /* we want the protected headers in the normal header of the payload */
return 0;
}
if (mimeparser->header_protected==NULL) { /* use the most outer protected header - this is typically created in sync with the normal, unprotected header */
size_t dummy = 0;
if (mailimf_envelope_and_optional_fields_parse(mime->mm_mime_start, mime->mm_length, &dummy, &mimeparser->header_protected)!=MAILIMF_NO_ERROR
|| mimeparser->header_protected==NULL) {
dc_log_warning(mimeparser->context, 0, "Protected headers parsing error.");
}
else {
hash_header(&mimeparser->header, mimeparser->header_protected, mimeparser->context);
}
}
else {
dc_log_info(mimeparser->context, 0, "Protected headers found in MIME header: Will be ignored as we already found an outer one.");
}
}
switch (mime->mm_type)
{
case MAILMIME_SINGLE:
any_part_added = dc_mimeparser_add_single_part_if_known(mimeparser, mime);
break;
case MAILMIME_MULTIPLE:
switch (mailmime_get_mime_type(mime, NULL, NULL))
{
case DC_MIMETYPE_MP_ALTERNATIVE: /* add "best" part */
/* Most times, mutlipart/alternative contains true alternatives as text/plain and text/html.
If we find a multipart/mixed inside mutlipart/alternative, we use this (happens eg in apple mail: "plaintext" as an alternative to "html+PDF attachment") */
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_MP_MIXED) {
any_part_added = dc_mimeparser_parse_mime_recursive(mimeparser, childmime);
break;
}
}
if (!any_part_added) {
/* search for text/plain and add this */