Last active
September 4, 2015 01:05
-
-
Save pgtwitter/af5c6fb1b34220a638d6 to your computer and use it in GitHub Desktop.
MailのSubjectをdecodeする
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
from email.parser import Parser | |
from email.header import decode_header | |
fp = open("/path/to/mail.eml", "rb") | |
parser = Parser() | |
message = parser.parse(fp) | |
fp.close() | |
strs = [] | |
for pair in decode_header(message['Subject']): | |
subject = pair[0] | |
encoding = pair[1] | |
strs.append(subject if (encoding == None) else subject.decode(encoding)) | |
print ' '.join(strs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quoted-printable: https://ja.wikipedia.org/wiki/Quoted-printable