diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/formbox.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/formbox.py b/src/formbox.py index 84c778a..46bad22 100644 --- a/src/formbox.py +++ b/src/formbox.py @@ -33,6 +33,17 @@ sanitise = partial(clean, tags=('a', 'code', 'em', 'strong', 'sub', 'sup', 'irc', 'ircs', 'mailto', 'matrix', 'xmpp')) +def get_body(message): + """Return the Markdown message body converted to HTML.""" + if message.is_multipart(): + for payload in map(get_body, message.get_payload()): + if payload is not None: return payload + elif message.get_content_type() in ('text/markdown', 'text/plain'): + return sanitise(linkify(markdown(message.get_payload(decode=True), + output_format='html5'))) + return None + + def decode(header): """Return the decoded email header.""" for string, charset in decode_header(header): @@ -60,14 +71,13 @@ def date(message): def render(template, archive, parent): """Render the thread recursively based on given template.""" for self in archive[parent]: + body = get_body(self) + if body is None: continue message_id = self['Message-Id'] try: author, address = decode(self['From']) except ValueError: author = self['From'] - # TODO: handle multipart - body = sanitise(linkify(markdown(self.get_payload(), - output_format='html5'))) rendered_children = render(template, archive, message_id) yield template.format(message_id=quote(message_id), mailto_params=urlencode(dict(reply_to(self))), |