Re: [exim] Extracting address from a From header

Góra strony
Delete this message
Reply to this message
Autor: Mike Brudenell
Data:  
Dla: Exim Users
Temat: Re: [exim] Extracting address from a From header
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}}}


Can anyone see any problems with doing to?

By the way, the reason for doing this is to compare the domains from the
RFC5321.MailFrom and RFC5322.From addresses so I can log when they differ
and pick up any systems on-site that aren't playing ball nicely with
DMARC-enhanced SPF tests. (Mind, I guess I should also be tackling
malformed RFC5322.From addresses from such systems too… Groan!)

Cheers,
Mike B-)


On 19 August 2016 at 13:13, Mike Brudenell <mike.brudenell@???>
wrote:

> Hi, all -
>
> A little Friday afternoon conundrum…
>
> I'm wanting to extract the domain part of the address given in the value
> of a message's From header. I initially thought this would suffice:
>
> ${domain:$h_From:}
>
>
> And indeed it works for well-formed addresses, as shown by:
>
> % exim -be '${domain:pmb1@???}'
> york.ac.uk
> % exim -be '${domain:Mike Brudenell <pmb1@???>}'
> york.ac.uk
>
>
> But of course some client software sends out Form headers that are
> malformed according to the RFC, such as
>
> From: somename@??? <somename@???>
>
>
> This is malformed because the presence of the "@" in the leading
> display-name field means it should be enclosed within quotation marks. And
> because it's malformed Exim's ${domain:…} returns the empty string.
>
> Does anyone have any magic to extract the domain from such a "malformed,
> but not terribly badly malformed" address? (I'm loathe to rely on
> extracting the thing between angle-brackets as they might appear in the
> display-name field.)
>
> I think I'm asking the impossible and am likely to be shot down for trying
> to parse invalid addresses, but just in case… any ideas?
>
> Cheers,
> Mike B-)
>
> --
> Systems Administrator & Change Manager
> IT Services, University of York, Heslington, York YO10 5DD, UK
> Tel: +44-(0)1904-323811
>
> Web: www.york.ac.uk/it-services
> Disclaimer: www.york.ac.uk/docs/disclaimer/email.htm
>




--
Systems Administrator & Change Manager
IT Services, University of York, Heslington, York YO10 5DD, UK
Tel: +44-(0)1904-323811

Web: www.york.ac.uk/it-services
Disclaimer: www.york.ac.uk/docs/disclaimer/email.htm