change internal link when exporting an html note (fastmail specific)
fix exception after last note
This commit is contained in:
parent
20983b322a
commit
0833fbe161
|
@ -3,6 +3,7 @@ import imaplib
|
|||
import email
|
||||
from email.header import decode_header
|
||||
import os
|
||||
import re
|
||||
|
||||
username = ""
|
||||
password = ""
|
||||
|
@ -19,7 +20,7 @@ status, messages = imap.select("Notes", True)
|
|||
|
||||
messages = int(messages[0])
|
||||
|
||||
for i in range(messages, messages-N, -1):
|
||||
for i in range(messages, max(0, messages-N), -1):
|
||||
res, msg = imap.fetch(str(i), "(RFC822)")
|
||||
for response in msg:
|
||||
if isinstance(response, tuple):
|
||||
|
@ -59,6 +60,8 @@ for i in range(messages, messages-N, -1):
|
|||
md = markdownify(body)
|
||||
if md[:4] == 'html':
|
||||
md = md[4:]
|
||||
# fastmail specific: replace internal links
|
||||
md = re.sub(r'\[(.*)\]\(https://app.fastmail.com.*\)', '[[\\1]]', md)
|
||||
open(filepath, "wb").write(md.replace('\r\n', '\n').encode('utf8'))
|
||||
|
||||
imap.close()
|
||||
|
|
Loading…
Reference in New Issue