fine tuning

This commit is contained in:
quenousimporte 2024-04-10 21:44:15 +02:00
parent 93f02d8247
commit d2cd0568f6
4 changed files with 15 additions and 13 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
md2imap/mbox
md2imap/*.header
md2imap/*.imap
md2imap/input/*
md2imap/input**/*
imap2md/notes/*

View File

@ -46,20 +46,20 @@ for i in range(messages, messages-N, -1):
pass
if content_type == "text/plain" and "attachment" not in content_disposition:
open(filepath, "w").write(body)
open(filepath, "wb").write(body.replace('\r\n', '\n').encode('utf8'))
elif "attachment" in content_disposition:
print('/!\\ attachment')
else:
content_type = msg.get_content_type()
body = msg.get_payload(decode=True).decode()
if content_type == "text/plain":
open(filepath, "wb").write(body.encode('utf8'))
open(filepath, "wb").write(body.replace('\r\n', '\n').encode('utf8'))
if content_type == "text/html":
md = markdownify(body)
if md[:4] == 'html':
md = md[4:]
open(filepath, "wb").write(md.encode('utf8'))
open(filepath, "wb").write(md.replace('\r\n', '\n').encode('utf8'))
imap.close()
imap.logout()

View File

@ -8,4 +8,4 @@ Reply-To: name <email>
X-Uniform-Type-Identifier: com.apple.mail-note
Subject: =?UTF-8?Q?title?=
X-Universally-Unique-Identifier: uid
Status: RO
Status: RO

View File

@ -7,19 +7,20 @@ qp () {
rm mbox
for f in input/*.md
do
dos2unix "$f"
f=${f##*/}
title=${f%.md}
subject=$(echo $title|qp -e)
uid=$(cat /proc/sys/kernel/random/uuid)
cp imap-note-header "$title".imap
sed -i "s/uid/${uid}/" "$title".imap
sed -i "s/title/${subject}/" "$title".imap
sed -i "s/name/$1/" "$title".imap
sed -i "s/email/$2/" "$title".imap
cp imap-note-header "$title".header
sed -i "s/name/$1/" "$title".header
sed -i "s/email/$2/" "$title".header
sed -i "s/uid/${uid}/" "$title".header
sed -i "s/title/${subject}/" "$title".header
cat "input/$f" | qp -e >> "$title".imap
cat "$title".imap >> mbox
cat "$title".header >> mbox
printf '\n\n' >> mbox
rm "$title".imap
cat "input/$f" | qp -e >> mbox
rm "$title".header
done