Hi - How would you read in the attachment from your unix mail account? The attachment is in BASE64 so I need to isolate those lines so I can convert them. The number of lines varies from a few to a few hundred. To complicate matters, the mail box gets non related emails I want to ignore. The lines before the attachment look like this:
These are emails coming from another system to my unix mailbox. They have an attachment made up of lines of data. I want to isolate them, convert from base64, then send them on for further processing. The other emails could be anything but none of them will have an attachments. That's why I was trying to look at only the ones that had this on a line: filename="Report_attachment 2017-01-28.csv". The date would change so I would only search for filename="Report_attachment. I thought if I found that line in the mail file, then found the space afterwards, then start reading in the data until I hit another space. But I'm open to any suggestions.
Now the emails will automatically be piped into the process as they arrive.
Then add something similar to:
#!/usr/bin/bash
subject1=" Email job submission status"
subject2=" Fax job status - Conversion Failure"
subject3=" Fax Status for Job ID"
first=0
start=0
JOBSTATUS=; export JOBSTATUS
SPOOLID=; export SPOOLID
DATETIME=; export DATETIME
PAGES=; export PAGES
STATUS=; export STATUS
TOTTIME=; export TOTTIME
#
while read line
do
if [ $first -eq 0 ]
then
first=1
from=`echo $line |cut -d" " -f2 `
if [ "$from" != "support@faxage.com" ]
then
echo not from faxage
exit
fi
fi
line1=${line/:/_}
key=`echo $line1|cut -d"_" -f1`
value=`echo $line1|cut -d"_" -f2`
value=`echo "$value"`
if [ "a$value" = "a" ]
then
continue
fi
if [ "a$key" != "aSubject" -a $start -eq 0 ]
then
continue
fi
if [ "a$key" = "aSubject" ]
then
start=1
if [ "a${value:0:${#subject1}}" = "a$subject1" ]
then
JOBSTATUS="QUEUED"
continue
fi
if [ "a${value:0:${#subject2}}" = "a$subject2" ]
then
JOBSTATUS="ERROR"
continue
fi
if [ "a${value:0:${#subject3}}" = "a$subject3" ]
then
JOBSTATUS="OK"
continue
fi
fi
if [ "$key" = "CustID" ]
then
SPOOLID=$value
fi
if [ "$key" = "Status" ]
then
STATUS=`echo $value`
fi
if [ "$key" = "Finished At" ]
then
DATETIME=`echo $value`
DATETIME=${DATETIME:0:10}${DATETIME:11:8}${DATETIME:20:7}
fi
if [ "$key" = "Transmit Time" ]
then
TOTTIME=`echo $value`
fi
if [ "$key" = "Page Count" ]
then
PAGES=`echo $value`
fi
done
echo JOBSTATUS=$JOBSTATUS >>/u2/fax/faxage.log
echo SPOOLID=$SPOOLID >>/u2/fax/faxage.log
echo STATUS=$STATUS >>/u2/fax/faxage.log
echo PAGES=$PAGES >>/u2/fax/faxage.log
echo DATETIME=$DATETIME >>/u2/fax/faxage.log
echo TOTTIME=$TOTTIME >>/u2/fax/faxage.log
given an email that looks like:
From support@faxage.com Tue Oct 18 13:47:58 2016
Message-Id: <201610up.com>
Received: from [6.199]
for <faxout@p.com>; Tue, 18 Oct 2016 11:47:51 -0600 (MDT)
Content-Type: multipart/mixed; boundary="_----------=_1476812871189590"
MIME-Version: 1.0
X-Mailer: MIME::Lite 3.029 (F2.78; T1.35; A2.12; B3.08; Q3.08)
Date: Tue, 18 Oct 2016 11:47:51 -0600
From: "FAXAGE" <support@faxage.com>
To: "Canada Inc" <faxout@p.com>
Subject: Fax Status for Job ID 289215564 to (819)555-1212
X-Faxage-Status: Failure
upportontent-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--_----------=_1476812871189590
Content-Disposition: inline
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
Your fax job has completed. Details are below:
To: Email to FAX
Number: (819)555-1212
Status: Failure
Reason: No Answer
Finished At: 2016-10-18 13:47:49 EDT
Transmit Time: 00:00:16
Pages Sent: 0
CustID:999999
--_----------=_1476812871189590--