Jump to content

Problem with shell script when parsing email


fallguy

Recommended Posts

Hello,

 

This is my post here, so I'll try to remain this clean and concise :)

I'm using a .forward file to forward email to a shell script in order to parse out the Subject and Body for later use. It's important that I use a shell script here, rather than perl or another language. After receiving the Subject and Body, I'm trying to forward these to a php script on an external server via curl. However, when I send an email the php script does not receive the Subject and Body. I believe the problem may be with curl, because when I run a simulated email through parse.sh, via cat test.txt | ./parse.sh, both the Subject and Body are properly returned.

 

Here is the content of the .forward file, located at /home/Dave/:

 

|/home/Dave/parse.sh

 

The content of the shell script (parse.sh) is attached. Is the curl command that I'm using not formatted correctly, and/or is there any error is my methods used to parse the Subject and Body?

 

Any help would be appreciated. --Thanks :)

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Thanks for the response. On a side note, this seems to be working on my local setup when running a test, such as echo "Subject: 19800131 Body.." | ./parse.sh. The script.php at the end, however, is failing to recognize the post variables.

 

#!/bin/bash
in=`fold -s -w 64`

BODY=`echo "$in" | sed -n 'H;${g;s/.*\n\n\(.*\)/\1/g;p}'`
BODY=$(echo -n "$BODY" | \
perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg');

SUBJECT=`echo "$in" | grep -m1 -i 'Subject:.*[0-9]\{8\}.*' | \
sed 's/^Subject:\(.*\)$/\1/'`
SUBJECT=$(echo -n "$SUBJECT" | \
perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg');

curl -s -d "subject=${SUBJECT}&body=${BODY}" http://www.domain.com/script.php
exit 0

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.