Skip to content

Instantly share code, notes, and snippets.

@jvehent
Created Feb 29, 2012
Embed
What would you like to do?
python zip error
# 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()
@jvehent
Copy link
Author

jvehent commented Feb 29, 2012

julienv@mac:~/Code/dmarc-parser [master -]$ python unzip.py 
unzipping /tmp/google_dmarc_report.zip

julienv@mac:~/Code/dmarc-parser [master -]$ cat unzip.py 
#!/usr/bin/env python
import zipfile
attach_dest = "/tmp/google_dmarc_report.zip"
# unzip
print("unzipping %s" % attach_dest)
zf = zipfile.ZipFile(attach_dest, 'r')
zf.extractall("/tmp/")
zf.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment