Re: [exim] Rewrite FROM address

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Phil Pennock
Ημερομηνία:  
Προς: Luke Sheldrick
Υ/ο: exim-users@exim.org
Καινούρια Θέματα: Re: [exim] Rewrite FROM address
Αντικείμενο: Re: [exim] Rewrite FROM address
On 2008-03-08 at 16:33 +0000, Luke Sheldrick wrote:
> Howrver have changed $1 for $local_part, and it does work, however there are a couple of glitches.


Okay, again it's after 3am and I have a couple of glasses of wine in me,
but I see why I used $1 before, not $local_part. $local_part is the
recipient local part, $1 was matched against the sender.

In the header rewrite, use $1 as originally stated.
In the return_path setting, instead of $1 or $local_part use
$sender_address_local_part -- this just gets longer and longer. ;)

> Also if exim cannot find the txt file for a user in the subaddress
> folder (or redir as I called it) it is failing the messages.. Is there
> a way to get around this, i.e. If there is now file, to keep it as it
> were?


Oh. If the file doesn't exist, it's probably being treated as an
unforced failure because the lookup didn't exist, not as a forced
failure (key not found so using the "fail" clause).

Oh, and the return_path wasn't setting the domain.

Okay, so now we're up to:

return_path = ${if exists {/etc/mail/subaddres-maps/$sender_address_local_part} \
{${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$sender_address_local_part}{$value@$sender_address_domain}fail}}\
{$return_path}}

Having fun yet? :^)

> And one more :P could we rewrite the script slightly, so it rewrites
> the complete email address? As at the moment will only do it for
> an0key.co.uk, and whilst there is only three domains on this setup
> (i.e. My home / test env) would be good if in the redir folder I could
> put luke@??? for example?


Hey, at last one which isn't my fault, but just something not originally
asked for. Cool.

Okay, for the return_path this makes it shorter, since instead of
$sender_address_local_part you can just use $sender_address (in both
places).

For the headers_rewrite, use *@* and then $2 to refer to the domain;
once in the filename ($1@$2) and once when constructing the address.

So, if I'm not mistaken (again) this should be:

  max_rcpt = 1
  headers_rewrite = *@* ${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$1@$2}{$value}fail}@$2 f
  return_path = ${if exists {/etc/mail/subaddres-maps/$sender_address} \
    {${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$sender_address}{$value@$sender_address_domain}fail}}\
    {$return_path}}


Note that this assumes that the domain remains unchanged. If you want
to be able to change the domain too, then include the domain in the
value in the lookup file instead and use:

  max_rcpt = 1
  headers_rewrite = *@* ${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$1@$2}{$value}fail} f
  return_path = ${if exists {/etc/mail/subaddres-maps/$sender_address} \
    {${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$sender_address}{$value}fail}}\
    {$return_path}}


Note further that this still remains untested by me. Caveat emptor.

Regards,
-Phil