← Documentation Index

NAME

Mailmunge::Test::Rspamd - run a message through rspamd

ABSTRACT

This class connects to an rspamd daemon and passes the input message to rspamd for evaluation.

SYNOPSIS

    package MyFilter;
    use Mailmunge::Test::Rspamd;

    sub filter_begin {
        my ($self, $ctx) = @_;
        my $test = Mailmunge::Test::Rspamd->new($self);
        my $ans = $test->rspamd_check($ctx, '127.0.0.1', 11333);
        my $resp = $ans->{response};
        if (!$ans->{results}) {
            # Failure of some kind - timeout, rspamd not running, etc.
            # Specific error message will be in $ans->{response}->message
            return $self->action_tempfail($ctx, $resp->message);
        }

        # We have rspamd results; you can inspect $ans->{results}
        # to decide what action to take, or use the code below to take
        # action based on $ans->{respones}; $ans->{response} is a
        # Mailmunge::Response object with a suggested response

        if ($self->action_from_response($ctx, $resp)) {
            # Rspamd suggested an action, which we took
            return;
        }

        # Must be: $resp->is_success so continue with rest of filter
    }

CLASS METHODS

Mailmunge::Test::Rspamd->new($filter)

Constructs a new Mailmunge::Test::Rspamd object and stores a copy of $filter in it.

INSTANCE METHODS

rspamd_check($ctx, $host, $port [, $timeout])

Connects to the rspamd daemon on the given $host and $port and asks it to evaluate the current message. $timeout is an overall timeout in seconds for rspamd to reply; if not supplied, it defaults to 300 seconds.

The return value from rspamd_check is a hash with the following elements:

response

A Mailmunge::Response object with the suggested response to the message. If something went wrong with rspamd, then the response element will be the only element in the hash. Its status will be set to TEMPFAIL and its message will contain an error message.

results

If rspamd successfully scanned the message, the results element will be a hash containing the rspamd response. This data structure is described in detail at https://www.rspamd.com/doc/architecture/protocol.php#rspamd-http-reply. It is up to the caller of rspamd_check to inspect the reply from rspamd and call appropriate functions such as action_reject, etc.

If rspamd did not successfully scan the message, then there will be no results element.

SEE ALSO

rspamd at https://www.rspamd.com/

AUTHOR

Dianne Skoll <dianne@skollsoft.com>

LICENSE

This code is licensed under the terms of the GNU General Public License, version 2.

Copyright © 2021 Skoll Software Consulting