Re: [exim] help with redirect router and filter after header…

Top Page
Delete this message
Reply to this message
Author: Alex Roman
Date:  
To: exim-users
Subject: Re: [exim] help with redirect router and filter after header rewrite
Hi Dean,

Many thanks for the reply. Sounds promising but (although I haven't
tried it out) the problem I see which I reported before is that by the
time routers are executed, the address will have already been rewritten
by the global rewrite.

What I need is to both (a) rewrite the address
user+gmail.com+onbehalf@??? into user@??? and send it
along to gmail.com and (b) send a copy of the same email to
admin@???.

I'll post again after I fiddling more taking into account your and
John's suggestions.

Thanks again both,
Alex.


On 4-Jul-13 3:57 pm, Dean Brooks wrote:
> Hi,
>
> A potential simpler way to do this. I tested this on our configuration
> and it worked fine. Note that this doesn't rewrite the headers, but
> rather acts like regular email forwarding.
>
> A single router:
>
> onbehalf-forward:
>    driver = redirect
>    domains = MYDOMAIN.COM
>    local_part_suffix = +onbehalf
>    condition = ${if match{$local_part}{\N^([^+]+)\+([^+]+)\N}}
>    data = ${sg{$local_part}{\\\+}{\@}},admin@???
>    no_verify_sender

>
> When using local_part_suffix, the suffix must be present before the
> router is accepted, and it is stripped from $local_part before any
> other checks, including the condition check. The no_verify_sender
> prevents sender addresses from using this format during ACL verification.
>
> The extra backslashes on the \\\\+ part of the ${sg} function is
> required to make it be treated as a plus sign and not as a regex +.
>
> May not be exactly what you want, but thought I'd throw it out there.
>
> --
> Dean Brooks
> dean@???
>
> On Wed, Jul 03, 2013 at 10:08:28PM +0100, Alex Roman wrote:
>> Hi,
>>
>> I'm hoping a kind soul can help. I did read docs and made some
>> steps, but am a bit stuck and am also new to Exim.
>>
>> Exim is handling mail for mydomain.com. I managed to have emails
>> sent to user+gmail.com+onbehalf@??? delivered to
>> user@??? (yes I know it's prone to open relay). I'm using this
>> global rewrite pattern under "begin rewrite" to do that:
>>
>> \N^([^+]+)\+([^+]+)\+onbehalf@???$\N $1@$2 Ttcb
>>
>> Works fine, messages are indeed delivered to user@???.
>>
>> But I want such emails to also be copied to admin@???,
>> where "admin" is an alias for "root" in /etc/aliases. This is where
>> I'm stuck.
>>
>> I tried with a redirect router:
>>
>> onbehalf:
>>      debug_print = "R: copy onbehalf messages"
>>      driver = redirect
>>      data = #Exim filter\n\
>>          if "$h_to:" contains "+onbehalf"\n\
>>          then deliver admin@???\n\
>>          endif
>>      allow_filter
>>      #check_local_user
>>      user = root
>>      #unseen

>>
>> According to the debug output, the filter in this router fails
>> because the address has already been rewritten before the router is
>> executed. Doesn't matter if it's the first router after "begin
>> routers" or last.
>>
>> Looking at the debug output, I see that Exim reports adding a useful
>> X-rewrote-original-recipient header:
>>
>>>> Headers after rewriting and local additions:
>> * To: SNIPPED+gmail.com+onbehalf@???
>> T To: SNIPPED@???
>>    Subject: test routing
>> I Message-Id: <E1UuRrd-0005tY-4S@???>
>> * X-rewrote-original-recipient: SNIPPED+gmail.com+onbehalf@???
>> F From: root@???
>>    Date: Wed, 03 Jul 2013 20:33:13 +0200

>>
>> I tried to change the redirect filter to the following:
>>
>>      data = #Exim filter\n\
>>          if "$h_X-rewrote-original-recipient:" contains "+onbehalf"\n\
>>          then deliver admin@???\n\
>>          endif

>>
>> But the debug output reports that X- header to be empty "":
>>
>> --------> onbehalf router <--------
>> local_part=SNIPPED domain=gmail.com
>> R: reply to mydomain.com review invitation
>> calling integru_invitereply router
>> rda_interpret (string): #Exim filter\nif
>> "$h_X-rewrote-original-recipient:" contains "+onbehalf"\nthen
>> deliver admin@???\nendif
>> expanded: #Exim filter
>> if "" contains "+onbehalf"
>> then deliver admin@???
>> endif
>>
>> Any clues would be greatly appreciated.
>>
>> Alex.
>>
>> --
>> ## 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/
>>
>