使用bash仅提取传入电子邮件的正文部分

编程入门 行业动态 更新时间:2024-10-28 21:18:33
本文介绍了使用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仅提取传入电子邮件的正文部分

本文发布于:2023-06-09 04:15:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/595043.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电子邮件   正文   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!