Mailinglists35 via Postfix-users:
>      
>  Hi
>  
> I run a postfix 3.5.9 smtp relay for a webserver that sends user signup and 
> forgot password emails. That's the only use case and the server does not 
> receive any other emails and neither generates any locally.
>  
> I'm trying to prevent leaking internal information (hostname  &  IP) in 
> Received header.

If the use case is sending "signup" and "reset" email messages, you
cuold drop all Received: headers that match your pattern (the pattern
can then be simplified because it only needs to look at the first line).

But wait, there is more.

> For this, I've setup `smtp_header_checks = regexp:/etc/postfix/header_checks` 
> with the contents:
>  
> /^(Received: from \[127\.0\.0\.1\] \(web\d\w+ 
> \[\d+\.\d+\.\d+\.\d+\]\))((.|\n|\t)*)/m REPLACE Received: from 
> email.domain.tld (email.domain.tld. [1.2.3.4])$2

> The postmap input looks like this:
>  
> echo -e    "Received: from [127.0.0.1] (web1dev [10.11.12.13])\n\tby 
> email.domain.tld (Postfix) with ESMTPS id C9056
>    7E002\n\tfor  <em...@gmail.com>; Fri,    8 Mar 2024 19:20:29 +0200 (EET)" 
> | postmap -q - pcre:/etc/postfix/header_checks
>    Received: from [127.0.0.1] (web1dev [10.11.12.13])     REPLACE Received: 
> from email.domain.tld (email.domain.tld. [1.2.3.4])
>  
> What I am doing wrong?

The postmap command reads input from stdin one line at a time, and
applies each input line to all the header_checks patterns.  It can't
be used for multiline inputs.

However, it can handle multiline input when used like this, but the
details may be bash specific.

$ cat header_checks
/^Received: from \S+ \(web\d\w+ [^)]+\)(.+)/m REPLACE Received: from 
email.domain.tld (email.domain.tld. [1.2.3.4])$1

input=$(echo -e "Received: from [127.0.0.1] (web1dev [10.11.12.13])\n\tby 
email.domain.tld (Postfix) with ESMTPS id C90567E002\n\tfor <em...@gmail.com>; 
Fri,  8 Mar 2024 19:20:29 +0200 (EET)")

$ postmap -q "$input" pcre:header_checks
REPLACE Received: from email.domain.tld (email.domain.tld. [1.2.3.4])
        by email.domain.tld (Postfix) with ESMTPS id C90567E002
        for <em...@gmail.com>; Fri,  8 Mar 2024 19:20:29 +0200 (EET)

It took me a while to figure that out.

        Wietse
_______________________________________________
Postfix-users mailing list -- postfix-users@postfix.org
To unsubscribe send an email to postfix-users-le...@postfix.org

Reply via email to