Re: [exim] Rewrite FROM address

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Chris Edwards
Datum:  
To: exim-users@exim.org
Alte Treads: Re: [exim] Rewrite FROM address
Betreff: Re: [exim] Rewrite FROM address
Earlier this year we had a discussion on automagically setting From header
according to which mailing list is being posted to.

Phil helpfully suggested (in message quoted below) a transport with a
rewrite rule that uses the recipient address as key to a lookup, the
result of which being used to replace the From header on the way out.

The (untested) transport Phil suggested looked like (modulo line wraps):

|   max_rcpt = 1
|   headers_rewrite = *@* 
|    ${lookup{$local_part@$domain}lsearch{/etc/mail/subaddress-maps/$1@$2}{$value}fail} f


Some months later, I'm trying to implement something like this, but I've
got stuck. As far as I can tell, within a rewrite rule, $local_part
actually refers to the address being rewritten, which for an 'f' rewrite
rule, means the *sender address*. Which is no use here :-(

(Earlier in his post, Phil explained he was temporarily confused about
this distinction - but thought he had it sorted later. But now I'm
confused!)

So, is there a way to access the recipient address inside an 'f' rewrite
rule ? At least, inside a transport when there's only 1 recipient.
Kinda looks like not, so I probably need a rethink.

Thanks for any clue.

Chris

PS - FWIW I'm not interested in mangling the return-path, as my lists only
seem to care about the From header.




On Sun, 9 Mar 2008, Phil Pennock wrote:

| Date: Sun, 9 Mar 2008 03:54:04 -0700
| From: Phil Pennock <exim-users@???>
| Reply-To: exim-users@???
| To: Luke Sheldrick <luke@???>
| Cc: "exim-users@???" <exim-users@???>
| Subject: 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
| 
|