I use offlineimap
to fetch the mails into a Maildir folder.
I want to automatically parse all new incoming emails in a Maildir folder and send only the "from", "subject" and "body" as an instant message somewhere else.
So I try to process all mails with
MPATH=~/Mail
if [ -n "$(ls "$MPATH/INBOX/new/")" ]; then
for f in "$MPATH/INBOX/new/"*; do
SUB="$(cat "$f"|grep '^Subject' | head -n1 | sed "s/Subject: //g")"
FROM="$(cat "$f" | grep '^From' | head -n1 | head -n 1|sed "s/From: //g")"
BODY="$(cat "$f"|sed -e '1,/Content-Transfer-Encoding/d')"
MESS="$FROM: $SUB$BODY"
echo $f
echo "$MESS"
mv "$f" "$MPATH/INBOX/cur/"
done
fi
This already works fine for some simple emails, but how do I get rid of everything that is not the plain body, like signatures, attachements,...?
offlineimap
to fetch the mails into a Maildir folder at the moment – Dyanncat
a file over and over, instead of just reading it in one pass and parsing out the parts you want? – Honey