I need to restore .zip archives, extract the file to .zip and extract its data. .Zip archives are attached to email message files; I do not use the mail protocol to access the mailbox. I can parse the messages ...
...
from email.parser import Parser
...
for fileName in os.listdir(mailDir):
...
message = Parser().parse(open(mailDir + '/' + fileName, 'r'))
...
for part in message.walk():
if part.get_content_type() == 'application/octet-stream':
When I first started writing this code, I tested an email message with an attached CSV and had no problems accessing the attachment and pulling out the data, but now that I am working against emails with .zip (containing the previously used .csv) I was stuck. Added ...
import zipfile
... but it seems to me that I need to actually save the attached .zip to the file system in order to be able to use the zipfile. I would prefer not to do this and thought (hoped) that I could just use ...
zipfile.ZipFile(the_base64_string_from_message, 'r')
. .zip ? , , ( , ).