Skip to content

Instantly share code, notes, and snippets.

@ikapper
Last active February 3, 2023 02:22
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 ikapper/ea80f8bbebea2ba33798a23381961f94 to your computer and use it in GitHub Desktop.
Save ikapper/ea80f8bbebea2ba33798a23381961f94 to your computer and use it in GitHub Desktop.
traslate body of vnt file to txt file
"""
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