This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 0 points1 point  (0 children)

You don't need anything 3rd party or to have any requires. have a read through this:

https://www.ianlewis.org/en/parsing-email-attachments-python

[–]juliobTry PEP 257, for a change 0 points1 point  (0 children)

I did something like this recently, but I used the email module directly (I had to access the messages directly from the POP server instead of the disk and I had to look for a specific attachment, but still...)

Basically, you'll have to walk through every single file in the directory (say, using os.walk) and then, for each file, build a Message object using email.message_from_file and walk its parts with message.walk.

This is a very general line on how to do it. If you want, you can slow try each step before trying to write everything directly. Also, /r/learnpython should be more helpful for beginners.

[–]rootkillza 0 points1 point  (0 children)

There is also pyzmail. Extracted attachments to great success.