Mailing List Archive

Problems with rewriting a domain
Dear collegues,
we moved some internal domains from "olddomain.org" to "newdomain.org"
we have internal routing for the new and old domain
Now we want to get rid of the routing for "olddomain.org"
and I want to rewrite "olddomain.org" to "newdomain.org"
so "foo@sub.olddomain.org" should become "foo@sub.newdomain.org"
In my rewrite section of exim I use

^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS

which seems to run fine:

# exim -brw foo@sub.olddomain.org
2022-08-09 16:18:28 "foo@sub.olddomain.org" from smtp sender rewritten as "foo@sub.newdomain.org" by rule 1
SMTP: foo@sub.newdomain.org
sender: foo@sub.olddomain.org
from: foo@sub.olddomain.org
to: foo@sub.olddomain.org
cc: foo@sub.olddomain.org
bcc: foo@sub.olddomain.org
reply-to: foo@sub.olddomain.org
env-from: foo@sub.olddomain.org
2022-08-09 16:18:28 "foo@sub.olddomain.org" from env-to rewritten as "foo@sub.newdomain.org" by rule 1
env-to: foo@sub.newdomain.org

However, when I activate this, I see the following in my logs:
2022-08-09 15:59:22 Rewrite of <foo@sub.olddomain.org> yielded unparseable address: '>' missing at end of address in address <foo@sub.newdomain.org
and my routing fails since I have removed the routing for "olddomain.org"

So I modified my rewriting rule to
^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org> TS
(note the '>') Now it works as expected !?

Anyway with this, I'll get
# exim -brw foo@sub.olddomain.org
2022-08-09 16:24:33 Rewrite of foo@sub.olddomain.org yielded unparseable address: malformed address: > may not follow foo@sub.newdomain.org in address foo@sub.newdomain.org>
sender: foo@sub.olddomain.org
from: foo@sub.olddomain.org
to: foo@sub.olddomain.org
cc: foo@sub.olddomain.org
bcc: foo@sub.olddomain.org
reply-to: foo@sub.olddomain.org
env-from: foo@sub.olddomain.org
2022-08-09 16:24:33 Rewrite of foo@sub.olddomain.org yielded unparseable address: malformed address: > may not follow foo@sub.newdomain.org in address foo@sub.newdomain.org>
env-to: foo@sub.olddomain.org

What is going wrong here ?
Exim version 4.94.2 under Debian 11 (Bullseye)

Regards, Olaf
--
Karlsruher Institut für Technologie (KIT)
Steinbuch Centre for Computing (SCC)

Dipl.-Geophys. Olaf Hopp

Zirkel 2
Gebäude 20.21, Raum 316
76131 Karlsruhe

Telefon: +49 721 608-48009
E-Mail: Olaf.Hopp@kit.edu
Web: www.scc.kit.edu

Sitz der Körperschaft:
Kaiserstraße 12, 76131 Karlsruhe

KIT - Die Forschungsuniversität in der Helmholtz-Gemeinschaft
Re: Problems with rewriting a domain [ In reply to ]
On Tue, 9 Aug 2022, Olaf Hopp (SCC) via Exim-users wrote:

> Dear collegues,
> we moved some internal domains from "olddomain.org" to "newdomain.org"
> we have internal routing for the new and old domain
> Now we want to get rid of the routing for "olddomain.org"
> and I want to rewrite "olddomain.org" to "newdomain.org"
> so "foo@sub.olddomain.org" should become "foo@sub.newdomain.org"
> In my rewrite section of exim I use
>
> ^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS
>
> which seems to run fine:
>
> # exim -brw foo@sub.olddomain.org
> 2022-08-09 16:18:28 "foo@sub.olddomain.org" from smtp sender rewritten as
> "foo@sub.newdomain.org" by rule 1
> SMTP: foo@sub.newdomain.org
> sender: foo@sub.olddomain.org
> from: foo@sub.olddomain.org
> to: foo@sub.olddomain.org
> cc: foo@sub.olddomain.org
> bcc: foo@sub.olddomain.org
> reply-to: foo@sub.olddomain.org
> env-from: foo@sub.olddomain.org
> 2022-08-09 16:18:28 "foo@sub.olddomain.org" from env-to rewritten as
> "foo@sub.newdomain.org" by rule 1
> env-to: foo@sub.newdomain.org
>
> However, when I activate this, I see the following in my logs:
> 2022-08-09 15:59:22 Rewrite of <foo@sub.olddomain.org> yielded unparseable
> address: '>' missing at end of address in address <foo@sub.newdomain.org
> and my routing fails since I have removed the routing for "olddomain.org"
>
> So I modified my rewriting rule to
> ^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org> TS
> (note the '>') Now it works as expected !?
>
> Anyway with this, I'll get
> # exim -brw foo@sub.olddomain.org
> 2022-08-09 16:24:33 Rewrite of foo@sub.olddomain.org yielded unparseable
> address: malformed address: > may not follow foo@sub.newdomain.org in address
> foo@sub.newdomain.org>
> sender: foo@sub.olddomain.org
> from: foo@sub.olddomain.org
> to: foo@sub.olddomain.org
> cc: foo@sub.olddomain.org
> bcc: foo@sub.olddomain.org
> reply-to: foo@sub.olddomain.org
> env-from: foo@sub.olddomain.org
> 2022-08-09 16:24:33 Rewrite of foo@sub.olddomain.org yielded unparseable
> address: malformed address: > may not follow foo@sub.newdomain.org in address
> foo@sub.newdomain.org>
> env-to: foo@sub.olddomain.org
>
> What is going wrong here ?
> Exim version 4.94.2 under Debian 11 (Bullseye)

You have:
^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS

The examples suggest that:

*@*olddomain.org $1@$2.newdomain.org TS

would be sufficient.
In particular I doubt that you need the anchoring "^".
Perhaps the extending patterns are forcing $1 to include
the opening "<", so that the matching ">" is never removed ?

This does seem like a bug though.

--
Andrew C. Aitchison Kendal, UK
andrew@aitchison.me.uk

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Problems with rewriting a domain [ In reply to ]
On 8/9/22 17:54, Andrew C Aitchison wrote:
> On Tue, 9 Aug 2022, Olaf Hopp (SCC) via Exim-users wrote:

[...]

> You have:
>        ^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS
>
> The examples suggest that:
>
>     *@*olddomain.org $1@$2.newdomain.org TS
>
> would be sufficient.

When using 'S' as rewriting flag you must use regular expressions.
Otherwise exim won't start:
rewrite rule has the S flag but is not a regular expression
And I think I need the 'S' flag here, otherwise my routing fails.

> In particular I doubt that you need the anchoring "^".

And also the leading '^' is necessary when using 'S'
otherwise exim also fails to start for the same reason

> Perhaps the extending patterns are forcing $1 to include
> the opening "<", so that the matching ">" is never removed ?
>
> This does seem like a bug though.
I also think so

Olaf


--
Karlsruher Institut für Technologie (KIT)
Steinbuch Centre for Computing (SCC)

Dipl.-Geophys. Olaf Hopp

Zirkel 2
Gebäude 20.21, Raum 316
76131 Karlsruhe

Telefon: +49 721 608-48009
E-Mail: Olaf.Hopp@kit.edu
Web: www.scc.kit.edu

Sitz der Körperschaft:
Kaiserstraße 12, 76131 Karlsruhe

KIT - Die Forschungsuniversität in der Helmholtz-Gemeinschaft
Re: Problems with rewriting a domain [ In reply to ]
On Wed, 10 Aug 2022, Olaf Hopp (SCC) via Exim-users wrote:

> On 8/9/22 17:54, Andrew C Aitchison wrote:
>> On Tue, 9 Aug 2022, Olaf Hopp (SCC) via Exim-users wrote:
>
> [...]
>
>> You have:
>> ^(.*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS
>>
>> The examples suggest that:
>>
>> *@*olddomain.org $1@$2.newdomain.org TS
>>
>> would be sufficient.
>
> When using 'S' as rewriting flag you must use regular expressions.
> Otherwise exim won't start:
> rewrite rule has the S flag but is not a regular expression
> And I think I need the 'S' flag here, otherwise my routing fails.

Ah. I didn't know about the S flag.

>> In particular I doubt that you need the anchoring "^".
>
> And also the leading '^' is necessary when using 'S'
> otherwise exim also fails to start for the same reason

Odd.

>> Perhaps the extending patterns are forcing $1 to include
>> the opening "<", so that the matching ">" is never removed ?

31.9 The SMTP-time rewriting flag
---------------------------------

The rewrite flag "S" specifies a rewrite of incoming envelope addresses at SMTP
time, as soon as an address is received in a MAIL or RCPT command, and before
any other processing; even before syntax checking. The pattern is required to
be a regular expression, and it is matched against the whole of the data for
the command, including any surrounding angle brackets.

So $1 *does* include the opening "<" which is why you had to add the ">"

The rule
^([^<]*)@(.*)\\.olddomain\\.org $1@$2.newdomain.org TS
seems to work for me.

Without the doubled slash:
^([^<]*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS
we would also rewrite foo@subolddomain.org as foo@su.newdomain.org

#exim4 -C /tmp/werdna/exim.rewrite.test2 -d+all -brw "Fred Flintstone <foo@subolddomain.org>"
... ... ...
08:46:22 240891 ?considering: ^([^<]*)@(.*)\.olddomain\.org
08:46:22 240891 ???expanding: ^([^<]*)@(.*)\.olddomain\.org
08:46:22 240891 ??????result: ^([^<]*)@(.*).olddomain.org
sender: Fred Flintstone <foo@subolddomain.org>
from: Fred Flintstone <foo@subolddomain.org>
to: Fred Flintstone <foo@subolddomain.org>
cc: Fred Flintstone <foo@subolddomain.org>
bcc: Fred Flintstone <foo@subolddomain.org>
reply-to: Fred Flintstone <foo@subolddomain.org>
env-from: foo@subolddomain.org
08:46:22 240891 ?considering: ^([^<]*)@(.*)\.olddomain\.org
08:46:22 240891 ???expanding: ^([^<]*)@(.*)\.olddomain\.org
08:46:22 240891 ??????result: ^([^<]*)@(.*).olddomain.org
08:46:22 240891 address match test: subject=foo@subolddomain.org pattern=^([^<]*)@(.*).olddomain.org
08:46:22 240891 foo@subolddomain.org in "^([^<]*)@(.*).olddomain.org"? yes (matched "^([^<]*)@(.*).olddomain.org")
08:46:22 240891 ?considering: $1@$2.newdomain.org
08:46:22 240891 ???expanding: $1@$2.newdomain.org
08:46:22 240891 ??????result: foo@su.newdomain.org
08:46:22 240891 LOG: address_rewrite MAIN
08:46:22 240891 "foo@subolddomain.org" from env-to rewritten as "foo@su.newdomain.org" by rule 1
env-to: foo@su.newdomain.org
08:46:22 240891 search_tidyup called
08:46:22 240891 >>>>>>>>>>>>>>>> Exim pid=240891 (fresh-exec) terminating
with rc=0 >>>>>>>>>>>>>>>>

--
Andrew C. Aitchison Kendal, UK
andrew@aitchison.me.uk
--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Problems with rewriting a domain [ In reply to ]
On 8/10/22 09:51, Andrew C Aitchison wrote:

> the command, including any surrounding angle brackets.

Argh, RTFM :(

> So $1 *does* include the opening "<" which is why you had to add the ">"
>
> The rule
>     ^([^<]*)@(.*)\\.olddomain\\.org $1@$2.newdomain.org TS
> seems to work for me.

I still had problems, with your suggested [^<]
Rewriting was OK, but my routing still was unhappy.
Anyway I ended up with

^(.*)@(.*)\\.olddomain\\.org(>?) $1@$2.newdomain.org$3 TS


> Without the doubled slash:
>     ^([^<]*)@(.*)\.olddomain\.org $1@$2.newdomain.org TS
> we would also rewrite foo@subolddomain.org as foo@su.newdomain.org

Thanks for the hint about the double slash.
But since I have no MX on "subolddomain.org" this more a cosmetic problem ;-)

Thanks for your help,
Olaf



--
Karlsruher Institut für Technologie (KIT)
Steinbuch Centre for Computing (SCC)

Dipl.-Geophys. Olaf Hopp

Zirkel 2
Gebäude 20.21, Raum 316
76131 Karlsruhe

Telefon: +49 721 608-48009
E-Mail: Olaf.Hopp@kit.edu
Web: www.scc.kit.edu

Sitz der Körperschaft:
Kaiserstraße 12, 76131 Karlsruhe

KIT - Die Forschungsuniversität in der Helmholtz-Gemeinschaft