Skip to content

Instantly share code, notes, and snippets.

@MasterAM MasterAM/unpack.py
Created May 12, 2015

Embed
What would you like to do?
This file is meant to unpack Israeli court attachments embedded in signature files. I got one of those files without the original file as the only attachment, while the email message stated there were 2 attachments. I don't know the general structure of those files since I only had this instance to deal with, but I hope someone else finds it use…
import base64
import xml.etree.ElementTree as ET
import sys
def decode(infile, outfile):
tree = ET.parse(infile)
xmlns = '{http://www.w3.org/2000/09/xmldsig#}'
b64 = tree.find("./SignaturePackage/{0}Signature/{0}Object/DocumentContent".format(xmlns)).text
txt = base64.b64decode(b64)
with open(outfile, 'bw+') as f:
f.write(txt)
if __name__ == "__main__":
if len(sys.argv) < 2:
print('usage: python unpack.py <input_filename>')
exit(1)
infile = sys.argv[1]
outfile = 'out.pdf'
decode(infile, outfile)
print('Done. Result saved to {0}'.format(outfile))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.