Extract zip file from email attachment

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sat Apr 7 07:51:22 CEST 2007


Basilisk96 wrote:
> >
> > Could the file like object still be encoded in MIME or something?
> >
>
> Yes it is. You don't need to seek(0).
> Try this:
>
> decoded = email.base64mime.decode(part.get_payload())
> fileObj.write(decoded)

Or better:
decoded = part.get_payload(decode=True)
fileObj.write(decoded)
fileObj.seek(0)
zip = zipfile.ZipFile(fileObj)
zip.printdir()




More information about the Python-list mailing list