Python从.msg文件中提取.msg附件

时间:2020-03-23 03:52:32

标签: python email extract email-attachments msg

我有一些.msg文件,每个文件包含几个.msg附件。

我的目标是使用python提取这些.msg附件并将其保存到另一个文件夹中。

通常,我使用.close包提取附件,如下所示:

while((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))

但是当我对这些.msg文件使用这样的代码时,它将同时提取原始msg文件和附加的msg文件。但是我只想提取原始msg文件,但保留附件中的msg文件。

要弄清楚我的观点,如果我有以下msg文件:

extract_msg

这就是我想要的:

msg = extract_msg.Message(msgdir) # msgdir is the directory of .msg file
if msg.attachments:
    for att in msg.attachments:
        att.save(customPath=outputdir) # outputdir is the directory of output folder

这就是我所拥有的:

A.msg
-A's attachment1: B1.msg
    -B1's attachment1: C1.pdf
    -B1's attachment2: C2.txt
-A's attachment2: B2.msg

0 个答案:

没有答案
相关问题