Created
February 29, 2012 15:55
-
-
Save jvehent/1941950 to your computer and use it in GitHub Desktop.
python zip error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# iterate through the list on messages | |
for number in message_number[0].split(): | |
# fetch the current message | |
typ, data = connection.fetch(number, '(RFC822)') | |
# parse the email | |
message = email.message_from_string(data[0][1]) | |
# for each attachment | |
for part in message.walk(): | |
attach_name = part.get_filename() | |
print ("found %s" % attach_name) | |
if attach_name: | |
# extract the attachment from the email | |
attach_dest = "/tmp/google_dmarc_report.zip" | |
print("detaching into %s" % attach_dest) | |
fd = file(attach_dest, "wb") | |
attach_data = email.base64mime.decode(part.get_payload()) | |
fd.write(attach_data) | |
fd.close | |
# unzip | |
print("unzipping %s" % attach_dest) | |
zf = zipfile.ZipFile(attach_dest, 'r') | |
zf.extractall("/tmp/") | |
zf.close() |
Author
jvehent
commented
Feb 29, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment