text stringlengths 0 357 |
|---|
* body_not_terminated is null-terminated, use strlen(body_not_terminated) here. |
* @return None. |
*/ |
void dc_mimeparser_parse(dc_mimeparser_t* mimeparser, const char* body_not_terminated, size_t body_bytes) |
{ |
int r = 0; |
size_t index = 0; |
struct mailimf_optional_field* optional_field = NULL; |
dc_mimeparser_empty(mimeparser); |
/* parse body */ |
r = mailmime_parse(body_not_terminated, body_bytes, &index, &mimeparser->mimeroot); |
if(r!=MAILIMF_NO_ERROR || mimeparser->mimeroot==NULL) { |
goto cleanup; |
} |
//printf("before decryption:\n"); mailmime_print(mimeparser->mimeroot); |
/* decrypt, if possible; handle Autocrypt:-header |
(decryption may modifiy the given object) */ |
dc_e2ee_decrypt(mimeparser->context, mimeparser->mimeroot, mimeparser->e2ee_helper); |
//printf("after decryption:\n"); mailmime_print(mimeparser->mimeroot); |
/* recursively check, whats parsed, this also sets up header_old */ |
dc_mimeparser_parse_mime_recursive(mimeparser, mimeparser->mimeroot); |
/* set some basic data */ |
{ |
struct mailimf_field* field = dc_mimeparser_lookup_field(mimeparser, "Subject"); |
if (field && field->fld_type==MAILIMF_FIELD_SUBJECT) { |
mimeparser->subject = dc_decode_header_words(field->fld_data.fld_subject->sbj_value); |
} |
} |
if (dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Version")) { |
mimeparser->is_send_by_messenger = 1; |
} |
if (dc_mimeparser_lookup_field(mimeparser, "Autocrypt-Setup-Message")) { |
/* Autocrypt-Setup-Message header found - check if there is an application/autocrypt-setup part */ |
int i, has_setup_file = 0; |
for (i = 0; i < carray_count(mimeparser->parts); i++) { |
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); |
if (part->int_mimetype==DC_MIMETYPE_AC_SETUP_FILE) { |
has_setup_file = 1; |
} |
} |
if (has_setup_file) { |
/* delete all parts but the application/autocrypt-setup part */ |
mimeparser->is_system_message = DC_CMD_AUTOCRYPT_SETUP_MESSAGE; |
for (i = 0; i < carray_count(mimeparser->parts); i++) { |
dc_mimepart_t* part = (dc_mimepart_t*)carray_get(mimeparser->parts, i); |
if (part->int_mimetype!=DC_MIMETYPE_AC_SETUP_FILE) { |
dc_mimepart_unref(part); |
carray_delete_slow(mimeparser->parts, i); |
i--; /* start over with the same index */ |
} |
} |
} |
} |
else if ((optional_field=dc_mimeparser_lookup_optional_field(mimeparser, "Chat-Content"))!=NULL |
&& optional_field->fld_value!=NULL) |
{ |
if (strcmp(optional_field->fld_value, "location-streaming-enabled")==0) { |
mimeparser->is_system_message = DC_CMD_LOCATION_STREAMING_ENABLED; |
} |
} |
/* some special system message? */ |
if (dc_mimeparser_lookup_field(mimeparser, "Chat-Group-Image") |
&& carray_count(mimeparser->parts)>=1) { |
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 0); |
if (textpart->type==DC_MSG_TEXT) { |
if (carray_count(mimeparser->parts)>=2) { |
dc_mimepart_t* imgpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 1); |
if (imgpart->type==DC_MSG_IMAGE) { |
imgpart->is_meta = 1; |
} |
} |
} |
} |
// create compound messages |
if (mimeparser->is_send_by_messenger |
&& s_generate_compound_msgs |
&& carray_count(mimeparser->parts)==2) |
{ |
dc_mimepart_t* textpart = (dc_mimepart_t*)carray_get(mimeparser->parts, 0); |
dc_mimepart_t* filepart = (dc_mimepart_t*)carray_get(mimeparser->parts, 1); |
if (textpart->type==DC_MSG_TEXT |
&& DC_MSG_NEEDS_ATTACHMENT(filepart->type) |
&& !filepart->is_meta) |
{ |
free(filepart->msg); |
filepart->msg = textpart->msg; |
textpart->msg = NULL; |
dc_mimepart_unref(textpart); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.