rspamd_task
This module provides routines for tasks manipulation in rspamd. Tasks usually represent messages being scanned, and this API provides access to such elements as headers, symbols, metrics and so on and so forth. Normally, task objects are passed to the lua callbacks allowing to check specific properties of messages and add the corresponding symbols to the scan’s results.
Functions:
Function | Description |
---|---|
rspamd_task.create([cfg]) |
Create a new empty task. |
rspamd_task.load_from_file(filename[, cfg]) |
Loads a message from specific file. |
rspamd_task.load_from_string(message[, cfg]) |
Loads a message from specific file. |
Methods:
Method | Description |
---|---|
task:get_message() |
Returns task raw message content as opaque text. |
task:set_message(msg) |
Updates task message with another message; It also parses a message to. |
task:process_message() |
Parses message. |
task:get_cfg() |
Get configuration object for a task. |
task:get_mempool() |
Returns memory pool valid for a lifetime of task. |
task:get_session() |
Returns asynchronous session object that is used by many rspamd asynchronous. |
task:set_session(session) |
Sets new async session for a task. |
task:get_ev_base() |
Return asynchronous event base for using in callbacks and resolver. |
task:get_worker() |
Returns a worker object associated with the task. |
task:insert_result([enforce_symbol,]symbol, weight[, option1, ...]) |
Insert specific symbol to the tasks scanning results assigning the initial. |
task:insert_result_named(shadow_result, [enforce_symbol,]symbol, weight[, option1, ...]) |
Insert specific symbol to the tasks scanning results assigning the initial. |
task:adjust_result(symbol, score[, option1, ...]) |
Alters the existing symbol’s score to a new score. |
task:remove_result(symbol[, shadow_result]) |
Removes the symbol from a named or unnamed/default result. |
task:set_pre_result(action, [message, [module], [score], [priority], [flags]) |
Sets pre-result for a task. |
task:has_pre_result() |
Returns true if task has some pre-result being set. |
task:append_message(message, [category]) |
Adds a message to scanning output. |
task:get_urls([need_emails|list_protos][, need_images]) |
Get all URLs found in a message. |
task:get_urls_filtered([{flags_include}, [{flags_exclude}]], [{protocols_mask}]) |
Get urls managed by either exclude or include flags list. |
task:has_urls([need_emails]) |
Returns ‘true’ if a task has urls listed. |
task:inject_url(url) |
Inserts an url into a task (useful for redirected urls). |
task:get_content() |
Get raw content for the specified task. |
task:get_filename() |
Returns filename for a specific task. |
task:get_rawbody() |
Get raw body for the specified task. |
task:get_emails() |
Get all email addresses found in a message. |
task:get_text_parts() |
Get all text (and HTML) parts found in a message. |
task:get_parts() |
Get all mime parts found in a message. |
task:get_meta_words([how='stem']) |
Get meta words from task (subject and displayed names). |
task:get_request_header(name) |
Get value of a HTTP request header. |
task:set_request_header(name, value) |
Set value of a HTTP request header. |
task:get_subject() |
Returns task subject (either from the protocol override or from a header). |
task:get_header(name[, case_sensitive]) |
Get decoded value of a header specified with optional case_sensitive flag. |
task:has_header(name[, case_sensitive]) |
Get decoded value of a header specified with optional case_sensitive flag. |
task:get_header_raw(name[, case_sensitive]) |
Get raw value of a header specified with optional case_sensitive flag. |
task:get_header_full(name[, case_sensitive[, need_modified]]) |
Get raw value of a header specified with optional case_sensitive flag. |
task:get_header_count(name[, case_sensitive]) |
Lightweight version if you need just a header’s count. |
task:get_raw_headers() |
Get all undecoded headers of a message as a string. |
task:get_headers([need_modified=false]) |
Get all headers of a message in the same format as get_header_full. |
task:modify_header(name, mods) |
Modify an existing or non-existing header with the name name . |
task:get_received_headers() |
Returns a list of tables of parsed received headers. |
task:get_queue_id() |
Returns queue ID of the message being processed. |
task:get_uid() |
Returns ID of the task being processed. |
task:get_resolver() |
Returns ready to use rspamd_resolver object suitable for making asynchronous DNS requests. |
task:set_resolver(resolver) |
Sets rspamd_resolver for a specified task. |
task:inc_dns_req() |
Increment number of DNS requests for the task. |
task:get_dns_req() |
Get number of dns requests being sent in the task. |
task:has_recipients([type]) |
Return true if there are SMTP or MIME recipients for a task. |
task:get_recipients([type]) |
Return SMTP or MIME recipients for a task. |
task:get_principal_recipient() |
Returns a single string with so called principal recipient for a message. |
task:get_reply_sender() |
Returns a single string with address that should be used to reply on a message. |
task:set_recipients([type], {rcpt1, rcpt2...}, [how='add']) |
Sets recipients for a task. |
task:has_from([type]) |
Return true if there is SMTP or MIME sender for a task. |
task:get_from([type]) |
Return SMTP or MIME sender for a task. |
task:set_from(type, addr) |
Sets sender for a task. |
task:get_user() |
Returns authenticated user name for this task if specified by an MTA. |
task:set_user([username]) |
Sets or resets (if username is not specified) authenticated user name for this task. |
task:get_from_ip() |
Returns rspamd_ip object of a sender that is provided by MTA. |
task:set_from_ip(str) |
Set tasks’s IP address based on the passed string. |
task:get_client_ip() |
Returns rspamd_ip object of a client connected to rspamd (normally, it is an IP address of MTA). |
task:get_helo() |
Returns the value of SMTP helo provided by MTA. |
task:get_hostname() |
Returns the value of sender’s hostname provided by MTA. |
task:get_images() |
Returns list of all images found in a task as a table of rspamd_image . |
task:get_archives() |
Returns list of all archives found in a task as a table of rspamd_archive . |
task:get_dkim_results() |
Returns list of all dkim check results as table of maps. |
task:get_symbol(name, [shadow_result_name]) |
Searches for a symbol name in all metrics results and returns a list of tables. |
task:get_symbols_all() |
Returns array of symbols matched in default metric with all metadata. |
task:get_symbols([shadow_result_name]) |
Returns array of all symbols matched for this task. |
task:get_groups([need_private]) |
Returns a map [group -> group_score] for matched group. |
task:get_symbols_numeric() |
Returns array of all symbols matched for this task. |
task:get_symbols_tokens() |
Returns array of all symbols as statistical tokens. |
task:process_ann_tokens(symbols, ann_tokens, offset, [min]) |
Processes ann tokens. |
task:has_symbol(name, [shadow_result_name]) |
Fast path to check if a specified symbol is in the task’s results. |
task:enable_symbol(name) |
Enable specified symbol for this particular task. |
task:disable_symbol(name) |
Disable specified symbol for this particular task. |
task:get_date(type[, gmt]) |
Returns timestamp for a connection or for a MIME message. |
task:get_message_id() |
Returns message identifier from the Message-ID header. |
task:get_timeval([raw]) |
Returns the timestamp for a task start processing time. |
task:get_scan_time([set]) |
Returns 2 floating point numbers. |
task:get_metric_result() |
Get full result of a metric as a table. |
task:get_metric_score(name) |
Get the current score of metric name (must be nil or ‘default’) . |
task:get_metric_threshold(action) |
Get the current threshold of the action action for the default metric. |
task:get_metric_action(name) |
Get the current action of metric name (must be nil or ‘default’). |
task:set_metric_score(name, score) |
Set the current score of metric name . |
task:set_metric_subject(subject) |
Set the subject in the default metric. |
task:learn(is_spam[, classifier) |
Learn classifier classifier with the task. |
task:set_settings(obj) |
Set users settings object for a task. |
task:set_settings_id(id) |
Set users settings id for a task (must be registered previously). |
task:get_settings() |
Gets users settings object for a task. |
task:lookup_settings(key) |
Gets users settings object with the specified key for a task. |
task:get_settings_id() |
Get numeric hash of settings id if specified for this task. |
task:set_milter_reply(obj) |
Set special reply for milter. |
task:process_re(params) |
Processes the specified regexp and returns number of captures (cached or new). |
task:cache_set(key, value) |
Store some value to the task cache. |
task:cache_get(key) |
Returns cached value or nil if nothing is cached. |
task:get_size() |
Returns size of the task in bytes (that includes headers + parts size). |
task:set_flag(flag_name[, set]) |
Set specific flag for task. |
task:has_flag(flag_name) |
Checks for a specific flag in task. |
task:get_flags() |
Get list of flags for task. |
task:get_digest() |
Returns message’s unique digest (32 hex symbols). |
task:store_in_file([mode|table]) |
If task was loaded using file scan, then this method just returns its name,. |
task:get_protocol_reply([flags]) |
This method being called from a postfilter will return reply for a message. |
task:headers_foreach(callback, [params]) |
This method calls callback for each header that satisfies some condition. |
task:disable_action(action) |
Disables some action for this task (e.g. |
task:get_newlines_type() |
Returns the most frequent newlines type met in a task. |
task:get_stat_tokens() |
Returns list of tables the statistical tokens. |
task:lookup_words(map, function({o, n, s, f}) ... end) |
Matches words in a task (including meta words) against some map (set, regexp and so on). |
task:get_dns_req() |
Get number of dns requests being sent in the task. |
The module rspamd_task
defines the following functions.
rspamd_task.create([cfg])
Create a new empty task
Parameters:
No parameters
Returns:
{rspamd_task}
: new taskBack to module description.
rspamd_task.load_from_file(filename[, cfg])
Loads a message from specific file
Parameters:
No parameters
Returns:
{boolean,rspamd_task|error}
: status + new task or error messageBack to module description.
rspamd_task.load_from_string(message[, cfg])
Loads a message from specific file
Parameters:
No parameters
Returns:
{boolean,rspamd_task|error}
: status + new task or error messageBack to module description.
The module rspamd_task
defines the following methods.
task:get_message()
Returns task raw message content as opaque text
Parameters:
No parameters
Returns:
{rspamd_text}
: task raw contentBack to module description.
task:set_message(msg)
Updates task message with another message; It also parses a message to fill the internal structures. Input might be a string, a lua_text or a table of the former stuff.
Parameters:
msg {string/text/table}
: new message to setReturns:
{boolean,number}
: if a message has been set + its raw sizeBack to module description.
task:process_message()
Parses message
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_cfg()
Get configuration object for a task.
Parameters:
No parameters
Returns:
{rspamd_config}
: (config.html)[configuration object] for the taskBack to module description.
task:get_mempool()
Returns memory pool valid for a lifetime of task. It is used internally by many rspamd routines.
Parameters:
No parameters
Returns:
{rspamd_mempool}
: memory pool objectBack to module description.
task:get_session()
Returns asynchronous session object that is used by many rspamd asynchronous utilities internally.
Parameters:
No parameters
Returns:
{rspamd_session}
: session objectBack to module description.
task:set_session(session)
Sets new async session for a task
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_ev_base()
Return asynchronous event base for using in callbacks and resolver.
Parameters:
No parameters
Returns:
{rspamd_ev_base}
: event baseBack to module description.
task:get_worker()
Returns a worker object associated with the task
Parameters:
No parameters
Returns:
{rspamd_worker}
: worker objectBack to module description.
task:insert_result([enforce_symbol,]symbol, weight[, option1, ...])
Insert specific symbol to the tasks scanning results assigning the initial weight to it.
Parameters:
enforce_symbol {boolean}
: if represented and true, then insert symbol even if it is not registered in the metricsymbol {string}
: symbol to insertweight {number}
: initial weight (this weight is multiplied by the metric weight)options {string}
: list of optional options attached to a symbol insertedReturns:
No return
Back to module description.
task:insert_result_named(shadow_result, [enforce_symbol,]symbol, weight[, option1, ...])
Insert specific symbol to the tasks scanning results assigning the initial weight to it.
Parameters:
shadow_result {string}
: name of shadow resultenforce_symbol {boolean}
: if represented and true, then insert symbol even if it is not registered in the metricsymbol {string}
: symbol to insertweight {number}
: initial weight (this weight is multiplied by the metric weight)options {string}
: list of optional options attached to a symbol insertedReturns:
No return
Back to module description.
task:adjust_result(symbol, score[, option1, ...])
Alters the existing symbol’s score to a new score. It is not affected by metric score or grow factor. You can also add new options using this method. Symbol must be already inserted into metric or an error will be emitted.
Parameters:
symbol {string}
: symbol to adjustscore {number}
: this value is NOT multiplied by the metric scoreoptions {string/table}
: list of optional options attached to a symbol adjustedReturns:
No return
Back to module description.
task:remove_result(symbol[, shadow_result])
Removes the symbol from a named or unnamed/default result
Parameters:
symbol {string}
: symbol to removeshadow_result {string}
: name of shadow resultReturns:
{boolean}
: true if a symbol has been removedBack to module description.
task:set_pre_result(action, [message, [module], [score], [priority], [flags])
Sets pre-result for a task. It is used in pre-filters to specify early result
of the task scanned. If a pre-filter sets some result, then further processing
may be skipped. For selecting action it is possible to use global table
rspamd_actions
or a string value:
reject
: reject message permanentlyadd header
: add spam headerrewrite subject
: rewrite subject to spam subjectgreylist
: greylist messageaccept
or no action
: whitelist messagequarantine
: quarantine the message; depending on the MTA, it can be done via HOLD.
Note: the message parameter must be nil
for proper operation.discard
: drop the message from the queue without returning an error to the sender.Actions should be defined in the actions.conf
configuration file.
This function also accepts a table from Rspamd 2.6 with the following keys:
Parameters:
action {rspamd_action or string}
: a numeric or string action valuemessage {string}
: action messagemodule {string}
: optional module namescore {number/nil}
: optional explicit scorepriority {number/nil}
: optional explicit priorityflags {string/nil}
: optional flags (e.g. ‘least’ for least action)Returns:
No return
Back to module description.
task:has_pre_result()
Returns true if task has some pre-result being set. If result has been set this function also returns pre result action, message and module as strings in this order.
Parameters:
No parameters
Returns:
{boolean,[string,string,string]}
: true if task has some pre-result being setBack to module description.
task:append_message(message, [category])
Adds a message to scanning output.
Parameters:
message {string}
: no descriptionmessage {category}
: categoryReturns:
No return
Back to module description.
task:get_urls([need_emails|list_protos][, need_images])
Get all URLs found in a message. Telephone urls and emails are not included unless explicitly asked in list_protos
Parameters:
need_emails {boolean}
: if true
then return also email urls, this can be a comma separated string of protocols desired or a table (e.g. mailto
or telephone
)need_images {boolean}
: return urls from images (<img src=…>) as wellReturns:
{table rspamd_url}
: list of all urls foundBack to module description.
task:get_urls_filtered([{flags_include}, [{flags_exclude}]], [{protocols_mask}])
Get urls managed by either exclude or include flags list
Parameters:
flags_include {table}
: included flagsflags_exclude {table}
: excluded flagsprotocols_mask {table}
: include only specific protocolsReturns:
{table rspamd_url}
: list of urls matching conditionsBack to module description.
task:has_urls([need_emails])
Returns ‘true’ if a task has urls listed
Parameters:
need_emails {boolean}
: if true
then return also email urlsReturns:
{boolean}
: true if a task has urls (urls or emails if need_emails
is true)Back to module description.
task:inject_url(url)
Inserts an url into a task (useful for redirected urls)
Parameters:
url {lua_url}
: url to injectReturns:
No return
Back to module description.
task:get_content()
Get raw content for the specified task
Parameters:
No parameters
Returns:
{text}
: the data contained in the taskBack to module description.
task:get_filename()
Returns filename for a specific task
Parameters:
No parameters
Returns:
{string|nil}
: filename or nil if unknownBack to module description.
task:get_rawbody()
Get raw body for the specified task
Parameters:
No parameters
Returns:
{text}
: the data contained in the taskBack to module description.
task:get_emails()
Get all email addresses found in a message.
Parameters:
No parameters
Returns:
{table rspamd_url}
: list of all email addresses foundBack to module description.
task:get_text_parts()
Get all text (and HTML) parts found in a message
Parameters:
No parameters
Returns:
{table rspamd_text_part}
: list of text partsBack to module description.
task:get_parts()
Get all mime parts found in a message
Parameters:
No parameters
Returns:
{table rspamd_mime_part}
: list of mime partsBack to module description.
task:get_meta_words([how='stem'])
Get meta words from task (subject and displayed names)
stem
: stemmed words (default)norm
: normalised words (utf normalised + lowercased)raw
: raw words in utf (if possible)full
: list of tables, each table has the following fields:
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_request_header(name)
Get value of a HTTP request header.
Parameters:
name {string}
: name of header to getReturns:
{rspamd_text}
: value of an HTTP headerBack to module description.
task:set_request_header(name, value)
Set value of a HTTP request header. If value is omitted, then a header is removed
Parameters:
name {string}
: name of header to getvalue {rspamd_text/string}
: new header’s valueReturns:
No return
Back to module description.
task:get_subject()
Returns task subject (either from the protocol override or from a header)
Parameters:
No parameters
Returns:
{string}
: value of a subject (decoded)Back to module description.
task:get_header(name[, case_sensitive])
Get decoded value of a header specified with optional case_sensitive flag. By default headers are searched in caseless matter.
Parameters:
name {string}
: name of header to getcase_sensitive {boolean}
: case sensitiveness flag to search for a headerReturns:
{string}
: decoded value of a headerBack to module description.
task:has_header(name[, case_sensitive])
Get decoded value of a header specified with optional case_sensitive flag. By default headers are searched in the case insensitive matter.
Parameters:
name {string}
: name of header to getcase_sensitive {boolean}
: case sensitiveness flag to search for a headerReturns:
{boolean}
: true if header existsBack to module description.
task:get_header_raw(name[, case_sensitive])
Get raw value of a header specified with optional case_sensitive flag. By default headers are searched in caseless matter.
Parameters:
name {string}
: name of header to getcase_sensitive {boolean}
: case sensitiveness flag to search for a headerReturns:
{string}
: raw value of a headerBack to module description.
task:get_header_full(name[, case_sensitive[, need_modified]])
Get raw value of a header specified with optional case_sensitive flag. By default headers are searched in caseless matter. This method returns more information about the header as a list of tables with the following structure:
name
- name of a headervalue
- raw value of a headerdecoded
- decoded value of a headertab_separated
- true
if a header and a value are separated by tab
characterempty_separator
- true
if there are no separator between a header and a valueParameters:
name {string}
: name of header to getcase_sensitive {boolean}
: case sensitiveness flag to search for a headerneed_modified {boolean}
: return a modified value of a header if presentedReturns:
{list of tables}
: all values of a header as specified aboveBack to module description.
task:get_header_count(name[, case_sensitive])
Lightweight version if you need just a header’s count
Parameters:
name {string}
: name of header to getcase_sensitive {boolean}
: case sensitiveness flag to search for a headerReturns:
{number}
: number of header’s occurrences or 0 if not foundBack to module description.
task:get_raw_headers()
Get all undecoded headers of a message as a string
Parameters:
No parameters
Returns:
{rspamd_text}
: all raw headers for a message as opaque textBack to module description.
task:get_headers([need_modified=false])
Get all headers of a message in the same format as get_header_full
Parameters:
No parameters
Returns:
{table of headers data}
: all headers for a messageBack to module description.
task:modify_header(name, mods)
Modify an existing or non-existing header with the name name
Mods is a table with the following structure:
Parameters:
No parameters
Returns:
{bool}
: true if header could be modified (always true unless we don’t have an unparsed message)Back to module description.
task:get_received_headers()
Returns a list of tables of parsed received headers. A tables returned have the following structure:
from_hostname
- string that represents hostname provided by a peerfrom_ip
- string representation of sending IP addressreal_hostname
- hostname as resolved by MTAreal_ip
- rspamd_ip object representing sending IP addressby_hostname
- MTA hostnameproto
- protocol, e.g. ESMTP or ESMTPStimestamp
- received timestampfor
- for value (unparsed mailbox)Please note that in some situations rspamd cannot parse all the fields of received headers. In that case you should check all strings for validity.
Parameters:
No parameters
Returns:
{table of tables}
: list of received headers described aboveBack to module description.
task:get_queue_id()
Returns queue ID of the message being processed.
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_uid()
Returns ID of the task being processed.
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_resolver()
Returns ready to use rspamd_resolver object suitable for making asynchronous DNS requests.
Parameters:
No parameters
Returns:
{rspamd_resolver}
: resolver object associated with the task’s sessionBack to module description.
task:set_resolver(resolver)
Sets rspamd_resolver for a specified task.
Parameters:
No parameters
Returns:
No return
Back to module description.
task:inc_dns_req()
Increment number of DNS requests for the task. Is used just for logging purposes.
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_dns_req()
Get number of dns requests being sent in the task
Parameters:
No parameters
Returns:
{number}
: number of DNS requestsBack to module description.
task:has_recipients([type])
Return true if there are SMTP or MIME recipients for a task.
Parameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP recipients and fallback to MIME if failed, 1
or smtp
means checking merely SMTP recipients and 2
or mime
means MIME recipients onlyReturns:
{bool,integer}
: true
if there are recipients of the following type and a number of such a recipients excluding artificial onesBack to module description.
task:get_recipients([type])
Return SMTP or MIME recipients for a task. This function returns list of internet addresses each one is a table with the following structure:
name
- name of internet address in UTF8, e.g. for Vsevolod Stakhov <blah@foo.com>
it returns Vsevolod Stakhov
addr
- address part of the addressuser
- user part (if present) of the address, e.g. blah
domain
- domain part (if present), e.g. foo.com
Parameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP recipients and fallback to MIME if failed, 1
or smtp
means checking merely SMTP recipients and 2
or mime
means MIME recipients onlyReturns:
{list of addresses}
: list of recipients or nil
Back to module description.
task:get_principal_recipient()
Returns a single string with so called principal recipient
for a message. The order
of check is the following:
Parameters:
No parameters
Returns:
{string}
: principal recipientBack to module description.
task:get_reply_sender()
Returns a single string with address that should be used to reply on a message
Parameters:
No parameters
Returns:
{address}
: email addressBack to module description.
task:set_recipients([type], {rcpt1, rcpt2...}, [how='add'])
Sets recipients for a task. This function accepts table that will be converted to the address. If some fields are missing they are subsequently reconstructed by this function. E.g. if you specify ‘user’ and ‘domain’, then address and raw string will be reconstructed
name
- name of internet address in UTF8, e.g. for Vsevolod Stakhov <blah@foo.com>
it returns Vsevolod Stakhov
addr
- address part of the addressuser
- user part (if present) of the address, e.g. blah
domain
- domain part (if present), e.g. foo.com
Parameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP recipients and fallback to MIME if failed, 1
or smtp
means checking merely SMTP recipients and 2
or mime
means MIME recipients onlyrecipients {list of tables}
: recipients to sethow {string}
: define how to set recipients: rewrite
- rewrite existing recipients, alias
- treat existing recipients as aliased recipients, add
- add new recipientsReturns:
{boolean}
: result of the operationBack to module description.
task:has_from([type])
Return true if there is SMTP or MIME sender for a task.
Parameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP recipients and fallback to MIME if failed, 1
or smtp
means checking merely SMTP recipients and 2
or mime
means MIME recipients onlyReturns:
{bool}
: true
if there is sender of the following typeBack to module description.
task:get_from([type])
Return SMTP or MIME sender for a task. This function returns an internet address which one is a table with the following structure:
raw
- the original value without any processingname
- name of internet address in UTF8, e.g. for Vsevolod Stakhov <blah@foo.com>
it returns Vsevolod Stakhov
addr
- address part of the addressuser
- user part (if present) of the address, e.g. blah
domain
- domain part (if present), e.g. foo.com
flags
- table with following keys set to true if given condition fulfilled:
<blah@foo.com>
addressParameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP sender and fallback to MIME if failed, 1
or smtp
means checking merely SMTP sender and 2
or mime
means MIME From:
onlyReturns:
{address}
: sender or nil
Back to module description.
task:set_from(type, addr)
Sets sender for a task. This function accepts table that will be converted to the address. If some fields are missing they are subsequently reconstructed by this function. E.g. if you specify ‘user’ and ‘domain’, then address and raw string will be reconstructed
name
- name of internet address in UTF8, e.g. for Vsevolod Stakhov <blah@foo.com>
it returns Vsevolod Stakhov
addr
- address part of the addressuser
- user part (if present) of the address, e.g. blah
domain
- domain part (if present), e.g. foo.com
Parameters:
type {integer|string}
: if specified has the following meaning: 0
or any
means try SMTP sender and fallback to MIME if failed, 1
or smtp
means checking merely SMTP sender and 2
or mime
means MIME From:
only{table {no type}
: no descriptionReturns:
{boolean}
: success or notBack to module description.
task:get_user()
Returns authenticated user name for this task if specified by an MTA.
Parameters:
No parameters
Returns:
{string}
: username or nilBack to module description.
task:set_user([username])
Sets or resets (if username is not specified) authenticated user name for this task.
Parameters:
No parameters
Returns:
{string}
: the previously set username or nilBack to module description.
task:get_from_ip()
Returns rspamd_ip object of a sender that is provided by MTA
Parameters:
No parameters
Returns:
{rspamd_ip}
: ip address objectBack to module description.
task:set_from_ip(str)
Set tasks’s IP address based on the passed string
Parameters:
str {string}
: string representation of ipReturns:
No return
Back to module description.
task:get_client_ip()
Returns rspamd_ip object of a client connected to rspamd (normally, it is an IP address of MTA)
Parameters:
No parameters
Returns:
{rspamd_ip}
: ip address objectBack to module description.
task:get_helo()
Returns the value of SMTP helo provided by MTA.
Parameters:
No parameters
Returns:
{string}
: HELO valueBack to module description.
task:get_hostname()
Returns the value of sender’s hostname provided by MTA
Parameters:
No parameters
Returns:
{string}
: hostname valueBack to module description.
task:get_images()
Returns list of all images found in a task as a table of rspamd_image
.
Each image has the following methods:
get_width
- return width of an image in pixelsget_height
- return height of an image in pixelsget_type
- return string representation of image’s type (e.g. ‘jpeg’)get_filename
- return string with image’s file nameget_size
- return size in bytesParameters:
No parameters
Returns:
{list of rspamd_image}
: images found in a messageBack to module description.
task:get_archives()
Returns list of all archives found in a task as a table of rspamd_archive
.
Each archive has the following methods available:
get_files
- return list of strings with filenames inside archiveget_files_full
- return list of tables with all information about filesis_encrypted
- return true if an archive is encryptedget_type
- return string representation of image’s type (e.g. ‘zip’)get_filename
- return string with archive’s file nameget_size
- return size in bytesParameters:
No parameters
Returns:
{list of rspamd_archive}
: archives found in a messageBack to module description.
task:get_dkim_results()
Returns list of all dkim check results as table of maps. Callee must ensure that
dkim checks have been completed by adding dependency on DKIM_TRACE
symbol.
Fields in map:
result
- string result of check:
reject
allow
tempfail
permfail
not found
bad record
domain
- dkim domainselector
- dkim selectorbhash
- short version of b tag (8 base64 symbols)fail_reason
- reason of failure (if applicable)Parameters:
No parameters
Returns:
{list of maps}
: dkim check resultsBack to module description.
task:get_symbol(name, [shadow_result_name])
Searches for a symbol name
in all metrics results and returns a list of tables
one per metric that describes the symbol inserted.
Please note, that for using this function you need to ensure that the symbol
being queried is already checked. This is guaranteed if there is a dependency
between the caller symbol and the checked symbol (either virtual or real).
Please check rspamd_config:register_dependency
method for details.
The symbols are returned as the list of the following tables:
metric
- name of metricscore
- score of a symbol in that metricoptions
- a table of strings representing options of a symbolgroup
- a group of symbol (or ‘ungrouped’)Parameters:
name {string}
: symbol’s nameReturns:
{list of tables}
: list of tables or nil if symbol was not foundBack to module description.
task:get_symbols_all()
Returns array of symbols matched in default metric with all metadata
Parameters:
No parameters
Returns:
{table}
: table of tables formatted as in task:get_symbol()
except that metric
is absent and name
is addedBack to module description.
task:get_symbols([shadow_result_name])
Returns array of all symbols matched for this task
Parameters:
No parameters
Returns:
{table, table}
: table of strings with symbols names + table of theirs scoresBack to module description.
task:get_groups([need_private])
Returns a map [group -> group_score] for matched group. If need_private
is
unspecified, then the global option public_groups_only
is used for default.
Parameters:
No parameters
Returns:
{table, number}
: a map [group -> group_score]Back to module description.
task:get_symbols_numeric()
Returns array of all symbols matched for this task
Parameters:
No parameters
Returns:
{table|number, table|number}
: table of numbers with symbols ids + table of theirs scoresBack to module description.
task:get_symbols_tokens()
Returns array of all symbols as statistical tokens
Parameters:
No parameters
Returns:
{table|number}
: table of numbersBack to module description.
task:process_ann_tokens(symbols, ann_tokens, offset, [min])
Processes ann tokens
Parameters:
symbols {table|string}
: list of symbols in this profileann_tokens {table|number}
: list of tokens (including metatokens)offset {integer}
: offset for symbols token (#metatokens)min {number}
: minimum value for symbols found (e.g. for 0 score symbols)Returns:
Back to module description.
task:has_symbol(name, [shadow_result_name])
Fast path to check if a specified symbol is in the task’s results.
Please note, that for using this function you need to ensure that the symbol
being queried is already checked. This is guaranteed if there is a dependency
between the caller symbol and the checked symbol (either virtual or real).
Please check rspamd_config:register_dependency
method for details.
Parameters:
name {string}
: symbol’s nameReturns:
{boolean}
: true
if symbol has been foundBack to module description.
task:enable_symbol(name)
Enable specified symbol for this particular task
Parameters:
name {string}
: symbol’s nameReturns:
{boolean}
: true
if symbol has been foundBack to module description.
task:disable_symbol(name)
Disable specified symbol for this particular task
Parameters:
name {string}
: symbol’s nameReturns:
{boolean}
: true
if symbol has been foundBack to module description.
task:get_date(type[, gmt])
Returns timestamp for a connection or for a MIME message. This function can be called with a single table arguments with the following fields:
format
- a format of date returned:
message
- returns a mime date as integer (unix timestamp)connect
- returns a unix timestamp of a connection to rspamdgmt
- returns date in GMT
timezone (normal for unix timestamps)By default this function returns connection time in numeric format.
Parameters:
type {string}
: date format as described abovegmt {boolean}
: gmt flag as described aboveReturns:
{string/number}
: date representation according to formatBack to module description.
task:get_message_id()
Returns message identifier from the Message-ID
header. Angle brackets (<>
)
are stripped off if present. If a Message-ID header is missing undef
is
returned.
Parameters:
No parameters
Returns:
{string}
: ID of the messageBack to module description.
task:get_timeval([raw])
Returns the timestamp for a task start processing time.
Parameters:
raw {boolean}
: if true then two float numbers are returned: task start timestamp and timeout event timestampReturns:
{table}
: table with fields as described in struct timeval
in CBack to module description.
task:get_scan_time([set])
Returns 2 floating point numbers: scan real time and scan virtual time.
If set
is true
, then the finishing time is also set (enabled by default).
This function should be normally called on idempotent phase.
Parameters:
No parameters
Returns:
{number,number}
: real and virtual times in seconds with floating pointBack to module description.
task:get_metric_result()
Get full result of a metric as a table:
score
: current scoreaction
: current action as a stringnnegative
: number of negative rules matchednpositive
: number of positive rules matchedpositive_score
: total score for positive rulesnegative_score
: total score for negative rulespassthrough
: set to true if message has a passthrough resultParameters:
No parameters
Returns:
{table}
: metric resultBack to module description.
task:get_metric_score(name)
Get the current score of metric name
(must be nil or ‘default’) . Should be used in idempotent filters only.
Parameters:
name {string}
: name of a metricReturns:
{number,number}
: 2 numbers containing the current score and required score of the metricBack to module description.
task:get_metric_threshold(action)
Get the current threshold of the action action
for the default metric. Should be used after settings have been applied.
Parameters:
action {string}
: name of a actionReturns:
{number}
: the current threshold of the actionBack to module description.
task:get_metric_action(name)
Get the current action of metric name
(must be nil or ‘default’). Should be used in idempotent filters only.
Parameters:
name {string}
: name of a metricReturns:
{string}
: the current action of the metric as a stringBack to module description.
task:set_metric_score(name, score)
Set the current score of metric name
. Should be used in post-filters only.
Parameters:
name {string}
: name of a metricscore {number}
: the current score of the metricReturns:
No return
Back to module description.
task:set_metric_subject(subject)
Set the subject in the default metric
Parameters:
subject {string}
: subject to setReturns:
No return
Back to module description.
task:learn(is_spam[, classifier)
Learn classifier classifier
with the task. If is_spam
is true then message
is learnt as spam. Otherwise HAM is learnt. By default, this function learns
bayes
classifier.
Parameters:
is_spam {boolean}
: learn spam or hamclassifier {string}
: classifier’s nameReturns:
{boolean}
: true
if classifier has been learnt successfullyBack to module description.
task:set_settings(obj)
Set users settings object for a task. The format of this object is described here.
Parameters:
obj {any}
: any lua object that corresponds to the settings formatReturns:
No return
Back to module description.
task:set_settings_id(id)
Set users settings id for a task (must be registered previously)
Parameters:
id {number}
: numeric idReturns:
{boolean}
: true if settings id has been replaced from the existing oneAvailable in: 2.0+
Back to module description.
task:get_settings()
Gets users settings object for a task. The format of this object is described here.
Parameters:
No parameters
Returns:
{lua object}
: lua object generated from UCLBack to module description.
task:lookup_settings(key)
Gets users settings object with the specified key for a task.
Parameters:
key {string}
: key to lookupReturns:
{lua object}
: lua object generated from UCLBack to module description.
task:get_settings_id()
Get numeric hash of settings id if specified for this task. 0 is returned otherwise.
Parameters:
No parameters
Returns:
{number}
: settings-id hashBack to module description.
task:set_milter_reply(obj)
Set special reply for milter
Parameters:
obj {any}
: any lua object that corresponds to the settings formatReturns:
No return
Back to module description.
task:process_re(params)
Processes the specified regexp and returns number of captures (cached or new)
Params is the table with the following fields (mandatory fields are marked with *
):
re
* : regular expression objecttype
*: type of regular expression:
mime
: mime regexpheader
: header regexprawheader
: raw header expressionrawmime
: raw mime regexpbody
: raw body regexpurl
: url regexpheader
: for header and rawheader regexp means the name of headerstrong
: case sensitive match for headersParameters:
No parameters
Returns:
{number}
: number of regexp occurrences in the task (limited by 255 so far)Back to module description.
task:cache_set(key, value)
Store some value to the task cache
Parameters:
key {string}
: key to usevalue {any}
: any value (including functions and tables)Returns:
No return
Back to module description.
task:cache_get(key)
Returns cached value or nil if nothing is cached
Parameters:
key {string}
: key to useReturns:
{any}
: cached valueBack to module description.
task:get_size()
Returns size of the task in bytes (that includes headers + parts size)
Parameters:
No parameters
Returns:
{number}
: size in bytesBack to module description.
task:set_flag(flag_name[, set])
Set specific flag for task:
no_log
: do not log task summaryno_stat
: do not include task into scanned statspass_all
: check all filters for taskextended_urls
: output extended info about urlsskip
: skip task processinglearn_spam
: learn message as spamlearn_ham
: learn message as hambroken_headers
: header data is broken for a messageParameters:
flag {string}
: to setset {boolean}
: set or clear flag (default is set)Returns:
No return
Back to module description.
task:has_flag(flag_name)
Checks for a specific flag in task:
no_log
: do not log task summaryno_stat
: do not include task into scanned statspass_all
: check all filters for taskextended_urls
: output extended info about urlsskip
: skip task processinglearn_spam
: learn message as spamlearn_ham
: learn message as hambroken_headers
: header data is broken for a messageParameters:
flag {string}
: to checkReturns:
{boolean}
: true if flags is setBack to module description.
task:get_flags()
Get list of flags for task:
no_log
: do not log task summaryno_stat
: do not include task into scanned statspass_all
: check all filters for taskextended_urls
: output extended info about urlsskip
: skip task processinglearn_spam
: learn message as spamlearn_ham
: learn message as hambroken_headers
: header data is broken for a messagemilter
: task is initiated by milter connectionParameters:
No parameters
Returns:
{array of strings}
: table with all flags as stringsBack to module description.
task:get_digest()
Returns message’s unique digest (32 hex symbols)
Parameters:
No parameters
Returns:
{string}
: hex digestBack to module description.
task:store_in_file([mode|table])
If task was loaded using file scan, then this method just returns its name,
otherwise, a fresh temporary file is created and its name is returned. Default
mode is 0600. To convert lua number to the octal mode you can use the following
trick: tonumber("0644", 8)
. The file is automatically removed when task is
destroyed.
If table argument is specified, the following extra fields are allowed:
mode
: same as mode argumentforce_new
: always create a new filefilename
: use specific filename instead of a temporary onetmpmask
: use specific tempmask, e.g. ‘/tmp/file-XXXXX’, where XXXX will be replaced by some random letterskeep
: do not remove file after task is processedParameters:
mode {number}
: mode for new fileReturns:
{string}
: file name with task contentBack to module description.
task:get_protocol_reply([flags])
This method being called from a postfilter will return reply for a message as it is returned to a client. This method returns the Lua table corresponding to the UCL object. Flags is a table that specify which information should be there in a reply:
basic
: basic info, such as message-idmetrics
: metrics and symbolsmessages
: messagesdkim
: dkim signaturemilter
: milter control blockextra
: extra data, such as profilingurls
: list of all urls in a messageParameters:
flags {table}
: table of flags (default is all flags but urls
)Returns:
{table}
: ucl object corresponding to the replyBack to module description.
task:headers_foreach(callback, [params])
This method calls callback
for each header that satisfies some condition.
By default, all headers are iterated unless callback
returns true
. Nil or
false means continue of iterations.
Params could be as following:
full
: header value is full table of all attributes task:get_header_full
for detailsregexp
: return headers that satisfies the specified regexpParameters:
callback {function}
: function from header name and header valueparams {table}
: optional parametersReturns:
No return
Back to module description.
task:disable_action(action)
Disables some action for this task (e.g. ‘greylist’)
Parameters:
action {string}
: action to disableReturns:
{boolean}
: true if an action was enabled and is disabled after the method callBack to module description.
task:get_newlines_type()
Returns the most frequent newlines type met in a task
Parameters:
No parameters
Returns:
{string}
: “cr” for \r, “lf” for \n, “crlf” for \r\nBack to module description.
task:get_stat_tokens()
Returns list of tables the statistical tokens:
data
: 64 bit number encoded as a stringt1
: the first token (if any)t2
: the second token (if any)win
: window indexflag
: table of strings:
text
: text tokenmeta
: meta tokenlua
: lua meta tokenexception
: exceptionsubject
: subject tokenunigram
: unigram tokenParameters:
No parameters
Returns:
{table of tables}
: no descriptionBack to module description.
task:lookup_words(map, function({o, n, s, f}) ... end)
Matches words in a task (including meta words) against some map (set, regexp and so on) and call the specified function with a table containing 4 values:
Parameters:
No parameters
Returns:
No return
Back to module description.
task:get_dns_req()
Get number of dns requests being sent in the task
Parameters:
No parameters
Returns:
{number}
: number of DNS requestsBack to module description.
Back to top.