Compare commits
3 Commits
bc452a9f64
...
f1fc5a24c1
Author | SHA1 | Date |
---|---|---|
quenousimporte | f1fc5a24c1 | |
quenousimporte | 65e8d98646 | |
quenousimporte | 982ff576c5 |
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue