Created
October 30, 2022 03:37
-
-
Save h4sh5/ee214d82d809519975b9f60cf40f1f9a to your computer and use it in GitHub Desktop.
parse mail logs and extract all base64 encoded attachments
This file contains hidden or 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
| #!/usr/bin/env python2 | |
| import sys | |
| import os | |
| import base64 | |
| file = sys.argv[1] | |
| # os.mkdir('out') | |
| with open(file,'rb') as f: | |
| lastblock = '' | |
| for block in f.read().split('\n\n'): | |
| if 'attachment; filename' in lastblock: | |
| filename = lastblock.split('filename=')[1].split('"')[1] | |
| print(filename) | |
| with open('out/'+filename,'w') as outf: | |
| outf.write(base64.b64decode(block)) | |
| print 'written to ' 'out/'+filename | |
| lastblock = block |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment