]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix parsing of some misformed email addresses
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Jul 2021 14:42:57 +0000 (15:42 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 21 Jul 2021 14:42:57 +0000 (15:42 +0100)
src/libmime/email_addr.c
test/lua/unit/smtp_addr.lua

index 6895c1b11f9aa2c528607c8e273bebc6029529e8..38a4732c5d940653c9361ed4ba373e447781617f 100644 (file)
@@ -248,7 +248,7 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, const gchar *hdr,
                                                                gint max_elements)
 {
        GPtrArray *res = src;
-       gboolean seen_at = FALSE;
+       gboolean seen_at = FALSE, seen_obrace = FALSE;
 
        const gchar *p = hdr, *end = hdr + len, *c = hdr, *t;
        GString *ns, *cpy;
@@ -434,6 +434,12 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, const gchar *hdr,
                                state = skip_spaces;
                                next_state = parse_name;
                        }
+                       else if (*p == '@' && seen_obrace) {
+                               seen_at = TRUE;
+                       }
+                       else if (*p == '<') {
+                               seen_obrace = TRUE;
+                       }
                        p ++;
                        break;
                case parse_addr:
@@ -518,6 +524,17 @@ rspamd_email_address_from_mime (rspamd_mempool_t *pool, const gchar *hdr,
                break;
        case parse_quoted:
                /* Unfinished quoted string or a comment */
+               /* If we have seen obrace + at, then we still can try to resolve address */
+               if (seen_at && seen_obrace) {
+                       p = rspamd_memrchr (cpy->str, '<', cpy->len);
+                       g_assert (p != NULL);
+                       if (rspamd_email_address_check_and_add (p, end - p,
+                                       res, pool, ns, max_elements) == 0) {
+                               if (res->len == 0) {
+                                       rspamd_email_address_add (pool, res, NULL, ns);
+                               }
+                       }
+               }
                break;
        default:
                /* Do nothing */
index 062c509d56c217a554116ce52f777ae4fed38b89..cfce20fcc07434976b05679063bbbb225d507846 100644 (file)
@@ -4,7 +4,7 @@ context("SMTP address check functions", function()
   local logger = require("rspamd_logger")
   local ffi = require("ffi")
   local util = require("rspamd_util")
-  require "fun" ()
+  local fun = require "fun"
   ffi.cdef[[
   struct rspamd_email_address {
     const char *raw;
@@ -47,13 +47,13 @@ context("SMTP address check functions", function()
   }
 
 
-  each(function(case)
+  fun.each(function(case)
     test("Parse valid smtp addr: " .. case[1], function()
       local st = ffi.C.rspamd_email_address_from_smtp(case[1], #case[1])
 
       assert_not_nil(st, "should be able to parse " .. case[1])
 
-      each(function(k, ex)
+      fun.each(function(k, ex)
         if k == 'user' then
           local str = ffi.string(st.user, st.user_len)
           assert_equal(str, ex)
@@ -81,7 +81,7 @@ context("SMTP address check functions", function()
       '<a@example.com><>',
     }
 
-  each(function(case)
+  fun.each(function(case)
     test("Parse invalid smtp addr: " .. case, function()
       local st = ffi.C.rspamd_email_address_from_smtp(case, #case)