new script: misc/mimedecode

This commit is contained in:
Alexander Gehrke 2022-04-13 13:08:34 +02:00
parent 080fece651
commit 9e0c95e234

13
misc/mimedecode Executable file
View file

@ -0,0 +1,13 @@
#!/usr/bin/env python3
from email.header import decode_header
import sys
if len(sys.argv) < 2:
encoded = sys.stdin.read()
else:
encoded = ' '.join(sys.argv[1:])
text, encoding = decode_header(encoded)[0]
if type(text) is str:
print(text)
else:
print(text.decode(encoding))