On Fri, 29 Aug 2003, Jason Stubbs wrote:
> #!/bin/sh
>
> TMP1=`mktemp /tmp/mailcheck.XXXXXX`
> TMP2=`mktemp /tmp/mailcheck.XXXXXX`
>
> cat /dev/stdin > $TMP1
> grep Date: $TMP1 | head -n 1 > $TMP2
> grep From: $TMP1 | head -n 1 >> $TMP2
> grep Subject: $TMP1 | head -n 1 >> $TMP2
> cat $TMP2 | mail -s "Mail Notification" $1
> cat $TMP1
>
> rm $TMP1
> rm $TMP2
>
>
> In ~/.procmailrc, I have put:
>
> :0fw
> * ^X-Spam-Status: No*
> | /usr/local/bin/notify jason
>
>
> However, *any* mail that goes through it comes out blank! Whether it is spam
> or not! The script works fine from the shell so it's got to be something
> wrong with how I'm using procmail. I can't see where the error is though. I
> checked the $TMP files and both come out blank, so it seems that procmail is
> not piping the mail through the filter. Either way, it doesn't explain why
> spam is being corrupted as well. Can anyone help? Pretty please??
It's been a little while since I've done something like this, but I think
I've got it. 'cat /dev/stdin' is the wrong way to read input to a
command. Also, I'd just save everything in a variable, and avoid disk
access. And make sure you're only sending the header. I believe there's
an 'h' flag for procmail to do this. Scanning every line of a 5MB email
will be a bit of a performance loss.
#!/bin/bash
notify_msg=""
while read header_line
do
if `echo $header_line | egrep -q '^(From|Date|Subject)'`
then
notify_msg="${notify_msg}${header_line}\n"
fi
done
echo -e $notify_msg | mail -s "Mail Notification" $1
If you don't understand the grep line, read the entire grep man page top
to bottom. It will be one of the more useful things you do.
Hope this helps.
--
Caution: Product will be hot after heating
--
[EMAIL PROTECTED] mailing list