s365b.core.mailview

Read a stored email (MIME) for display: headers, plain text, attachments.

Used by the browse view. Nothing here renders HTML: an HTML body becomes text, so a backed-up message cannot run script or load remote images in the admin’s browser.

Attributes

Classes

MessageView

An email prepared for display.

Functions

html_to_text(html) → str

Convert HTML to readable plain text.

read_message(raw) → MessageView

Parse a MIME message for display.

Module Contents

s365b.core.mailview.MAX_BODY = 200000[source]
s365b.core.mailview.html_to_text(html: str) → str[source]

Convert HTML to readable plain text.

Parameters:

html – An HTML document or fragment.

Returns:

The visible text with paragraph breaks.

class s365b.core.mailview.MessageView[source]

An email prepared for display.

Variables:
  • subject – Subject.

  • sender – From.

  • to – To.

  • cc – Cc.

  • date – Date header as sent.

  • body – Plain-text body (HTML converted), possibly truncated.

  • body_was_html – The body came from an HTML part.

  • truncated – The body was cut at MAX_BODY characters.

  • attachments – {"filename", "content_type", "size"} per attachment.

subject: str = ''[source]
sender: str = ''[source]
to: str = ''[source]
cc: str = ''[source]
date: str = ''[source]
body: str = ''[source]
body_was_html: bool = False[source]
truncated: bool = False[source]
attachments: list[dict[str, Any]] = [][source]
s365b.core.mailview.read_message(raw: bytes) → MessageView[source]

Parse a MIME message for display.

Parameters:

raw – The message as stored (RFC 5322 / MIME).

Returns:

Headers, plain-text body and attachment list.