On Sat, Jan 14, 2023 at 03:16:53PM +1300, Peter wrote:
> Perhaps:
>
> /^(Received:.*)192\.168\.1\.2(.*)$/ REPLACE ${1}127.0.0.2${2}
No. This is neither precise nor accurate.
* Precision, the proposed regular expression can match unexpected
parts of the "Received" header.
* Accuracy, this is completely the wrong test, the IP address in
received lines is a *remote* address, but we're looking to prune
lines added by the local server. For that, one matches the
hostname (same as $myhostname) in the "by <name>" part of the
receving line... with due precision, e.g. with (not too ancient)
PCRE:
/\AReceived: \s+ from \s+ \S+
(?# Received from <heloname>)
(?: \s+ ( [(] (?: [^()\\]*+ | \\. | (?1)+)* [)] ))*
(?# zero or more nestable backslash escapable comments)
(\n \s+ by \s+ (?: \Qmta.name.example\E ) \s+
(?# by mta.name.example )
.* )
/x REPLACE Received: from localhost ${2}
The above can precisely match nested paired parentheses, with backslash
escaping, ... which is perhaps overkill in this context.
--
Viktor.