Compare commits
3 Commits
bc452a9f64
...
f1fc5a24c1
Author | SHA1 | Date |
---|---|---|
![]() |
f1fc5a24c1 | |
![]() |
65e8d98646 | |
![]() |
982ff576c5 |
|
@ -7,6 +7,7 @@ import os
|
||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
imapserver = ""
|
imapserver = ""
|
||||||
|
N = 500
|
||||||
|
|
||||||
if not os.path.isdir('notes'):
|
if not os.path.isdir('notes'):
|
||||||
os.mkdir('notes')
|
os.mkdir('notes')
|
||||||
|
@ -14,13 +15,10 @@ if not os.path.isdir('notes'):
|
||||||
def clean(text):
|
def clean(text):
|
||||||
return "".join(c if c.isalnum() else "_" for c in 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 = imaplib.IMAP4_SSL(imapserver)
|
||||||
imap.login(username, password)
|
imap.login(username, password)
|
||||||
|
|
||||||
status, messages = imap.select("Notes")
|
status, messages = imap.select("Notes", True)
|
||||||
|
|
||||||
messages = int(messages[0])
|
messages = int(messages[0])
|
||||||
|
|
||||||
|
@ -58,13 +56,12 @@ for i in range(messages, messages-N, -1):
|
||||||
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, "w").write(body)
|
open(filepath, "wb").write(body.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.encode('utf8'))
|
||||||
|
|
||||||
imap.close()
|
imap.close()
|
||||||
|
|
Loading…
Reference in New Issue