procmail
[Top] [All Lists]

Re: formail can't see $_

2004-06-22 14:51:54
Jim, Jim, Jim ...

My mailer would destroy the long lines in Jim's excerpts, so I'm going to have to break them badly for this message before it gets a chance to break them catastrophically.

Jim Osborn wrote:
        
    :0 fwh
    | formail -A "X-Diagnostic: `basename $_`: \
>        before `basename ${Spamsummaryrc}`; `date`"
    :0 fwh
    | formail -A "X-Diagnostic: `basename $_`: \
>        spamscore is: \"$SPAMSCORE\""

No idea why you don't combine those two, but let's look at the action lines. The first one includes a semicolon, which is in $SHELLMETAS. The second has no characters from $SHELLMETAS. That means that procmail will invoke a shell to run the first one but will run the second one iteslf.

Check your logfile:

procmail: Executing " formail -A "X-Diagnostic: `basename $_`: \
> before `basename ${Spamsummaryrc}`; `date`""

See how the spaces are preserved; procmail fed the entire command string as one argument to $SHELL $SHELLFLAGS.

> There are no Executing lines for the basename or date components.

Indeed not; all procmail executed was $SHELL, and the shell did not log "Executing" entries to procmail's logfile when it invoked basename or date.

procmail: Executing "formail,-A, \
> X-Diagnostic: spamrc: spamscore is: "NOSUBJECT, BCC, MSGID, NOBODY""

See the commas. Procmail split the line into arguments and invoked formail directly.

Does the format of that log output look familiar to anyone?

Yup.

Now, here's the rest of the explanation. When procmail hands a command line over to $SHELL, procmail doesn't do any command or variable substitution. Note how the first log entry line has `basename $_` with the backquotes and dollar sign intact, while the second one has that resolved to "spamrc" before logging.

So in the second one $_ means what procmail thinks it means (the current rcfile), while in the first one, $_ means what the shell thinks. I don't know what shell you're using, but for example, in ksh $_ means the last argument of the previous command. When you're starting a fresh shell invocation, that previous command is likely to be something from .kshrc.

Try this (unfold it if you like):

RCFILE = $_

:0 fwh
| formail -A "X-Diagnostic: `basename $RCFILE`: \
before `basename ${Spamsummaryrc}`; `date`"
:0 fwh
| formail -A "X-Diagnostic: `basename $RCFILE`: \
spamscore is: \"$SPAMSCORE\""

The lesson: never use special variables as command arguments.


____________________________________________________________
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

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