From 36d9ed520af44c3a82b613e25ce6a703cc8d7399 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 6 Mar 2017 13:26:03 +0000 Subject: [PATCH] [Minor] Some more adjustments to CTE detection --- src/libmime/mime_parser.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/libmime/mime_parser.c b/src/libmime/mime_parser.c index c6c80e3f0..54c490109 100644 --- a/src/libmime/mime_parser.c +++ b/src/libmime/mime_parser.c @@ -149,8 +149,8 @@ static enum rspamd_cte rspamd_mime_part_get_cte_heuristic (struct rspamd_task *task, struct rspamd_mime_part *part) { - const guint check_len = 80; - guint real_len, nspaces = 0, neqsign = 0, n8bit = 0; + const guint check_len = 128; + guint real_len, nspaces = 0, neqsign = 0, n8bit = 0, nqpencoded = 0; gboolean b64_chars = TRUE; const guchar *p, *end; enum rspamd_cte ret = RSPAMD_CTE_UNKNOWN; @@ -163,6 +163,18 @@ rspamd_mime_part_get_cte_heuristic (struct rspamd_task *task, p ++; } + if (end > p + 2) { + if (*(end - 1) == '=') { + neqsign ++; + end --; + } + + if (*(end - 1) == '=') { + neqsign ++; + end --; + } + } + if (end - p > real_len) { end = p + real_len; } @@ -178,6 +190,14 @@ rspamd_mime_part_get_cte_heuristic (struct rspamd_task *task, } else if (*p == '=') { neqsign ++; + p ++; + + if (p + 2 < end && g_ascii_isxdigit (*p) && g_ascii_isxdigit (*(p + 1))) { + p ++; + nqpencoded ++; + } + + continue; } else if (*p >= 0x80) { n8bit ++; @@ -194,7 +214,7 @@ rspamd_mime_part_get_cte_heuristic (struct rspamd_task *task, ret = RSPAMD_CTE_B64; } else if (n8bit == 0) { - if (neqsign > 2 && nspaces > 2) { + if (neqsign > 2 && nqpencoded > 2) { ret = RSPAMD_CTE_QP; } else { -- 2.39.5