Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-30 Thread Jason Stubbs
On Saturday 30 August 2003 14:15, Yorkshire Dave wrote:
> On Fri, 2003-08-29 at 14:50, Jason Stubbs wrote:
> > Hmmm
> >
> > I've called the script notify and changed it as follows:
> >
> > #!/bin/sh
>
> This is probably a silly question but why not just script it straight
> into ~/.procmailrc?

Because I don't know procmail well enough - barely at all, actually - to be 
able to do it straight out. Also, I'd like to get the first x lines of the 
body into the notification message as well. If it's a short e-mail my 
girlfriend may not have to use the computer at all! ;-)

> Oh, and it makes sense to use formail to extract the relevant fields,
> that's what it's for.
> FROM=`formail -xFrom:`
> SUBJ=`formail -xSubject:`
> DATE=`formail -xDate:`

Hmmm. Sounds cleaner but I've only got one stdin. Wouldn't formail want to see 
the entire mail message or at least all of the headers? If so, how could I 
duplicate stdin for each field?

Regards,
Jason

--
[EMAIL PROTECTED] mailing list

Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-30 Thread Yorkshire Dave
On Fri, 2003-08-29 at 14:50, Jason Stubbs wrote:
> Hmmm
> 
> I've called the script notify and changed it as follows:
> 
> #!/bin/sh
> 
This is probably a silly question but why not just script it straight
into ~/.procmailrc? 

Oh, and it makes sense to use formail to extract the relevant fields,
that's what it's for.
FROM=`formail -xFrom:`
SUBJ=`formail -xSubject:`
DATE=`formail -xDate:`

-- 
Yorkshire Dave
Custom rule generator for SpamAssassin.
http://www.wot.no-ip.com/cgi-bin/detoken.pl
top-posters will be tarred and feathered!


-- 
Scanned by MailScanner at wot.no-ip.com


--
[EMAIL PROTECTED] mailing list



Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-30 Thread Marshal Newrock
On Sat, 30 Aug 2003, Jason Stubbs wrote:

> The grep line is fairly easy to understand. I've got to learn regular
> expressions, though. They seem too useful!

That's what I meant.  'man 7 regex' and 'man pcre' for regular regular
expressions and perl compatible regular expressions, respectively.  In
fact, 'apropos pcre' reveals 'pcregrep' which I had not previously known
about.  Also 'man perlre' for using regular expressions in a perl script.
But regardless of what tool you use (grep, sed, perl, etc), learning
regular expressions is definately something you want to do.  But also
learn perl or another scripting language of your choice.  Bash is good for
simple tasks, but sooner or later you'll hit some limitations.

-- 
Caution: Product will be hot after heating


--
[EMAIL PROTECTED] mailing list



Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-30 Thread Jason Stubbs
On Saturday 30 August 2003 03:02, Marshal Newrock wrote:
> 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
>

This script is beautiful! Is helping me on my way to becoming more than a 
mediocre bash 'programmer'. Thanks very much.

> 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.

The grep line is fairly easy to understand. I've got to learn regular 
expressions, though. They seem too useful!

Regards,
Jason

--
[EMAIL PROTECTED] mailing list



Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-29 Thread Marshal Newrock
On Fri, 29 Aug 2003, Jason Stubbs wrote:

> #!/bin/sh
>
> TMP1=`mktemp /tmp/mailcheck.XX`
> TMP2=`mktemp /tmp/mailcheck.XX`
>
> 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



Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-29 Thread Jason Stubbs
Hmmm

I've called the script notify and changed it as follows:

#!/bin/sh

TMP1=`mktemp /tmp/mailcheck.XX`
TMP2=`mktemp /tmp/mailcheck.XX`

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??

Thanks in advance,
Jason

--
[EMAIL PROTECTED] mailing list



Re: [gentoo-user] Procmail and mail "notification" (SOVLED)

2003-08-29 Thread Jason Stubbs
Okay! Done it. Here's the script if anyone else is interested:

#!/bin/sh

MAILADDR="[EMAIL PROTECTED]"
TMP1=`mktemp /tmp/mailcheck.XX`
TMP2=`mktemp /tmp/mailcheck.XX`

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" $MAILADDR
cat $TMP1

rm $TMP1
rm $TMP2


Piping the appropriate mail through it with procmail should do what I want. 
Now to test it in the real world...

Jason

--
[EMAIL PROTECTED] mailing list