diff -urN ../Mail-SpamAssassin-3.4.4.orig/lib/Mail/SpamAssassin/Message/Metadata/Received.pm ./lib/Mail/SpamAssassin/Message/Metadata/Received.pm --- ../Mail-SpamAssassin-3.4.4.orig/lib/Mail/SpamAssassin/Message/Metadata/Received.pm 2020-01-25 04:50:48.000000000 +0200 +++ ./lib/Mail/SpamAssassin/Message/Metadata/Received.pm 2021-01-12 01:03:02.388501000 +0200 @@ -378,7 +378,6 @@ s/\)by /) by /; # --------------------------------------------------------------------------- - # OK -- given knowledge of most Received header formats, # break them down. We have to do something like this, because # some MTAs will swap position of rdns and helo -- so we can't @@ -454,9 +453,63 @@ # --------------------------------------------------------------------------- + # try to catch enveloper senders + if (/(?:return-path:? |envelope-(?:sender|from)[ =])?\b/i) { + $envfrom = $1; + } + # Received: from njmta-20.sailthru.com (173.228.155.20) by mta237-32.sailthru.com id hklipc1qqbs1 + # Received: from nj1-illmaroon.flt (172.18.20.34) by njmta-20.sailthru.com id hklilm1qqbsn + if (/\bfrom (\S+) \((${IP_ADDRESS})\) by (\S+) /) { + $rdns = $1; + $helo = $1; + $ip = $2; + $by = $3; + goto enough; + } + # Received: from ny1mta-226.sailthru.com ([65.39.215.226]:38412) by mx.org.ua with esmtp (envelope-from ) id 1khqhx-0007P6-G3 + elsif (/\bfrom (\S+) \(\[(${IP_ADDRESS})\](?::\d+)?\) by (\S+) /) { + $rdns = $1; + $helo = $1; + $ip = $2; + $by = $3; + $ident = $1 if (/ident=(\S*)/); + goto enough; + } + # Received: from mail.cks.com.ua ([194.140.239.176]:46462 helo=mail.avers.odessa.ua) by mx.org.ua with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (envelope-from ) id 1kg9bb-000Hg1-C4 + elsif (/\bfrom (\S+) \(\[(${IP_ADDRESS})\](?::\d+)? helo=(\S+)\) by (\S+) /) { + $rdns = $1; + $ip = $2; + $helo = $3; + $by = $4; + $ident = $1 if (/ident=(\S*)/); + goto enough; + } + # Received: from [45.137.124.40] (port=56167 helo=iqek.huicqmp.cn) by mx.org.ua with esmtp (envelope-from ) id 1khsoq-000PEN-Qk + elsif (/\bfrom \[(${IP_ADDRESS})\] \((?:port=\d+ )?helo=(\S+)\) by (\S+) /) { + $rdns = ''; + $ip = $1; + $helo = $2; + $by = $3; + $ident = $1 if (/ident=(\S*)/); + goto enough; + } + # Received: from localhost.localdomain (localhost [IPv6:::1]) by host.domain.tld (Postfix) with ESMTP id 3E3731C8B482F + # Received: from localhost.localdomain (localhost [127.0.0.1]) by host.domain.tld (Postfix) with ESMTP id 3E3731C8B482F + # Received: from localhost.localdomain (unknown [10.10.10.151]) by host.domain.tld (Postfix) with ESMTP id 3E3731C8B482F + elsif (/\bfrom (\S+) \((\S+) \[(?:IPv6:)?(${IP_ADDRESS})\]\) by (\S+) /) { + $helo = $1; + $rdns = ($2 eq 'unknown' ? '' : $2); + $ip = $3; + $by = $4; + $ip =~ s/^IPv6://; + goto enough; + } + +# --------------------------------------------------------------------------- + if (s/^from //) { # try to catch enveloper senders - if (/(?:return-path:? |envelope-(?:sender|from)[ =])(\S+)\b/i) { + if (/(?:return-path:? |envelope-(?:sender|from)[ =])?\b/i) { $envfrom = $1; }