On Thu, 21 Jun 2001, Jonathan Wilson wrote:
Howdy,
Hi,
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?
there is no body field, the body is separated from the header with a blank line. I did something like this once, to implement a small email-pager gateway (i sent only from: and subject: lines of the email)
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
never tested this way, i did cat - > emailfile.txt as the script gets the email via standard input...
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:
after this you could separate header from body in two separate files with something like (continuing the script) cat emailfile.txt | sed ´1,^$d´ > emailbody.txt cat emailfile.txt | sed ´^$,$d´ > emailheader.txt using sed to create files based on deletion of text before and after the blank line separeting body from header so, to get the variables... to=`cat emailheader.txt | grep ´^To:´ | awk ´{print $2}´ from=`cat emailheader.txt | grep ´^From:´ | awk ´{print $2}´ subject=´`cat emailheader.txt | grep ´^Subject:´ | awk -F: ´{print $2}´`´ body=´`cat emailbody.txt`´ so sh yourscript.sh --from $from ...
I guess the part i don't know how to do is the grepping.
maybe the method above helps :) it´s ugly, but it may even work! :) Best Regards Adilson