Skip to content

Instantly share code, notes, and snippets.

@a-yasui
Created June 24, 2015 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-yasui/458c1773087bf31901df to your computer and use it in GitHub Desktop.
Save a-yasui/458c1773087bf31901df to your computer and use it in GitHub Desktop.
oneline mime decode
# `test.txt` という名前の mail から plain text を取り出して吐き出す
msg = email.message_from_string(open('test.txt').read())
for part in msg.walk():
if part.get_content_type() == 'text/plain':
open('test.plan.txt', 'w').write( part.get_payload(decode=1).encode('iso-2022-jp').decode('utf8') )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment