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
|
import email
|
||||||
from email.header import decode_header
|
from email.header import decode_header
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
username = ""
|
username = ""
|
||||||
password = ""
|
password = ""
|
||||||
|
@ -19,7 +20,7 @@ status, messages = imap.select("Notes", True)
|
||||||
|
|
||||||
messages = int(messages[0])
|
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)")
|
res, msg = imap.fetch(str(i), "(RFC822)")
|
||||||
for response in msg:
|
for response in msg:
|
||||||
if isinstance(response, tuple):
|
if isinstance(response, tuple):
|
||||||
|
@ -59,6 +60,8 @@ for i in range(messages, messages-N, -1):
|
||||||
md = markdownify(body)
|
md = markdownify(body)
|
||||||
if md[:4] == 'html':
|
if md[:4] == 'html':
|
||||||
md = md[4:]
|
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'))
|
open(filepath, "wb").write(md.replace('\r\n', '\n').encode('utf8'))
|
||||||
|
|
||||||
imap.close()
|
imap.close()
|
||||||
|
|
Loading…
Reference in New Issue