I have some .msg files and each file contains several .msg attachments.
My goal is to use python to extract those .msg attachments and save them into another folder.
Usually I use extract_msg package to extract attachments as below:
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
But when I use such code to these .msg files, it will extract both the original msg file and attached msg files. But I only want to extract the original msg file but keep the attached msg files.
To clarify my point if I have the following msg file:
A.msg
-A's attachment1: B1.msg
-B1's attachment1: C1.pdf
-B1's attachment2: C2.txt
-A's attachment2: B2.msg
This is what I want:
Output Folder:
-B1.msg
-B2.msg
And this is what I have:
Output Folder:
-Folder B1:
-C1.pdf
-C2.txt
-Folder B2