diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-23 17:03:19 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-10-23 17:03:19 +0100 |
commit | 052ccc761e2e9000ed11fcdd121585da77256bf6 (patch) | |
tree | e89343bddf0452314bbeab89cf70c05430f18d81 /src | |
parent | 85fc3e7a7a34c58e389cac92ea7101e4b71cce37 (diff) | |
download | rspamd-052ccc761e2e9000ed11fcdd121585da77256bf6.tar.gz rspamd-052ccc761e2e9000ed11fcdd121585da77256bf6.zip |
[Feature] Support uuencoding
Diffstat (limited to 'src')
-rw-r--r-- | src/libmime/message.h | 1 | ||||
-rw-r--r-- | src/libmime/mime_parser.c | 65 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/libmime/message.h b/src/libmime/message.h index 642c19a0e..f3a8315fc 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -44,6 +44,7 @@ enum rspamd_cte { RSPAMD_CTE_8BIT = 2, RSPAMD_CTE_QP = 3, RSPAMD_CTE_B64 = 4, + RSPAMD_CTE_UUE = 5, }; struct rspamd_mime_text_part; diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index dc3ef4b7c..e11b59e34 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -105,6 +105,9 @@ rspamd_cte_to_string (enum rspamd_cte ct) case RSPAMD_CTE_B64: ret = "base64"; break; + case RSPAMD_CTE_UUE: + ret = "X-uuencode"; + break; default: break; } @@ -131,6 +134,15 @@ rspamd_cte_from_string (const gchar *str) else if (strcmp (str, "base64") == 0) { ret = RSPAMD_CTE_B64; } + else if (strcmp (str, "X-uuencode") == 0) { + ret = RSPAMD_CTE_UUE; + } + else if (strcmp (str, "uuencode") == 0) { + ret = RSPAMD_CTE_UUE; + } + else if (strcmp (str, "X-uue") == 0) { + ret = RSPAMD_CTE_UUE; + } return ret; } @@ -172,6 +184,11 @@ rspamd_mime_parse_cte (const gchar *in, gsize len) case 0x171029DE1B0423A9ULL: /* base-64 */ ret = RSPAMD_CTE_B64; break; + case 0x420b54dc00d13cecULL: /* uuencode */ + case 0x8df6700b8f6c4cf9ULL: /* x-uuencode */ + case 0x41f725ec544356d3ULL: /* x-uue */ + ret = RSPAMD_CTE_UUE; + break; } return ret; @@ -195,6 +212,33 @@ rspamd_mime_part_get_cte_heuristic (struct rspamd_task *task, p ++; } + if (end - p > sizeof ("begin-base64 ")) { + const guchar *uue_start; + + if (memcmp (p, "begin ", sizeof ("begin ") - 1) == 0) { + uue_start = p + sizeof ("begin ") - 1; + + while (uue_start < end && g_ascii_isspace (*uue_start)) { + uue_start ++; + } + + if (uue_start < end && g_ascii_isdigit (*uue_start)) { + return RSPAMD_CTE_UUE; + } + } + else if (memcmp (p, "begin-base64 ", sizeof ("begin-base64 ") - 1) == 0) { + uue_start = p + sizeof ("begin ") - 1; + + while (uue_start < end && g_ascii_isspace (*uue_start)) { + uue_start ++; + } + + if (uue_start < end && g_ascii_isdigit (*uue_start)) { + return RSPAMD_CTE_UUE; + } + } + } + if (end > p + 2) { if (*(end - 1) == '=') { neqsign ++; @@ -512,6 +556,27 @@ rspamd_mime_parse_normal_part (struct rspamd_task *task, rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed); break; + case RSPAMD_CTE_UUE: + parsed = rspamd_fstring_sized_new (part->raw_data.len / 4 * 3 + 12); + r = rspamd_decode_uue_buf (part->raw_data.begin, part->raw_data.len, + parsed->str, parsed->allocated); + rspamd_mempool_add_destructor (task->task_pool, + (rspamd_mempool_destruct_t)rspamd_fstring_free, parsed); + if (r != -1) { + parsed->len = r; + part->parsed_data.begin = parsed->str; + part->parsed_data.len = parsed->len; + } + else { + msg_err_task ("invalid quoted-printable encoded part, assume 8bit"); + part->ct->flags |= RSPAMD_CONTENT_TYPE_BROKEN; + part->cte = RSPAMD_CTE_8BIT; + memcpy (parsed->str, part->raw_data.begin, part->raw_data.len); + parsed->len = part->raw_data.len; + part->parsed_data.begin = parsed->str; + part->parsed_data.len = parsed->len; + } + break; default: g_assert_not_reached (); } |