]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix `with` parsing
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Feb 2019 17:24:51 +0000 (17:24 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 Feb 2019 17:24:51 +0000 (17:24 +0000)
src/libmime/mime_headers.c
test/lua/unit/received.lua

index 20c1e2ee9ff7470e3583396c41d78e729a5c2e9b..ca44c476591100f5bc61d83df9e46a2c71b6c6a7 100644 (file)
@@ -1427,7 +1427,7 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
 
                                RSPAMD_FTOK_ASSIGN (&t2, "esmtp");
 
-                               if (rspamd_ftok_starts_with (&t1, &t2) == 0) {
+                               if (rspamd_ftok_starts_with (&t1, &t2)) {
                                        /*
                                         * esmtp, esmtps, esmtpsa
                                         */
@@ -1440,6 +1440,7 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
                                                        rh->type = RSPAMD_RECEIVED_ESMTPS;
                                                        rh->flags |= RSPAMD_RECEIVED_FLAG_SSL;
                                                }
+                                               continue;
                                        }
                                        else if (t1.len == t2.len + 2) {
                                                if (t1.begin[t2.len - 1] == 's' &&
@@ -1448,9 +1449,11 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
                                                        rh->flags |= RSPAMD_RECEIVED_FLAG_AUTHENTICATED;
                                                        rh->flags |= RSPAMD_RECEIVED_FLAG_SSL;
                                                }
+                                               continue;
                                        }
                                        else if (t1.len == t2.len) {
                                                rh->type = RSPAMD_RECEIVED_ESMTP;
+                                               continue;
                                        }
                                }
 
@@ -1458,23 +1461,26 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
 
                                if (rspamd_ftok_cmp (&t1, &t2) == 0) {
                                        rh->type = RSPAMD_RECEIVED_LMTP;
+                                       continue;
                                }
 
                                RSPAMD_FTOK_ASSIGN (&t2, "imap");
 
                                if (rspamd_ftok_cmp (&t1, &t2) == 0) {
                                        rh->type = RSPAMD_RECEIVED_IMAP;
+                                       continue;
                                }
 
                                RSPAMD_FTOK_ASSIGN (&t2, "local");
 
                                if (rspamd_ftok_cmp (&t1, &t2) == 0) {
                                        rh->type = RSPAMD_RECEIVED_LOCAL;
+                                       continue;
                                }
 
                                RSPAMD_FTOK_ASSIGN (&t2, "http");
 
-                               if (rspamd_ftok_starts_with (&t1, &t2) == 0) {
+                               if (rspamd_ftok_starts_with (&t1, &t2)) {
                                        if (t1.len == t2.len + 1) {
                                                if (t1.begin[t2.len] == 's') {
                                                        rh->type = RSPAMD_RECEIVED_HTTP;
@@ -1484,6 +1490,8 @@ rspamd_smtp_received_parse (struct rspamd_task *task,
                                        else if (t1.len == t2.len) {
                                                rh->type = RSPAMD_RECEIVED_HTTP;
                                        }
+
+                                       continue;
                                }
                        }
 
index 75fd3701ce618dea2e7c8941329ce711c0d32526..b7a4257855d44030c82774bdeb50bba369f93ab9 100644 (file)
@@ -25,6 +25,19 @@ context("Received headers parser", function()
   ]]
 
   local cases = {
+    {[[from server.chat-met-vreemden.nl (unknown [IPv6:2a01:7c8:aab6:26d:5054:ff:fed1:1da2])
+       (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
+       (Client did not present a certificate)
+       by mx1.freebsd.org (Postfix) with ESMTPS id CF0171862
+       for <test@example.com>; Mon,  6 Jul 2015 09:01:20 +0000 (UTC)
+       (envelope-from upwest201diana@outlook.com)]],
+      {
+        real_ip = '2a01:7c8:aab6:26d:5054:ff:fed1:1da2',
+        from_hostname = 'server.chat-met-vreemden.nl',
+        real_hostname = '',
+        by_hostname = 'mx1.freebsd.org',
+      },
+    },
     {[[from out-9.smtp.github.com (out-9.smtp.github.com [192.30.254.192])
  (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
  (No client certificate requested)
@@ -91,7 +104,7 @@ context("Received headers parser", function()
        real_ip = '65.19.167.131',
        by_hostname = 'mail01.someotherdomain.org',
      }
-    }
+    },
   }
 
   local task = ffi.C.rspamd_task_new(nil, nil)
@@ -120,7 +133,7 @@ context("Received headers parser", function()
           end
         elseif k == 'from_ip' then
           if #v > 0 then
-            local got_string = tostring(rspamd_ip.from_string(ffi_string(hdr.from_ip)))
+            local got_string = tostring((rspamd_ip.from_string(ffi_string(hdr.from_ip) or '')) or '')
             local expected_string = tostring(rspamd_ip.from_string(v))
             assert_equal(expected_string, got_string,
                 string.format('%s: from_ip: %s, expected: %s',
@@ -132,7 +145,7 @@ context("Received headers parser", function()
           end
         elseif k == 'real_ip' then
           if #v > 0 then
-            local got_string = tostring(rspamd_ip.from_string(ffi_string(hdr.from_ip)))
+            local got_string = tostring((rspamd_ip.from_string(ffi_string(hdr.from_ip) or '')) or '')
             local expected_string = tostring(rspamd_ip.from_string(v))
             assert_equal(expected_string, got_string,
                 string.format('%s: real_ip: %s, expected: %s',