Discussion:
using header_checks to change message-id header
(too old to reply)
Jerico2day
2011-08-15 14:30:37 UTC
Permalink
Hey all, I'm wondering how best I can change the message ID in the
header of emails. I use Zarafa 7x on an internal machine and I don't
believe there is a way to change the header easily with that software.

Here's an example from my email headers

Message-Id: <***@my.domain.com>

The problem is, is that "my.domain.com" is an internal server that
sends mail to a relay server. I don't want people really seeing my
internal domain or IP. I was able to change other parts of the header
to remove my local address using header_checks.

I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.

Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.

Thanks!
Noel Jones
2011-08-15 15:09:43 UTC
Permalink
Post by Jerico2day
Hey all, I'm wondering how best I can change the message ID in the
header of emails. I use Zarafa 7x on an internal machine and I don't
believe there is a way to change the header easily with that software.
Here's an example from my email headers
The problem is, is that "my.domain.com" is an internal server that
sends mail to a relay server. I don't want people really seeing my
internal domain or IP. I was able to change other parts of the header
to remove my local address using header_checks.
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.
Thanks!
You can mangle an existing Message-ID with the REPLACE action just
like any other header.

Maybe your mail arrives without a message-id, so there isn't one
there to mangle. Postfix will insert a message-id if there isn't
one, and header_checks won't see the generated header.


-- Noel Jones
Peter Blair
2011-08-15 17:13:10 UTC
Permalink
Post by Jerico2day
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header  to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.
First in your main.cf:

header_checks = pcre:/etc/postfix/header_checks

Secondly in your /etc/postfix/header_checks:

/Message-Id:\s+<(.*?)@my.domain.com>/ REPLACE Message-Id: <$***@my.domain.net>

Thirdly, test it:

$ postmap -q "Message-Id: <***@my.domain.com>"
pcre:/etc/postfix/header_checks
Post by Jerico2day
Thanks!
Note, ensure that your postfix installation supports pcre. My desktop
is debian, so I call:

$ apt-cache search postfix-pcre
postfix-pcre - PCRE map support for Postfix
i***@brokersolutions.it
2012-08-28 13:07:53 UTC
Permalink
Post by Peter Blair
Post by Jerico2day
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header  to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.
header_checks = pcre:/etc/postfix/header_checks
pcre:/etc/postfix/header_checks
Post by Jerico2day
Thanks!
Note, ensure that your postfix installation supports pcre. My desktop
$ apt-cache search postfix-pcre
postfix-pcre - PCRE map support for Postfix
Thank's Peter, your string work perfect !!
a***@gmail.com
2016-12-23 15:31:32 UTC
Permalink
Post by Peter Blair
Post by Jerico2day
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header  to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.
header_checks = pcre:/etc/postfix/header_checks
pcre:/etc/postfix/header_checks
Post by Jerico2day
Thanks!
Note, ensure that your postfix installation supports pcre. My desktop
$ apt-cache search postfix-pcre
postfix-pcre - PCRE map support for Postfix
Hello,

Should i replace (my.domain.com) with my own domain ??

Thanks.

Ralf Hildebrandt
2011-08-16 06:35:24 UTC
Permalink
Post by Peter Blair
Post by Jerico2day
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header  to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Unfortunately, I'm not quite sure how to do that. I would appreciate
any assistance.
header_checks = pcre:/etc/postfix/header_checks
Warning: this might also alter Resent-Message-Id: into Message-Id:!!!

/^Message-Id:\s+<(.*?)@my\.domain\.com>$/ REPLACE Message-Id: <$***@my.domain.net>

could be more robust.
--
Ralf Hildebrandt
Geschäftsbereich IT | Abteilung Netzwerk
Charité - Universitätsmedizin Berlin
Campus Benjamin Franklin
Hindenburgdamm 30 | D-12203 Berlin
Tel. +49 30 450 570 155 | Fax: +49 30 450 570 962
***@charite.de | http://www.charite.de
Peter Blair
2011-08-16 12:16:13 UTC
Permalink
On Tue, Aug 16, 2011 at 2:35 AM, Ralf Hildebrandt
Post by Ralf Hildebrandt
Warning: this might also alter Resent-Message-Id: into Message-Id:!!!
-1s/might/will/

Cheers! :)
Jerico2day
2011-08-16 15:40:00 UTC
Permalink
Thanks all for the help. I decided instead to just replace all
instances of my internal domain using the following on my gateway
server:

/^(.*?)internal\.domain\.com(.*?)/ REPLACE ${1}pretend_name.domain.com${2}

This is because it wasn't modifying the Resent-Message-Id headers.

And on my internal server I just reverse the process. It doesn't seem
to work on lines containing multiple references to my internal server,
but that doesn't really affect me as I remove the received lines
altogether when it crosses my gateway.

Anyway, thanks again for the help!
bastian+postfix-users= (Bastian Blank)
2011-08-20 13:50:17 UTC
Permalink
Post by Jerico2day
I'd like to have postfix dynamically change "my.domain.com" only on
Message-Id header to some arbitrary domain that would be
public-facing for all outgoing mail and change it back for incoming
mail.
Care to explain how you intend to guarantee the uniqueness of the
message-ids?

Bastian
--
We Klingons believe as you do -- the sick should die. Only the strong
should live.
-- Kras, "Friday's Child", stardate 3497.2
s***@gmail.com
2016-10-24 23:22:31 UTC
Permalink
if anyone was looking like me for a catch all replace use this...

/Message-Id:\s+<(.*?)@.*?>/ REPLACE Message-Id: <$***@Domain.tld>
Continue reading on narkive:
Loading...