I have a Procmail rule that uses formail to parse the To: email header to determine the email address the email was sent to:
TO_=`formail -XTo:`
This isn't working, as I'd like ${TO_} to evaluate to "[email protected]", but what I'm getting is "To: firstName lastName".
How can I set an environment variable in a procmail script to the format I'd like?
No, you are extracting the full contents of the
To:header, which should normally look something likeTo: Real Name <[email protected]>. There are many variations, though; it could also be[email protected] (Real Name), for example, though this format is obsolescent.Demo:
If you know that the header contains the address between
<brokets>, you can extract the text between them without usingformailor another external utility.This uses Procmail's special
\/extraction token which assigns the matching text after it into the special internal variableMATCH.Tangentially, if you wanted to extract a header value without the header keyword itself, that would be
with a lowercase
-x.But this still extracts the entire value, i.e.
Real Name <[email protected]>. You could of course add a simplesedscript to extract just the email terminus; but generally speaking, you want to avoid spawning external processes for efficiency reasons.