Re: [exim] Extracting address from a From header

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Phillip Carroll
Ημερομηνία:  
Προς: exim-users
Αντικείμενο: Re: [exim] Extracting address from a From header
On 8/19/2016 5:52 AM, Mike Brudenell wrote:
> I think I've got a workaround by using *sg* to look for the final <…> (if
> there is one) in the value of $h_from: and stripping off everything before
> it:
>
> ${domain:${sg {$h_from:} {^.*<([^<]*)> *\$} {\$1}}}


I agree sg is the right approach. You can't really depend on anything
being per spec.

I didn't understand the purpose of the fragment '[^<]' in your pattern.
Possibly I just haven't written enough regex for exim.

I would tend to write something like
${sg {$h_from:} {^\N(.*)?\<(.*)?\>$\N} {[D1]\$1[D2]\$2}}'
This makes use of patterned substitution strings to allow for easier
parsing of the actual case, and \N to avoid expansions.

[~]#exim -be '${sg {george@???} {^\N(.*)?\<(.*)?\>$\N}
{[D1]\$1[D2]\$2}}'
george@???

[~]#exim -be '${sg {<george@???>} {^\N(.*)?\<(.*)?\>$\N}
{[D1]\$1[D2]\$2}}'
[D1][D2]george@???

[~]#exim -be '${sg {george@??? <george@???>}
{^\N(.*)?\<(.*)?\>$\N} {[D1]\$1[D2]\$2}}'
[D1]george@??? [D2]george@???

[~]#exim -be '${sg {"george peabody" <george@???>}
{^\N(.*)?\<(.*)?\>$\N} {[D1]\$1[D2]\$2}}'
[D1]"george peabody" [D2]george@???

- Phil Carroll