procmail
[Top] [All Lists]

Re: Pipe to cat somehow ruins previous recipe?? I'm lost.

1998-03-23 21:47:06
Ken Hooper <bighouse(_at_)type2(_dot_)com> writes:
Could somebody help with this? It's a "test" version of a script we use to
let messages from non-subscribers pass through a moderator and on to the
list. The problem is the recipe that pipes to cat. If that recipe is
present, it works, but the previous "munge up the header" recipe does not.
If the cat recipe is not present, the munge recipe works fine.
...
  # Let's put a short memo at the top of the body to remind people
  # to reply to the original author

:0 wfha
| cat reply.txt

This recipe feeds the header of the message into cat, which ignores it
and instead spits out the contents of "reply.txt", which then becomes
the new header, thus losing the previous header.  The cat command only
passes through it's stdin if you tell it to, by giving it the argument
"-":

        :0 wfha
        | cat - reply.txt


...
Also, how could I have cat expand the variable in the text? If reply.txt says:

      Please reply to $REPLYTO

what would the procmail be, this?:

| $ cat reply.txt

Nope.  You're mixing the syntax for conditions which that for actions.
That would cause the shell to look for a program named '$', which it
won't find.  To substitute things like $REPLYTO you'll need to use a
program like sed or perl.  If you know ahead of time what variables are
going to be involved, I would use sed.  If you want to be able to use
_any_ environment variables, then you'll need perl or something like it:

        | cat -; perl -pe 's:\$(\w+):${$1}:eg' reply.txt

(You'll need perl version 5 for that command to work, but if you only
have perl version 4, UPGRADE.)  Note that you probably don't want to
do substitution on the header to avoid problems with message-ids and
the like.  You can eliminate the cat using a more complicated perl command:

        | perl -pe 'BEGIN{while(<STDIN>){print}} s:\$(\w+):${$1}:eg' reply.txt


Philip Guenther