Last active
February 3, 2023 02:22
-
-
Save ikapper/ea80f8bbebea2ba33798a23381961f94 to your computer and use it in GitHub Desktop.
traslate body of vnt file to txt file
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
""" | |
decode vnt file body text into txt file | |
""" | |
import glob | |
import quopri | |
# ref: [RFC1521: 5.1. Quoted-Printable Content-Transfer-Encoding](https://www.ietf.org/rfc/rfc1521.txt) | |
if __name__ == "__main__": | |
head = "BODY;CHARSET=Shift_JIS;ENCODING=QUOTED-PRINTABLE:" | |
end = "CATEGORIES:" | |
for path in glob.glob("./memo*"): | |
print(path) | |
name = path[2 : len(path) - 4] | |
with open(path, encoding="utf-8") as f: | |
body = "" | |
# search body text | |
for line in f: | |
if line.startswith(head) or body != "": | |
if line.startswith(end): | |
break | |
# trim | |
line = line.strip() | |
if line.endswith("="): | |
line = line[:-1] | |
body += line | |
out = body.replace(head, "") | |
out = quopri.decodestring(out.encode("utf-8")) | |
out = out.decode("shift-jis") | |
with open(f"./{name}.txt", encoding="utf-8", mode="wt") as fout: | |
fout.write(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment