procmail
[Top] [All Lists]

RE: Special characters from recipe not escaped for the shell

2003-12-29 12:00:11


-----Original Message-----
From: Lee Hoffner
Sent: Monday, December 29, 2003 7:16 AM
[...]
How can I modify my recipe so
that & is escaped for the shell? (And which man page would list
other special
characters that I should probably also address?) Recipe below:

:0
* !? egrep -is -f /home/lhoffner/goodhtml.txt
* ^Content-(Transer-Encoding: base64|type:
(text/html|multipart/(mixed|alternative)))
{
      SPAMMER=`formail -rzx "To:"`
      SUB=`formail -zx "Subject:"`
      TRAP= 'echo '`date`': HTML message from '$SPAMMER' with
subject '$SUB' was
filed in SPAM. '$SPAMMER' was added to the spammer list. >>delete.log
echo '$SPAMMER' >>spammerlist'

      :0:
      $MAILDIR/SPAM
}


See "man procmailrc" and "man sh". Procmail follows 'sh' shell quoting
conventions.

A way to approach this to first decide upon the exact lines that you want to
execute in 'sh'. A good way to do this is to run 'sh' and play with the
expressions until you get them right. For example,

$ SPAMMER='Spam R US <spamrus(_at_)spam(_dot_)com>'
$ SUBJ='Make big $$$'\!
$ echo $SPAMMER
Spam R US <spamrus(_at_)spam(_dot_)com>
$ echo $SUBJ
Make big $$$!
$ echo "`date`: HTML message from '$SPAMMER' with subject '$SUBJ' was filed
in SPAM. '$SPAMMER' was added to the spammer list."
Mon Dec 29 10:16:20 PST 2003: HTML message from 'Spam R US
<spamrus(_at_)spam(_dot_)com>' with subject 'Make big $$$!' was filed in SPAM. 
'Spam R
US <spamrus(_at_)spam(_dot_)com>' was added to the spammer list.

Above, in the initial assignment to SUBJ, I used single quotes because that
is
an easy way to enter metacharacters like $ and ! without quoting them
further.
But, in the final echo statement, I used double quotes because I want to
substitute
the various variables, and I want to output single quotes without having to
further quote them. If you start out using single quotes and you want to
then
output a single quote, you have to first escape to double quotes, so you get
strange looking things like:

$ echo 'Santa said '"'"'Ho, Ho, Ho'\!"'"
Santa said 'Ho, Ho, Ho!'

Keep in mind that you'll need to further escape this at the procmail level,
so whatever you end up with won't be pretty.

Now that we know what we want to pass to the shell, we need to set TRAP
appropriately in procmail. Let's try it out in 'sh' first.

$ TRAP='echo "`date`: HTML message from '"'"'$SPAMMER'"'"' with sub
ject '"'"'$SUBJ'"'"' was filed in SPAM. '"'"'$SPAMMER'"'"'was added to the
spammer list."'
$ echo $TRAP
echo "`date`: HTML message from '$SPAMMER' with subject '$SUBJ' was filed in
SPAM. '$SPAMMER'was added to the spammer list."

We've got what we want in TRAP. So, this is one part of the TRAP setting
you'd
use:

TRAP='echo "`date`: HTML message from '"'"'$SPAMMER'"'"' with sub
ject '"'"'$SUBJ'"'"' was filed in SPAM. '"'"'$SPAMMER'"'"'was added to the
spammer list."'

Basically, inside single quotes at the procmail level, any place that you
want to pass through a single quote, you need to enter '"'"'.



_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail