1833491 Members
2864 Online
110052 Solutions
New Discussion

Script to parse mail

 
Rui Vilao
Regular Advisor

Script to parse mail

Greetings,

I am working on a shell script that I would add to my .forward file:

\rui, "|~/bin/mail_parser.sh"

For each incoming mail, it would search for a given pattern (eg. subject). Upon detection of a given pattern, it would perform a given action (eg. send a mail,...).

Any help or suggestion is welcome.

TIA,

Kind Regards,

Rui
"We should never stop learning"_________ rui.vilao@rocketmail.com
4 REPLIES 4
Eugen Cocalea
Respected Contributor

Re: Script to parse mail

Hi,

man procmail
man procmailex

E.
To Live Is To Learn
Eugen Cocalea
Respected Contributor

Re: Script to parse mail

Oops, I thought it's a Linux question, sorry :) Let's check if there is a procmail for HPUX :)

Found it:
http://hpux.tn.tudelft.nl/hppd/hpux/Networking/Mail/procmail-3.21/

E.
To Live Is To Learn
Eugen Cocalea
Respected Contributor

Re: Script to parse mail

Hi again,

Hrm, I should get the good habit to research first and answer after. No more 3 replies in a row then :)

Anyway, this is how it goes with procmail (on my linux at least, but should work the same on HPUX):

I have a .procmailrc file on my homedir. Any email that I get gets filtered by it. An example for subject parsing is (lines from .procmailrc):

:0:
* ^Subject:. pattern
mail/folder_for_pattern

This will save the mail with a certain pattern in their subject in the folder mail/... on my home dir.
You can run certain programs as well in the event that a match occurs (ie send an email, send a SMS, etc).

E.
To Live Is To Learn
Robin Wakefield
Honored Contributor

Re: Script to parse mail

Hi Rui,

I put the following in aliases:

parse: "|/usr/local/bin/parse_mail.sh"

Where /usr/local/bin/parse_mail.sh contains:

=========================================
#!/bin/ksh

while read line ; do
echo $line | grep -i subject && echo "The subject is $line" > /tmp/parse.out
done
==========================================

Sending to "parse" on this machine updated the /tmp/parse.out file.

Rgds, Robin.