[exim] Extracting address from a From header

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Mike Brudenell
Date:  
À: Exim Users
Sujet: [exim] Extracting address from a From header
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