procmail
[Top] [All Lists]

RE: Changing mail subjects to show recipient

2001-10-14 23:44:05
From: Steve Kemp <steven(_dot_)kemp(_at_)voxar(_dot_)com>

  Ok .. with the benefit of some advice I came up with
 a solution, but its not very pretty:


# Get the recipient.
FROM=`$FORMAIL -xTo:`

# Extract the domain - this should be improved.
# Four processes is too many..
ADDRESSE=`echo $FROM | tr \@ ' ' | awk '{print $2}' | tr \. ' ' | awk
'{print $1}'`


"Not very pretty"?  You ain't kidding.  :-)

I would have a very hard time coming up with any reason ever to
pipe tr through awk through tr through awk.  You can do it all
easily in one process with either awk or sed.  (But you actually
don't even have to leave procmail to do it.)

First, with sed:

 ADDRESSEE=`echo "$FROM" | sed -e 's/.*@//' -e 's/\..*//'`


But let's do it all inside procmail:

  # Get the recipient
  FROM=`$FORMAIL -xTo:`

  :0
  * FROM ?? ()\/[^(_at_)]+$
  * MATCH ?? ^^\/[^.]+
  { ADDRESSEE = $MATCH } 

In the first condition line, we capture to MATCH (via the `\/' token) the 
value of everything following the `@' until the end of $FROM.
In the second condition line, we parse MATCH at the first dot.

-- 
Netcom has imploded.  Please now use NOTnetcom.com for mail.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ex-Netcommies:  Mail "forwards" for free forwarding service!
NOT affiliated with EarthLink, Inc.'s Netcom brand identity.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>