procmail
[Top] [All Lists]

Re: Conditional subject

1997-09-03 12:19:05
Philip Guenther suggested to W. Wesley Groleau,

|       | formail -Yr${SUBJECT:+i'Subject: }${SUBJECT}${SUBJECT:+'} \

That would make me nervous.  I wouldn't want to bet on whether the braces
or the apostrophes would take precedence (the braces *should*, and given
that the complete action line includes a semicolon, it is the shell's inter-
pretation, not procmail's own, that counts).  This form would worry me less:

        formail -Yr{$SUBJECT:+i "Subject: $SUBJECT"} \

| The solution is to attach this to the -r argument.

You shouldn't have to attach.  This should work properly in any sh-based
shell (and it does when, in the absence of characters from $SHELLMETAS,
procmail runs the command):

        formail -Y -r ${SUBJECT:+-i "Subject: $SUBJECT"} \

If $SUBJECT is null or unset, the expression will evaluate to unquoted
nothingness and not cause the problem that quoted nullity would.  But I
guess that if your shell is that sensible, braces take precedence over
apostrophes inside them, and my only improvement on Philip's suggestion
is comparative brevity.

To answer Wesley's question as I understood it, yes, it is perfectly fine
to do something like this to set the variables in the INCLUDERC to the
particular values they'll need if the INCLUDERC is used at that point:

  :0 condition-related-flags
  * con-
  * di-
  * tions
  { COMMENT="whatever" SUBJECT="whatever" COPY_FOLDER="wherever"
    RESPONSE="whatever" INCLUDERC=autorespond.rc }

Note that unlike some shells, procmail will make assignments from left to
right and RESPONSE will be set before the INCLUDERC is used.  If you don't
want to rely on that, move the INCLUDERC assignment down to a line of its
own (with the right brace ... or you could put the right brace alone on
another line if you like).

I would recommend, though, just in case autorespond.rc gets included more
than once for a message, that at the top of autorespond.rc you give default
values for all the variables, except for $SUBJECT, which you want unset by
default:

  COMMENT=${COMMENT-"standard comment"} # set but null acceptable?
  COPY_FOLDER=${COPY_FOLDER:-$SPAMFOLDER} # set but null is unacceptable
  RESPONSE=${RESPONSE:-"stock response file"} # also unacceptable here

and at the foot of autorespond.rc you unset all those variables, including
SUBJECT, to make sure that the next use of autorespond.rc doesn't accident-
ally inherit the old values.  Exception: if any of those variables is to have
the same value no matter what, regardless of the specific recipe that calls
autorespond.rc, you can set it unconditionally in the main rcfile, not leave
it unchanged in the braces for any particular recipe, and leave it set at the
foot of autorespond.rc.

One last thing:

| >  :0:
| >  * >10000
| >  * !^X-Loop: noloops_for_wwgrol(_at_)fw(_dot_)hac(_dot_)com
| >  { INCLUDERC=autorespond.rc }

Get rid of that second colon; it has nothing to lock and will give you an
error.

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