aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-08 14:20:00 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-10-08 14:20:00 +0100
commitde4454e5e19e1f62cb7746086ebcfd6dc35ad425 (patch)
treece029a34bfa54388e6fef22a585c447a34249bf5 /src/libmime
parentf5335980825197a5711d51e3545b69f246de6c28 (diff)
downloadrspamd-de4454e5e19e1f62cb7746086ebcfd6dc35ad425.tar.gz
rspamd-de4454e5e19e1f62cb7746086ebcfd6dc35ad425.zip
[Minor] Fix parsing received that start from a comment
Diffstat (limited to 'src/libmime')
-rw-r--r--src/libmime/received.cxx37
1 files changed, 37 insertions, 0 deletions
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@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);