Re: [exim] Problems with rewriting a domain

Góra strony
Delete this message
Reply to this message
Autor: Andrew C Aitchison
Data:  
Dla: Olaf.Hopp
CC: exim users
Temat: Re: [exim] Problems with rewriting a domain
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@??? as foo@???


#exim4 -C /tmp/werdna/exim.rewrite.test2 -d+all -brw "Fred Flintstone <foo@???>"
         ...        ...        ...
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@???>
     from: Fred Flintstone <foo@???>
       to: Fred Flintstone <foo@???>
       cc: Fred Flintstone <foo@???>
      bcc: Fred Flintstone <foo@???>
reply-to: Fred Flintstone <foo@???>
env-from: foo@???
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@??? pattern=^([^<]*)@(.*).olddomain.org
08:46:22 240891 foo@??? 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@???
08:46:22 240891 LOG: address_rewrite MAIN
08:46:22 240891   "foo@???" from env-to rewritten as "foo@???" by rule 1
   env-to: foo@???
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@???