I have an use case where I need to strip decryption of password protected zip file attached to an email, and replace it with the same zip file unencrypted. What I have so far:
import zipfile
import StringIO
...
if part.get_content_type() == "application/zip":
encrypted_string = part.get_payload().decode("base64")
encrypted_zip = zipfile.ZipFile(StringIO(encrypted_string))
encrypted_zip.setpassword("password")
I know that the zip file is now decrypted as I can do encrypted_zip.namelist()
and it works. Now that I have regular zip in the var encrypted_zip, I would just like to base64 encode it and replace the payload of the current attachment and move forward to next attachment. However, ZipFile does not have ".to_string()" method which i could use to re-encode it.
How do I achieve this?