Created
June 2, 2017 10:44
-
-
Save sebastianw/ffe09b466a13db98755386dd10926815 to your computer and use it in GitHub Desktop.
Decode RFC2047 (formerly RFC1342) encoded mail headers - requires Python 3.3 or later
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
#! /usr/bin/env python3 | |
# Decode RFC2047 (formerly RFC1342) encoded mail headers | |
# Requires >= python 3.3 | |
import sys | |
from email.header import decode_header | |
def recode_utf8(subj): | |
output = '' | |
for s, enc in decode_header(subj): | |
if enc: | |
output += s.decode(enc) | |
else: | |
try: | |
output += s.decode() | |
except AttributeError: | |
output += s | |
return output | |
for l in sys.stdin.readlines(): | |
print(recode_utf8(l).strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment