procmail
[Top] [All Lists]

Re: Returning a value to a recipe

2009-03-09 05:12:41
On Mon, Mar 09, 2009 at 09:02:17AM +0100, Dallman Ross wrote:
Ed Blackman wrote Monday, March 09, 2009 7:44:
AWK=/usr/bin/awk
KEY=`formail -x X-The-Header:`  # or whatever
VAL=`$AWK "BEGIN { FS=\":\" } /^$KEY:/ { print \$2 }" < $HOME/valuemap`

:0
* VAL ?? .+                      # key matched
{
   # use $VAL somehow
}

Untested, but should at least get you on the path.

Oh, my.

Let me first say that that's clever -- for the shell.  I have to
tip my hat these days to anybody who remembers enough awk to do
something useful.  I myself like to dust off my awk and brush it up
occasionally too.

Thank you. Problems of the class "I want to extract a subset of regular fields from a subset of regular records" almost immediately make me think of awk or perl, and perl is usually considered too heavyweight for procmail.

But that said, this is procmail, and procmail is perfectly capable
of doing the greater part of what the OP wanted without any of
these shell gyrations.  So let's stick to showing how to do this in
procmail -- where, in any case, it ensues much more efficiently.
We'll add a bit of fgrep as the OP inferred we might want to do.
We don't even need formail here.

Interesting solution. I'd probably still prefer the awk solution unless performance is a problem, but that's because awk is idiomatic to me, and procmail solutions aren't (that's part of the reason I'm on the list, so I can speak procmail more fluently).

Btw, let me start by wondering why you are bothering to define
$AWK here, or why the OP (or rather the web-page source at which
he found the whitelist example) is bothering to define $FGREP.  I
would expect /usr/bin/awk to be the awk in the default path you
have compiled into your procmail; and I would expect /usr/bin/fgrep
to be the fgrep in the default path compiled into procmail.

I agree it's overkill in this instance, but I tend to make variables for external programs because there have been times when I wanted to make changes to all the call sites of a program in my .procmailrc (program was installed by hand, now comes with my distribution, or the program had a version bump and needs different arguments). Making the change in one place is easier than finding the ten places it is called and changing things there.

Ed

Attachment: signature.txt
Description: Digital signature

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail