procmail
[Top] [All Lists]

Re: safely passing email to the shell

1999-03-29 16:20:41
Okay, I've solved my own problem after thinking about it for a
bit.  Actually, it was pretty obvious what was happening.  It's
only good form to close this by letting you all know what the
problem was, though.

To recap, I forward a copy of any non-mailing-list incoming mail 
to a perl script with:
 
----------------- v v cut here v v -------------------------------
:0 ci
* $ !^$list_header
| /home/mshaw/bin/mailnotify -number 5981529 -after 7 -before 18 -days MTWRF
----------------- ^ ^ cut here ^ ^ -------------------------------

and that script forwards the message text to a pager.  I was getting
errors from mailstat when that text included characters that have
special meaning to the shell, however.

Well, as era pointed out in email to me, there's nothing in that 
recipe that obviously involves the shell, but as it turns out I had 
forgotten exactly *how* the text gets to the pager.  The mailnotify 
script was written a few months ago, after all, which might as well 
be an eternity to an old man like myself.  :)

Here's the business end of mailnotify:

system("/home/mshaw/bin/pager -number $number -text \"$text\"");

where the 'pager' script is yet another perl script I wrote a bit
more than a year ago, $number is my pager number and $text contains 
the first dozen or so lines of the email message.  What pager (the
script) does is rework the text into a really goofy format required 
by the pager (the communications device) email link -- so you can
see that I can't just forward email to the pager email link, it has
to go through all this processing....

Well, obviously any special characters in $text are going to be
seen by the shell.  And that seems to have been my problem.  For-
tunately, when I wrote the pager script, I included a feature that
would take the text intended for transmission from a file rather
than from the command line, so all I had to do to fix mailnotify
was write $text to a temporary file, then call 'pager' with

system("/home/mshaw/bin/pager -number $number -file $tempfile");

I've tested this with some text that consistently causes errors with 
the old version of mailnotify, and those errors do not occur with the
new version.

Whew! 

Well, thanks for putting up with me....

Best Regards,
Mark Shaw <mshaw(_at_)ti(_dot_)com>