Created
December 22, 2014 18:37
-
-
Save spapas/d7182a98374bf14e9632 to your computer and use it in GitHub Desktop.
Extract attachments from text mail messages
This file contains 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
import email | |
import sys | |
if __name__=='__main__': | |
if len(sys.argv)<2: | |
print "Please enter a file to extract attachments from" | |
sys.exit(1) | |
msg = email.message_from_file(open(sys.argv[1])) | |
for pl in msg.get_payload(): | |
if pl.get_filename(): # if it is an attachment | |
open(pl.get_filename(), 'wb').write(pl.get_payload(decode=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment