Skip to main content

Module email_processor

Module email_processor 

Source
Expand description

Renders email bodies, stored as the Gutenberg blocks the CMS email editor saves, into the HTML and plain-text parts of a message.

StructsΒ§

EmailGutenbergBlock
One block of an email body. Rich-text attributes (see EmailBlockName::is_rich_text_attribute) are HTML, sanitized when rendered; every other attribute is plain.
EmailLayoutFields
What a shell’s placeholders are filled with.
EmailRenderInput
What a message is rendered from: a body and subject with {{KEY}} placeholders, and the layout it is wrapped in.
EmailTheme
Colours the renderer writes inline, as #RRGGBB. Outlook desktop and clients that strip <style> read only these, so a shell’s CSS alone cannot rebrand them.
RenderedEmail
A message ready to hand to the mail relay.
TableCell πŸ”’

EnumsΒ§

EmailBlockName
Block types an email body may contain; must match allowedEmailCoreBlocks and blockTypeMapForEmails in the CMS. Any other type fails deserialization, so a body is never sent with a block silently left out.

ConstantsΒ§

CALLOUT_BACKGROUND_COLOR πŸ”’
CALLOUT_BORDER_COLOR πŸ”’
DEFAULT_EMAIL_LAYOUT
The shell used when no email_layouts row applies.
DEFAULT_EMAIL_THEME
The theme of DEFAULT_EMAIL_LAYOUT. Must match the column defaults of email_layouts.
DEFAULT_SPACER_HEIGHT_PX πŸ”’
EMAIL_ASSET_BASE_URL πŸ”’
Where the images the renderer links to are served from: services/main-frontend/public/static/email. Sent emails keep linking to these files, so they must never be renamed or removed.
IMAGE_SCHEMES πŸ”’
LINK_SCHEMES πŸ”’
MAX_IMAGE_WIDTH_PX πŸ”’
The width of the content column of the shells: 640px minus 40px padding on both sides.
MAX_SPACER_HEIGHT_PX πŸ”’
ONE_TIME_CODE_BACKGROUND_COLOR πŸ”’
ONE_TIME_CODE_BORDER_COLOR πŸ”’
ONE_TIME_CODE_FONT_FAMILY πŸ”’
ONE_TIME_CODE_TEXT_COLOR πŸ”’
QUOTE_BORDER_COLOR πŸ”’
QUOTE_TEXT_COLOR πŸ”’
RICH_TEXT_TAGS πŸ”’
The inline formatting Gutenberg’s rich text produces that email clients render. Not mark: old highlights lose their colour styles to the sanitizer, and a bare mark is painted yellow.
UNCHANGED_ALT_TEXT πŸ”’
What the CMS stores as an image’s alt text until the author writes one. Must match ALT_TEXT_NOT_CHANGED_PLACEHOLDER in services/cms/src/services/altTextPlaceholder.ts.

StaticsΒ§

ALL_TAG_REGEX πŸ”’
CSS_INLINER πŸ”’
HREFLESS_LINK_REGEX πŸ”’
IMG_TAG_REGEX πŸ”’
LAYOUT_PLACEHOLDER_REGEX πŸ”’
LINK_REGEX πŸ”’
PLACEHOLDER_REGEX πŸ”’
PREPENDED_PROTOCOL_BEFORE_PLACEHOLDER_REGEX πŸ”’
PREPENDED_PROTOCOL_IN_HREF_REGEX πŸ”’
QUOTE_VALUE_SANITIZER πŸ”’
For the value of quotes saved before quotes held inner blocks, which is a run of <p>s.
RICH_TEXT_SANITIZER πŸ”’
SRC_ATTRIBUTE_REGEX πŸ”’
WHITESPACE_REGEX πŸ”’

FunctionsΒ§

block_to_html πŸ”’
block_to_plaintext πŸ”’
callout_icon_file πŸ”’
The hosted PNG for a callout’s icon attribute; None for β€œnone” and unknown values.
fill_placeholders
Replaces {{KEY}} in every attribute, nested blocks included. Values are HTML-escaped in rich text and inserted as is elsewhere; a protocol Gutenberg prepended to a link whose whole target is a placeholder is dropped. Returns the keys found that replacements has no value for; those are left in place.
fill_placeholders_in_blocks πŸ”’
fill_placeholders_in_text πŸ”’
fill_placeholders_in_value πŸ”’
html_to_preformatted_text πŸ”’
Like html_to_text, but keeps the first line’s indentation.
html_to_text πŸ”’
Rich text to plain text. A link keeps its target, since the plain-text part has no other way to show it.
inline_css πŸ”’
Copies the <style> rules onto the elements they match, for clients that drop <style>.
layout_warnings
Problems that make a shell render badly: a missing {{SUBJECT}}, {{PREHEADER}} or {{LANGUAGE}}, or an image not loaded over https, which clients block or warn about. Empty when none is found; a heuristic, not validation.
list_to_plaintext πŸ”’
preheader
The inbox preview: the first paragraph as one line of text, or empty when there is none.
process_content_to_html
Renders a body into the HTML a shell’s {{CONTENT}} is replaced with.
process_content_to_plaintext
Renders a body into the plain-text part of a message. Links keep their targets in the text.
render_email
Renders a whole message. The one path both sending and previewing go through, so a preview shows what is sent.
replace_placeholders πŸ”’
rich_text_sanitizer πŸ”’
sanitize_rich_text πŸ”’
url_with_scheme πŸ”’
url trimmed, if it is absolute with one of schemes.
wrap_in_layout
Wraps a rendered body in an email shell: {{CONTENT}} gets the body as is, {{SUBJECT}}, {{PREHEADER}} and {{LANGUAGE}} their escaped values. One pass, so placeholders inside the body are never expanded.