Re: [exim] Rewriting envelope from to header From

Top Page
Delete this message
Reply to this message
Author: Frank Richter
Date:  
To: exim-users
Subject: Re: [exim] Rewriting envelope from to header From
Am 13.07.2017 um 00:50 schrieb Heiko Schlittermann via Exim-users:
> Hi,
>
> Frank Richter <frank.richter@???> (Mi 12 Jul 2017 15:46:31 CEST):
> …
>>>> From: Frank Richter
>>>> I'd like to rewrite envelope from "apache@*.mydomain" to the address in
>>>> header From.
>>>> I tried it according to https://github.com/Exim/exim/wiki/Q0801 with this
>>>> rewrite rule:
>>>>
>>>> apache@*.mydomain ${sg{$h_from:}{^.*<(.*)>}{\$1}} Ffrs
> seems complicated. Lena's approach is better (using the ${address:…}
> operator.


Yes, thanks for this.
>>> According to
>>> https://www.exim.org/exim-html-current/doc/html/spec_html/ch-address_rewriting.html
>>> (untested):
>>>
>>> apache@*.mydomain ${address:$rh_from:} F
>>>
>>> I suspect that the wiki page is wrong, but I'm not sure.
>> Unfortunately, this doesn't work either. Same error message:
>> Rewrite of apache@??? yielded unparseable address: empty
>> address in address
>>
>> I'm sendig with: swaks --to ... --from apache@??? --server
>> ... --data /tmp/mail
> The rules from the rewrite section are applied at the time the
> message is receveived (as written in the spec file). So, at the time
> the envelope gets rewritten, the $h_from: isn't set yet.


Ok, that's true. So I guess, it should be added to
https://github.com/Exim/exim/wiki/Q0801

> Probably you need to rewrite at transport time. But … the envelope
> sender can't be rewritten at transport time, transports have a
> "return_path" option for modification of the envelope sender.


Your and Jeremy's and Jan's comments lead me to this:

begin transports
…
smtp:
   driver = smtp
   return_path = ${if and {{match {$return_path}{^apache@.*\.tu-chemnitz\.de\$}}\
                           {match {${domain:${address:$h_from:}}}{.*\.tu-chemnitz\.de\$}}}\
                 {${address:$h_from:}}fail}


I tried some cases and abuse scenarios - it works as aspected: Rewrite
Envelope From, if the header From: is a local address.
Would it be possible to check the domain with a defined domainlist?

But anyway, I'll try to expand the test to check, if header From: is a valid
local address.

Many thanks,
Frank
Chemnitz University of Technology, Germany