]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Fix parsing received that start from a comment
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Oct 2021 13:20:00 +0000 (14:20 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 8 Oct 2021 13:20:00 +0000 (14:20 +0100)
src/libmime/received.cxx

index 6ba2cd678a8d34f125efbeb6628289f2453858e3..74d2e3574d34013753ac12b132adbb5454729574 100644 (file)
@@ -258,12 +258,41 @@ received_spill(const std::string_view &in,
        const auto *p = in.data();
        const auto *end = p + in.size();
 
+       /* Skip spaces */
        while (p < end && g_ascii_isspace (*p)) {
                p++;
        }
 
+       /* And SMTP comments */
+       if (*p == '(') {
+               auto obraces = 0, ebraces = 0;
+
+               while (p < end) {
+                       if (*p == ')') {
+                               ebraces ++;
+                       }
+                       else if (*p == '(') {
+                               obraces ++;
+                       }
+
+                       p ++;
+
+                       if (obraces == ebraces) {
+                               /* Skip spaces after  */
+                               while (p < end && g_ascii_isspace (*p)) {
+                                       p++;
+                               }
+                               break;
+                       }
+               }
+       }
+
        auto len = end - p;
 
+       if (len == 0) {
+               return {};
+       }
+
        auto maybe_process_part = [&](received_part_type what) -> bool {
                parts.emplace_back(what);
                auto &rcvd_part = parts.back();
@@ -1003,6 +1032,14 @@ TEST_CASE("parse received")
                                                        {"by_hostname", "mail.832zsu.cn"},
                                        }
                        },
+                       // From part is in the comment
+                       {"(from asterisk@localhost)\n"
+                        "        by pbx.xxx.com (8.14.7/8.14.7/Submit) id 076Go4wD014562;\n"
+                        "        Thu, 6 Aug 2020 11:50:04 -0500"sv,
+                                       {
+                                                       {"by_hostname", "pbx.xxx.com"},
+                                       }
+                       },
        };
        rspamd_mempool_t *pool = rspamd_mempool_new_default("rcvd test", 0);