Re: [exim] Extract email address from From header

Top Page
Delete this message
Reply to this message
Author: Elliot Murdock
Date:  
To: exim-users
Subject: Re: [exim] Extract email address from From header
Hello!

Where is the mention of the ${addresses:$h_from:} variable expansion?
I couldn't find it in the variable index at
http://www.exim.org/exim-html-current/doc/html/spec_html/ch58.html

Thanks,
Elliot

On Fri, Oct 29, 2010 at 8:02 AM, Phil Pennock <exim-users@???> wrote:
> On 2010-10-29 at 03:19 +0200, Elliot Murdock wrote:
>> However, the $header_From variable returns not only the email address
>> but any names associated with it.  For example,
>> From: John Doe <johndoe@???> gives John Doe <johndoe@???>
>>
>> I would need a regex to extract the email address.
>
> That would be a case of having a hammer and thinking you're holding
> nails.  ;)  It's also a world of pain, because while matching the bit of
> an email address inside the <...> is doable in a regexp, handling the
> whole display format with just a regex is an exercise in masochism.  It
> can be done, but it's a bit like proving traditional vi is
> turing-complete and then using it to solve problems.
>
> The ${addresses:...} expansion operator will help you.  It extracts the
> addresses from a string, just as you want.
>
> Note that the From: header is defined to be able to take 1 or more
> addresses.
>
> So  ${addresses:$h_from:}  will work, as long as there's just one
> address in From.  It generates a colon-separated list of the email
> addresses, and instances of the list-separator in the data are doubled,
> for escaping.
>
> To reliably get just one email address from From:, if you're happy with
> it being the last such, then:
>  ${reduce{${addresses:$h_from:}}{}{$item}}
>
> -Phil
>