从电子邮件中提取文件附件并将其保存到文件中?

从电子邮件中提取文件附件并将其保存到文件中?

我有一封以纯文本形式存储的电子邮件(是的,标题、消息、附件,所有内容都在一个纯文本文件中),我想从中提取 PDF 文档。我复制了 base64 编码的文本,然后运行它base64 -d并将cat其写入文件。然后我尝试打开它,但没有成功,而且它看起来不像 PDF 文件。

我在这里做错了什么吗?我相当确定它确实是用 base64 编码的并且是一个 PDF 文件。

这是电子邮件:

---------- MESSAGE FOLLOWS ----------
Date: Tue, 6 Mar 2012 12:24:24 -0800 (PST)
From: "Outer, Inc." <[email protected]>
To: Mike Young <[email protected]>
Message-ID: <[email protected]>
Subject: Your results are in, Mike!
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_0_1998493940.1331065464916"
X-Peer: 127.0.0.1

------=_Part_0_1998493940.1331065464916
Content-Type: multipart/alternative; 
    boundary="----=_Part_1_1254200493.1331065464936"

------=_Part_1_1254200493.1331065464936
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Great job, Mike on your baby!
------=_Part_1_1254200493.1331065464936
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<html>
    <body>
        <h3>Great job, Mike on your baby!</h3>
    </body>
</html>
------=_Part_1_1254200493.1331065464936--

------=_Part_0_1998493940.1331065464916
Content-Type: application/pdf; name="Baby Results.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Baby Results.pdf"

JVBERi0xLjQKJeLjz9MKMyAwIG9iaiA8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VH
cmF5L1N1YnR5cGUvSW1hZ2UvQml0c1BlckNvbXBvbmVudCA4L1dpZHRoIDI1My9MZW5ndGggMTYx
...
HR5P9F0eg4+P8tWzo2bPl6eGcNwyLqqW+chQi7Fo/CTWPUI7Kud1ZYgpcnSg7do4SKpTy10jyggP
1dVbvqS63pYxNl1JGGcvD1P+VFdN2b7O3YBqXTuiRteun3nmUdcoObmr5qduv09

答案1

munpack 似乎是您想要的工具。

相关内容