procmail
[Top] [All Lists]

Re: What's the better way?

2002-09-22 11:11:30
Paul asked which is preferable:

| Inside backquotes:
|
| BOGOFACTOR="`/usr/local/bin/bogofilter -v 2>/dev/null | tail -1`"
| :0 fhw
| * BOGOFACTOR ?? ().*Spamicity.of.\/[0-9].+
| | formail -A "X-bogofactor: $MATCH

You're missing a closing quote there (and again where you repeated the formail
command), but let's keep moving:

| or using chained recipes:
|
| :0 hbw
| BOGOFACTOR=| (/usr/local/bin/bogofilter -v | tail -1)

The parentheses are unnecessary (so are `hb'; `hb' is the default).

| :0 afhw
| * BOGOFACTOR ?? ()Spamicity.of.\/[0-9].+
| | formail -A "X-bogofactor: $MATCH

My guess is that, since with chaining will allow procmail to skip running
formail for nothing when bogofilter has exited badly, it's preferable;
however, the real difference, if any exists, probably is in the backquote
assignment versus the variable capture format.

| And while we're at it, can someone explain how I parse multiline output
| that's been assigned to a variable, so I can skip the `| tail -1`?  I
| *thought* that .* should match newlines as well, but it doesn't seem to.

No, it doesn't and it shouldn't.  But unless "Spamicity.of." plus some digits
can occur on more than one line of bogofilter's output, you don't need to.
Procmail will happily scan a multiline variable just as it happily scans
complete heads, complete bodies, and complete messages:

 :0w
 BOGOFACTOR=| /usr/local/bin/bogofilter -v

 :0afhw
 * BOGOFACTOR ?? Spamicity.of.\/[0-9]+
 | formail -A "X-bogofactor: $MATCH"

If the string can occur more than once in $BOGOFACTOR and you need to make
sure that extract from the bottommost,

 :0w
 BOGOFACTOR=| /usr/local/bin/bogofilter -v

 :0afhw
 * 1^1 BOGOFACTOR ?? Spamicity.of.\/[0-9]+
 | formail -A "X-bogofactor: $MATCH"

That addresses the problem more than it does the question, but it should help.



_______________________________________________
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>