procmail
[Top] [All Lists]

Re: passing a score value to a program

1997-03-21 19:03:24
Robert Brown asked,

|  > Ken Marsh asked,
|  > 
|  > | How would I use the $= withing procmail (or would I have  to
|  > | pass it to another program) to use it's value?

| I would like to pass the score value to a program, but it doesn't work for
| me.  I'm getting "variable syntax". 

That's an error message from the shell that your recipe invokes.  I've
explained this before, fairly recently.

| Basically, I'm doing things like this:
| 
| :0
| *500^0 ^TOfoo(_at_)bar\(_dot_)com
| |formail -I "X-myhdr: foo(_at_)bar" | procmail_print $=
| 
| I think the prob is that the $= is after the "|". 

The problem is that $= is on the same line as the second pipe symbol.  You'd
have the same trouble if "$=" occurred first.  The second pipe is a character
from $SHELLMETAS, and you need it that way this time because you need a shell
to handle the piping.

| If I do something like:
| 
| :0
| *500^0 ^TOfoo(_at_)bar\(_dot_)com
| |echo $=
| 
| It works fine.

Right.  That action line has no characters from $SHELLMETAS (the opening
pipe symbol doesn't count) so procmail runs it itself.  (Note that procmail
invokes the /bin/echo executable [or whatever it finds in $PATH] for that,
not the sort of echo facility built into most shells.)

As I've posted before, to pass a special variable to a program that will
be invoked by a shell (rather than directly by procmail) you need to save
it in a regular variable first, which procmail will export.

| Is the score stored in any other "normal" named variable besides $=?

Not automatically (unlike $-, which is always mirrored in $LASTFOLDER except
when you have changed or unset LASTFOLDER since the last time $- was copied
into it).  You have to store it yourself:

  :0
  * 500^0 ^TOfoo(_at_)bar\(_dot_)com
  {
   SCORE = $=
  
   :0
   |formail -I "X-myhdr: foo(_at_)bar" | procmail_print $SCORE
  }

or if that is the final delivery of such a message, you can avoid using
characters from $SHELLMETAS by filtering instead of piping:

  :0fwh
  * 500^0 ^TOfoo(_at_)bar\(_dot_)com
  | formail -I "X-myhdr: foo(_at_)bar"
   :0A
   | procmail_print $=

In that case, the action containing "$=" is run by procmail itself without
invoking a shell, so procmail gets to interpret "$=".

I hope that Robert's actual code, though, is more complicated than that,
because there are only two possibilities with this example: the score is 500
or the action is not executed at all.  So he doesn't need to save the score
at all if this is all he's doing; he can do this more simply:

  :0
  * ^TOfoo(_at_)bar\(_dot_)com
  | formail -I "X-mydr: foo(_at_)bar" | procmail_print 500