diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-12 13:54:24 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-12 13:54:24 +0000 |
commit | 1ae701bc0d7997ed31dbb383c77a5f422fcc4a7f (patch) | |
tree | 911fc212fd5001f1c8c0eabca660b88cef9bff4b | |
parent | 6da8d8cae25d859b6f25a8bfc279189330a41a45 (diff) | |
download | rspamd-1ae701bc0d7997ed31dbb383c77a5f422fcc4a7f.tar.gz rspamd-1ae701bc0d7997ed31dbb383c77a5f422fcc4a7f.zip |
[Minor] Add some initial workarounds for broken CT
-rw-r--r-- | src/libmime/content_type.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libmime/content_type.c b/src/libmime/content_type.c index fa9768bf4..934c12eab 100644 --- a/src/libmime/content_type.c +++ b/src/libmime/content_type.c @@ -66,6 +66,7 @@ rspamd_content_type_parse (const gchar *in, gsize len, rspamd_mempool_t *pool) { struct rspamd_content_type *res = NULL, val; + rspamd_ftok_t srch; val.lc_data = rspamd_mempool_alloc (pool, len); memcpy (val.lc_data, in, len); @@ -79,6 +80,40 @@ rspamd_content_type_parse (const gchar *in, rspamd_mempool_add_destructor (pool, (rspamd_mempool_destruct_t)g_hash_table_unref, res->attrs); } + + /* Now do some hacks to work with broken content types */ + if (res->subtype.len == 0) { + srch.begin = "text"; + srch.len = 4; + + if (rspamd_ftok_cmp (&res->type, &srch) == 0) { + /* Workaround for Content-Type: text */ + /* Assume text/plain */ + res->subtype.begin = "plain"; + res->subtype.len = 5; + } + else { + srch.begin = "html"; + srch.len = 4; + + if (rspamd_ftok_cmp (&res->type, &srch) == 0) { + /* Workaround for Content-Type: html */ + res->type.begin = "text"; + res->type.len = 4; + res->subtype.begin = "html"; + res->subtype.len = 4; + } + else { + srch.begin = "application"; + srch.len = 11; + + if (rspamd_ftok_cmp (&res->type, &srch) == 0) { + res->subtype.begin = "octet-stream"; + res->subtype.len = 12; + } + } + } + } } else { msg_warn_pool ("cannot parse content type: %*s", (gint)len, val.lc_data); |