Compare commits

...

3 Commits

Author SHA1 Message Date
quenousimporte f1fc5a24c1 fix encoding 2024-04-10 17:38:31 +02:00
quenousimporte 65e8d98646 move param 2024-04-10 17:26:01 +02:00
quenousimporte 982ff576c5 fix open imap as readonly 2024-04-10 17:13:55 +02:00
1 changed files with 3 additions and 6 deletions

View File

@ -7,6 +7,7 @@ import os
username = ""
password = ""
imapserver = ""
N = 500
if not os.path.isdir('notes'):
os.mkdir('notes')
@ -14,13 +15,10 @@ if not os.path.isdir('notes'):
def clean(text):
return "".join(c if c.isalnum() else "_" for c in text)
# number of top emails to fetch
N = 200
imap = imaplib.IMAP4_SSL(imapserver)
imap.login(username, password)
status, messages = imap.select("Notes")
status, messages = imap.select("Notes", True)
messages = int(messages[0])
@ -58,13 +56,12 @@ for i in range(messages, messages-N, -1):
content_type = msg.get_content_type()
body = msg.get_payload(decode=True).decode()
if content_type == "text/plain":
open(filepath, "w").write(body)
open(filepath, "wb").write(body.encode('utf8'))
if content_type == "text/html":
md = markdownify(body)
if md[:4] == 'html':
md = md[4:]
open(filepath, "wb").write(md.encode('utf8'))
imap.close()