[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [OT BASH SCRIPT] Script to extract certain information from anemail



Jonathan Wilson wrote:
> 
> Howdy,
> 
> I reckon a sendmail user will have something like this in their /etc/smrsh directory ;-)
> 
> Does anyone have a script that,after being passed and email message from the MTA, could extract the From:, To:, Subject:, and Body: fields from an email and send it as certain arguments to another script?
> 
> for instance, right now I can make an email account, and everything sent to that address gets sent to a script instead of to a spool:
> script:      |"/etc/smrsh/email2script.sh"
> 
> email2script.sh looks like this:
> 
>         #!/bin/sh
>         /work/test/email2script.txt $@
> 
> which puts the content of the email into a text file named /work/test/email2script.txt
> 
> But instead of just passing all the contents along to a text file, I want it to grep out the headers and pass them as arguments to a script, sorts like this:
> 
> I would need the headers stuffed into variables, let's say $FROM $TO $SUBJ and $BODY
> 
> I would then need those passed to a script like so:
> 
>         #!/bin/bash
> <snip all the grepping and variable setting>
> 
>         /work/test/email2script.sh --from=$FROM --to=$TO --subject=$SUBJ --message=$BODY
> 
> I guess the part i don't know how to do is the grepping.
> 
> Anyone have something like this already, or care to show me an example?
> 
> TIA


You can do this with grep, but why?  Much easier to use perl;
there are modules for extracting the headers and accessing the
fields as a hash.  Simple, clean, and fairly fast.

rickf





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]