Subject: Re: What is wrong with this rule?

From: [email-masked] (David W. Tamkin)
Date: Sat, 31 Dec 1994 18:34:14 -0600 (CST)

Robert Nicholson wrote again,

| OK, doesn't procmail always have to be given a condition?

No.  If a recipe is to be run unconditionally, all you need is the 0 on the
flag line.  The recipe will run on any letter for which procmail reaches that
part of the rcfile.

| The only reason I need the { } at all is to have scope for the FROM
| assignment.

Two comments: an assignment between recipes operates on all mail (provided
that procmail reads that part of the rcfile) and, if it uses backquotes,
receives the entire text -- head and body -- as its stdin.

Second, the variable capture syntax can avoid the braces if you prefer.

 :0  flags
 * condition
 {
  variable=`command`
 }

is equivalent to this

 :0  flags
 * condition
 variable=| command

unless you wanted to spawn a clone, for which you need the braces.

| Can it take just a simple * ?

I assume that the question mark is grammatical puncuation there and not part
of what you intend to write.  Yes, a simple asterisk will mean a null
condition, and null conditions always pass.  If

 :0
 *
 unconditional_action

makes you feel better than

 :0
 unconditional_action

then go ahead; it's not that much slower.

When Michael Corrigan suggested,

| >How about simply:
| >STUPIDUSERS=$HOME/Mail/.stupidusers
| >FROM="`formail -rx To:`"

Robert wondered,

| Formail doesn't have anything to process here outside of the rule does it?

Yes; backquotes in an assignment between recipes feed the entire text to the
command (at least if there are no SHELLMETAS in the command).

---

From: [email-masked] (David W. Tamkin)
Date: Sat, 31 Dec 1994 22:27:31 -0600 (CST)

| Ok, I've now got.
| 
| STUPIDUSERS=$HOME/Mail/.stupidusers
| 
| :
| *
| {
|     :0h
|     FROM=|formail -rx To:
| 
|     :0f
|     * ? fgrep -e "$FROM" $STUPIDUSERS >/dev/null
|     | formail -I Message-ID: ; echo "   Removed Message-ID" >/dev/console;
| }

You still don't need the braces.  All mail is going through it.  If you'd
like to set it off typographically so that it looks like a single unit when
you read your rcfile, you can still indent it:

 STUPIDUSERS=$HOME/Mail/.stupidusers
 # if MAILDIR is already set to $HOME/Mail, you don't need the full path,
 # because then you're cd'ed there already

	:0h
	FROM=|formail -rzx To:

	:0hf # and probably W
	* ? fgrep -e "$FROM" $STUPIDUSERS >/dev/null
	| formail -I Message-ID: ; echo "   Removed Message-ID" >/dev/console
	# one semicolon (or one greater-than sign) is enough to force a shell

| Is this more efficient now that I'm only putting the header into
| formail?

Yes.  You could also, if you're running 3.10, use the -z option of formail
to get rid of that leading space that -x keeps without -z.  It also helps
to filter only the head when you remove the Message-ID.

And I think that stdout of an exit code condition goes to /dev/null by
default, so that may be unnecessary; if not, your version of fgrep may have
an option (such as -s or -q) that suppresses all output and just returns the
proper exit code.  Using that would be cheaper than redirecting output.

David W. Tamkin  Box 3284  Skokie, Illinois  60076-6284
[email-masked]    MCI Mail: 426-1818   +1 312 714 5610