commit de4454e: [Minor] Fix parsing received that start from a comment

Vsevolod Stakhov vsevolod at highsecure.ru
Fri Oct 8 13:21:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-10-08 14:20:00 +0100
URL: https://github.com/rspamd/rspamd/commit/de4454e5e19e1f62cb7746086ebcfd6dc35ad425 (HEAD -> master)

[Minor] Fix parsing received that start from a comment

---
 src/libmime/received.cxx | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx
index 6ba2cd678..74d2e3574 100644
--- a/src/libmime/received.cxx
+++ b/src/libmime/received.cxx
@@ -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 at 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);
 


More information about the Commits mailing list