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/mbox
md2imap/*.header
md2imap/*.imap md2imap/*.imap
md2imap/input/* md2imap/input**/*
imap2md/notes/* imap2md/notes/*

View File

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

View File

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