Module lua_mime
Module lua_mime
This module contains helper functions to modify mime parts
Brief content:
Functions:
| Function | Description |
|---|---|
lua_mime.configure_text_extraction(cfg) | Configures text extraction patterns from config. |
lua_mime.add_text_footer(task, html_footer, text_footer) | Adds a footer to all text parts in a message. |
lua_mime.multipattern_text_replace(task, mp, replacements) | Replaces text according to multipattern matches. |
lua_mime.modify_headers(task, {add = {hname = {value = 'value', order = 1}}, remove = {hname = {1,2}}}) | Adds/removes headers both internal and in the milter reply. |
lua_mime.message_to_ucl(task, [stringify_content]) | Exports a message to an ucl object. |
lua_mime.message_to_ucl_schema() | Returns schema for a message to verify result/document fields. |
lua_mime.remove_attachments(task, settings) | Removes all attachments from a message, keeping only text parts. |
lua_mime.get_displayed_text_part(task) | Returns the most relevant displayed content from an email. |
lua_mime.get_distinct_text_parts(task) | Returns the list of parts that are visible or have a distinct content. |
lua_mime.anonymize_message(task, settings) | Anonymizes message content by replacing sensitive data. |
lua_mime.extract_text_limited(task, opts) | Extracts text from a message with size limits and optional cleanup. |
Functions
The module lua_mime defines the following functions.
Function lua_mime.configure_text_extraction(cfg)
Configures text extraction patterns from config
- signature_patterns: array of signature patterns or regexp map
- reply_header_patterns: array of reply header patterns or regexp map
- reply_header_wrote_patterns: array of reply header "wrote" patterns or regexp map
- extend_defaults: boolean - if true, adds to defaults instead of replacing
Parameters:
cfg {table}: Configuration table with optional fields:
Returns:
No return
Back to module description.
Function lua_mime.add_text_footer(task, html_footer, text_footer)
Adds a footer to all text parts in a message. It returns a table with the following fields:
- out: new content (body only)
- need_rewrite_ct: boolean field that means if we must rewrite content type
- new_ct: new content type (type => string, subtype => string)
- new_cte: new content-transfer encoding (string)
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_mime.multipattern_text_replace(task, mp, replacements)
Replaces text according to multipattern matches. It returns a table with the following fields:
- out: new content (body only)
- need_rewrite_ct: boolean field that means if we must rewrite content type
- new_ct: new content type (type => string, subtype => string)
- new_cte: new content-transfer encoding (string)
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_mime.modify_headers(task, {add = {hname = {value = 'value', order = 1}}, remove = {hname = {1,2}}})
Adds/removes headers both internal and in the milter reply Mode defines to be compatible with Rspamd <=3.2 and is the default (equal to 'compat')
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_mime.message_to_ucl(task, [stringify_content])
Exports a message to an ucl object
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_mime.message_to_ucl_schema()
Returns schema for a message to verify result/document fields
Parameters:
No parameters
Returns:
No return
Back to module description.
Function lua_mime.remove_attachments(task, settings)
Removes all attachments from a message, keeping only text parts
- keep_images: boolean, whether to keep inline images (default: false)
- min_text_size: number, minimum text part size to keep (default: 0)
- max_text_size: number, maximum text part size to keep (default: inf)
- out: new content (body only)
Parameters:
task {task}: Rspamd task objectsettings {table}: Table with the following fields:
Returns:
{table}: modified message state similar to other modification functions:
Back to module description.
Function lua_mime.get_displayed_text_part(task)
Returns the most relevant displayed content from an email
Parameters:
task {task}: Rspamd task object
Returns:
{text_part}: a selected part
Back to module description.
Function lua_mime.get_distinct_text_parts(task)
Returns the list of parts that are visible or have a distinct content
Parameters:
task {task}: Rspamd task object
Returns:
- array of {text_part} a selected part
Back to module description.
Function lua_mime.anonymize_message(task, settings)
Anonymizes message content by replacing sensitive data
- strip_attachments: boolean, whether to strip all attachments
- custom_header_process: table of header_name => function(orig_header) pairs
Parameters:
task {task}: Rspamd task objectsettings {table}: Table with the following fields:
Returns:
{table}: modified message state similar to other modification functions
Back to module description.
Function lua_mime.extract_text_limited(task, opts)
Extracts text from a message with size limits and optional cleanup
- max_bytes: number - hard limit on output size (default: 32KB)
- max_words: number - alternative limit by word count
- preserve_first_part: boolean - prioritize newest content (top-post style)
- strip_quotes: boolean - remove quoted replies
- strip_reply_headers: boolean - remove "On X wrote:" patterns
- strip_signatures: boolean - remove signature blocks
- strip_footers: boolean - remove common email footers
- smart_trim: boolean - enable all heuristics
- text: string - extracted text
- truncated: boolean - whether text was truncated
- stats: table - statistics about extraction (removed_quotes, removed_signatures, etc)
Parameters:
task {task}: Rspamd task objectopts {table}: Options:
Returns:
{table}: Result table:
Back to module description.
Back to top.