本文介绍了使用bash仅提取传入电子邮件的正文部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 offlineimap 将邮件提取到Maildir文件夹中.
I use offlineimap to fetch the mails into a Maildir folder.
我想自动解析Maildir文件夹中的所有新收到的电子邮件,并仅在其他位置发送发件人",主题"和正文"作为即时消息.
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,...?
推荐答案如formail联机帮助页上所建议的那样,对我有用:
As suggested on formail manpage, that worked for me:
cat mailfile | sed -e '1,/^$/ d'更多推荐
使用bash仅提取传入电子邮件的正文部分
发布评论