]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Support uuencoding
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Oct 2019 16:03:19 +0000 (17:03 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 23 Oct 2019 16:03:19 +0000 (17:03 +0100)
lualib/lua_magic/init.lua
src/libmime/message.h
src/libmime/mime_parser.c

index d87e40d58727f4b6aa23feddacc3e2dda974fc52..2bfc067e365633ccd8b799a20f302a5c7b68a30f 100644 (file)
@@ -228,6 +228,8 @@ local function match_chunk(chunk, input, tlen, offset, trie, processed_tbl, log_
       for _,position in ipairs(match.positions) do
         local matched = false
         for _,pos in ipairs(matched_positions) do
+          lua_util.debugm(N, log_obj, 'found match %s at offset %s(from %s)',
+              pattern.ext, pos, offset)
           if not match_position(pos + offset, position) then
             matched = true
             break
index 642c19a0e24c7279e7e5ef0ea1f2c9ad695eab49..f3a8315fc9ad25942c8f1394077b14243dc78339 100644 (file)
@@ -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;
index dc3ef4b7c035fda56e10babf925f6892aec9bf90..e11b59e34793b4d30e0c43f39c62b0c06d73f279 100644 (file)
@@ -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 ();
        }