aiospamc package

Submodules

aiospamc.client module

Contains the Client class that is used to interact with SPAMD.

class aiospamc.client.Client(socket_path: str = None, host: str = 'localhost', port: int = 783, user: str = None, compress: bool = False, verify: Union[bool, str, pathlib.Path] = None, loop: asyncio.events.AbstractEventLoop = None)[source]

Bases: object

Client object for interacting with SPAMD.

__init__(socket_path: str = None, host: str = 'localhost', port: int = 783, user: str = None, compress: bool = False, verify: Union[bool, str, pathlib.Path] = None, loop: asyncio.events.AbstractEventLoop = None)None[source]

Client constructor.

Parameters
  • socket_path – The path to the Unix socket for the SPAMD service.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • user – Name of the user that SPAMD will run the checks under.

  • compress – If true, the request body will be compressed.

  • verify – Use SSL for the connection. If True, will use root certificates. If False, will not verify the certificate. If a string to a path or a Path object, the connection will use the certificates found there.

  • loop – The asyncio event loop.

Raises

ValueError – Raised if the constructor can’t tell if it’s using a TCP or a Unix domain socket connection.

static new_ssl_context(value: Union[bool, str, pathlib.Path])ssl.SSLContext[source]

Creates an SSL context based on the supplied parameter.

Parameters

value – Use SSL for the connection. If True, will use root certificates. If False, will not verify the certificate. If a string to a path or a Path object, the connection will use the certificates found there.

async send(request: aiospamc.requests.Request)aiospamc.responses.Response[source]

Sends a request to the SPAMD service.

If the SPAMD service gives a temporary failure response, then its retried.

Parameters

request – Request object to send.

Raises
async check(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Request the SPAMD service to check a message.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score.

Raises
async headers(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Request the SPAMD service to check a message with a HEADERS request.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains the modified message headers, but not the content of the message.

Raises
async ping()aiospamc.responses.Response[source]

Sends a ping request to the SPAMD service and will receive a response if the service is alive.

Returns

A response with “PONG”.

Raises
async process(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Process the message and return a modified copy of the message.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a modified copy of the message.

Raises
async report(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Check if message is spam and return report.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a report.

Raises
async report_if_spam(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Check if a message is spam and return a report if the message is spam.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a report if the message is considered spam.

Raises
async symbols(message: Union[bytes, SupportsBytes])aiospamc.responses.Response[source]

Check if the message is spam and return a list of symbols that were hit.

Parameters

message

A byte string containing the contents of the message to be scanned.

SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a comma-separated list of the symbols that were hit.

Raises
async tell(message: Union[bytes, SupportsBytes], message_class: Union[str, aiospamc.options.MessageClassOption], remove_action: Union[str, aiospamc.options.ActionOption] = None, set_action: Union[str, aiospamc.options.ActionOption] = None)[source]

Instruct the SPAMD service to to mark the message.

Parameters
  • message

    A byte string containing the contents of the message to be scanned.

    SPAMD will perform a scan on the included message. SPAMD expects an RFC 822 or RFC 2822 formatted email.

  • message_class – How to classify the message, either “ham” or “spam”.

  • remove_action – Remove message class for message in database.

  • set_action – Set message class for message in database. Either ham or spam.

Returns

A successful response with “DidSet” and/or “DidRemove” headers along with the actions that were taken.

Raises

aiospamc.common module

Common classes for the project.

class aiospamc.common.SpamcBody[source]

Bases: object

Provides a descriptor for a bytes-like object.

class aiospamc.common.SpamcHeaders(*, headers: Mapping[str, Union[aiospamc.header_values.HeaderValue, str, Any]] = None)[source]

Bases: object

Provides a dictionary-like interface for headers.

__init__(*, headers: Mapping[str, Union[aiospamc.header_values.HeaderValue, str, Any]] = None)None[source]

Initialize self. See help(type(self)) for accurate signature.

keys() → KeysView[str][source]
items() → ItemsView[str, aiospamc.header_values.HeaderValue][source]
values() → ValuesView[aiospamc.header_values.HeaderValue][source]

aiospamc.exceptions module

Collection of exceptions.

exception aiospamc.exceptions.ClientException[source]

Bases: Exception

Base class for exceptions raised from the client.

exception aiospamc.exceptions.BadRequest[source]

Bases: aiospamc.exceptions.ClientException

Request is not in the expected format.

exception aiospamc.exceptions.BadResponse[source]

Bases: aiospamc.exceptions.ClientException

Response is not in the expected format.

exception aiospamc.exceptions.AIOSpamcConnectionException[source]

Bases: Exception

Base class for exceptions from the connection.

exception aiospamc.exceptions.AIOSpamcConnectionFailed[source]

Bases: aiospamc.exceptions.AIOSpamcConnectionException

Connection failed.

exception aiospamc.exceptions.ResponseException[source]

Bases: Exception

Base class for exceptions raised from a response.

exception aiospamc.exceptions.UsageException[source]

Bases: aiospamc.exceptions.ResponseException

Command line usage error.

code = 64
exception aiospamc.exceptions.DataErrorException[source]

Bases: aiospamc.exceptions.ResponseException

Data format error.

code = 65
exception aiospamc.exceptions.NoInputException[source]

Bases: aiospamc.exceptions.ResponseException

Cannot open input.

code = 66
exception aiospamc.exceptions.NoUserException[source]

Bases: aiospamc.exceptions.ResponseException

Addressee unknown.

code = 67
exception aiospamc.exceptions.NoHostException[source]

Bases: aiospamc.exceptions.ResponseException

Hostname unknown.

code = 68
exception aiospamc.exceptions.UnavailableException[source]

Bases: aiospamc.exceptions.ResponseException

Service unavailable.

code = 69
exception aiospamc.exceptions.InternalSoftwareException[source]

Bases: aiospamc.exceptions.ResponseException

Internal software error.

code = 70
exception aiospamc.exceptions.OSErrorException[source]

Bases: aiospamc.exceptions.ResponseException

System error (e.g. can’t fork the process).

code = 71
exception aiospamc.exceptions.OSFileException[source]

Bases: aiospamc.exceptions.ResponseException

Critical operating system file missing.

code = 72
exception aiospamc.exceptions.CantCreateException[source]

Bases: aiospamc.exceptions.ResponseException

Can’t create (user) output file.

code = 73
exception aiospamc.exceptions.IOErrorException[source]

Bases: aiospamc.exceptions.ResponseException

Input/output error.

code = 74
exception aiospamc.exceptions.TemporaryFailureException[source]

Bases: aiospamc.exceptions.ResponseException

Temporary failure, user is invited to try again.

code = 75
exception aiospamc.exceptions.ProtocolException[source]

Bases: aiospamc.exceptions.ResponseException

Remote error in protocol.

code = 76
exception aiospamc.exceptions.NoPermissionException[source]

Bases: aiospamc.exceptions.ResponseException

Permission denied.

code = 77
exception aiospamc.exceptions.ConfigException[source]

Bases: aiospamc.exceptions.ResponseException

Configuration error.

code = 78
exception aiospamc.exceptions.TimeoutException[source]

Bases: aiospamc.exceptions.ResponseException

Read timeout.

code = 79

aiospamc.header_values module

Collection of request and response header value objects.

class aiospamc.header_values.HeaderValue[source]

Bases: object

class aiospamc.header_values.GenericHeaderValue(value: str, encoding='utf8')[source]

Bases: aiospamc.header_values.HeaderValue

Generic header value.

__init__(value: str, encoding='utf8')None[source]

Initialize self. See help(type(self)) for accurate signature.

class aiospamc.header_values.CompressValue(algorithm='zlib')[source]

Bases: aiospamc.header_values.HeaderValue

Compress header. Specifies what encryption scheme to use. So far only ‘zlib’ is supported.

__init__(algorithm='zlib')None[source]

Constructor

Parameters

algorithm – Compression algorithm to use. Currently on zlib is supported.

class aiospamc.header_values.ContentLengthValue(length: int = 0)[source]

Bases: aiospamc.header_values.HeaderValue

ContentLength header. Indicates the length of the body in bytes.

__init__(length: int = 0)None[source]

ContentLength constructor.

Parameters

length – Length of the body.

class aiospamc.header_values.MessageClassValue(value: aiospamc.options.MessageClassOption = None)[source]

Bases: aiospamc.header_values.HeaderValue

MessageClass header. Used to specify whether a message is ‘spam’ or ‘ham.’

__init__(value: aiospamc.options.MessageClassOption = None)None[source]

MessageClass constructor.

Parameters

value – Specifies the classification of the message.

class aiospamc.header_values.SetOrRemoveValue(action: aiospamc.options.ActionOption = None)[source]

Bases: aiospamc.header_values.HeaderValue

Base class for headers that implement “local” and “remote” rules.

__init__(action: aiospamc.options.ActionOption = None)None[source]

_SetRemoveBase constructor.

Parameters

action – Actions to be done on local or remote.

class aiospamc.header_values.SpamValue(value: bool = False, score: float = 0.0, threshold: float = 0.0)[source]

Bases: aiospamc.header_values.HeaderValue

Spam header. Used by the SPAMD service to report on if the submitted message was spam and the score/threshold that it used.

__init__(value: bool = False, score: float = 0.0, threshold: float = 0.0)None[source]

Spam header constructor.

Parameters
  • value – True if the message is spam, False if not.

  • score – Score of the message after being scanned.

  • threshold – Threshold of which the message would have been marked as spam.

class aiospamc.header_values.UserValue(name: str = None)[source]

Bases: aiospamc.header_values.HeaderValue

User header. Used to specify which user the SPAMD service should use when loading configuration files.

__init__(name: str = None)None[source]

User constructor.

Parameters

name – Name of the user account.

aiospamc.incremental_parser module

Module for the parsing functions and objects.

exception aiospamc.incremental_parser.ParseError(message=None)[source]

Bases: Exception

Error occurred while parsing.

__init__(message=None)None[source]

Construct parsing exception with optional message.

Parameters

message – User friendly message.

exception aiospamc.incremental_parser.NotEnoughDataError(message=None)[source]

Bases: aiospamc.incremental_parser.ParseError

Expected more data than what the protocol content specified.

exception aiospamc.incremental_parser.TooMuchDataError(message=None)[source]

Bases: aiospamc.incremental_parser.ParseError

Too much data was received than what the protocol content specified.

class aiospamc.incremental_parser.States(value)[source]

Bases: enum.Enum

States for the parser state machine.

Status = 1
Header = 2
Body = 3
Done = 4
class aiospamc.incremental_parser.Parser(delimiter: bytes, status_parser: Callable[bytes, Mapping[str, str]], header_parser: Callable[bytes, Tuple[str, Any]], body_parser: Callable[[bytes, int], bytes], start: aiospamc.incremental_parser.States = <States.Status: 1>)[source]

Bases: object

The parser state machine.

Variables

result – Storage location for parsing results.

__init__(delimiter: bytes, status_parser: Callable[bytes, Mapping[str, str]], header_parser: Callable[bytes, Tuple[str, Any]], body_parser: Callable[[bytes, int], bytes], start: aiospamc.incremental_parser.States = <States.Status: 1>)None[source]

Parser constructor.

Parameters
  • delimiter – Byte string to split the different sections of the message.

  • status_parser – Callable to parse the status line of the message.

  • header_parser – Callable to parse each header line of the message.

  • body_parser – Callable to parse the body of the message.

  • start – The state to start the parser on. Allowed for easier testing.

property state

The current state of the parser.

Returns

The States instance.

parse(stream: bytes) → Mapping[str, Any][source]

Entry method to parse a message.

Parameters

stream – Byte string to parse.

Returns

Returns the parser results dictionary stored in the class attribute result.

Raises
status()None[source]

Splits the message at the delimiter and sends the first part of the message to the status_line callable to be parsed. If successful then the results are stored in the result class attribute and the state transitions to States.Header.

Raises
  • NotEnoughDataError – When there is no delimiter the message is incomplete.

  • ParseError – When the status_line callable experiences an error.

header()None[source]

Splits the message at the delimiter and sends the line to the header_parser.

When splitting the action will be determined depending what is matched:

Header line

Delimiter

Leftover

Action

No

Yes

Delimiter

Headers done, empty body. Clear buffer and transition to States.Body.

No

Yes

N/A

Headers done. Transition to States.Body.

Yes

Yes

N/A

Parse header. Record in result class attribute.

No

No

No

Message was a status line only. Transition to States.Body.

Raises

ParseError – None of the previous conditions are matched.

body()None[source]

Uses the length defined in the Content-length header (defaulted to 0) to determine how many bytes the body contains.

Raises

TooMuchDataError – When there are too many bytes in the buffer compared to the Content-length header value. Transitions the state to States.Done.

aiospamc.incremental_parser.parse_request_status(stream: bytes) → Dict[str, str][source]

Parses the status line from a request.

Parameters

stream – The byte stream to parse.

Returns

A dictionary with the keys verb, protocol and version.

Raises

ParseError – When the status line is in an invalid format, not a valid verb, or doesn’t have the correct protocol.

aiospamc.incremental_parser.parse_response_status(stream: bytes) → Dict[str, str][source]

Parse the status line for a response.

Parameters

stream – The byte stream to parse.

Returns

A dictionary with the keys protocol, version, status_code, and message.

Raises

ParseError – When the status line is in an invalid format, status code is not an integer, or doesn’t have the correct protocol.

aiospamc.incremental_parser.parse_message_class_value(stream: Union[str, aiospamc.options.MessageClassOption])aiospamc.header_values.MessageClassValue[source]

Parses the Message-class header value.

Parameters

stream – String or MessageClassOption instance.

Returns

A MessageClassValue instance representing the value.

Raises

ParseError – When the value doesn’t match either ham or spam.

aiospamc.incremental_parser.parse_content_length_value(stream: Union[str, int])aiospamc.header_values.ContentLengthValue[source]

Parses the Content-length header value.

Parameters

stream – String or integer value of the header.

Returns

A ContentLengthValue instance.

Raises

ParseError – When the value cannot be cast to an integer.

aiospamc.incremental_parser.parse_compress_value(stream: str)aiospamc.header_values.CompressValue[source]

Parses a value for the Compress header.

Parameters

stream – String to parse.

Returns

A CompressValue instance.

aiospamc.incremental_parser.parse_set_remove_value(stream: Union[aiospamc.options.ActionOption, str])aiospamc.header_values.SetOrRemoveValue[source]

Parse a value for the DidRemove, DidSet, Remove, and Set headers.

Parameters

stream – String to parse or an instance of ActionOption.

Returns

A SetOrRemoveValue instance.

aiospamc.incremental_parser.parse_spam_value(stream: str)aiospamc.header_values.SpamValue[source]

Parses the values for the Spam header.

Parameters

stream – String to parse.

Returns

An SpamValue instance.

Raises

ParseError – Raised if there is no true/false value, or valid numbers for the score or threshold.

aiospamc.incremental_parser.parse_user_value(stream: str)aiospamc.header_values.UserValue[source]
aiospamc.incremental_parser.parse_generic_header_value(stream: str)aiospamc.header_values.GenericHeaderValue[source]

Parses any user-defined or currently unknown header values.

Parameters

stream – String to parse.

Returns

A GenericHeaderValue instance.

aiospamc.incremental_parser.parse_header_value(header: str, value: Union[str, bytes])aiospamc.header_values.HeaderValue[source]

Sends the header value stream to the header value parsing function.

Parameters
  • header – Name of the header.

  • value – String or byte stream of the header value.

Returns

The HeaderValue instance from the parsing function.

aiospamc.incremental_parser.parse_header(stream: bytes) → Tuple[str, aiospamc.header_values.HeaderValue][source]

Splits the header line and sends to the header parsing function.

Parameters

stream – Byte stream of the header line.

Returns

A tuple of the header name and value.

aiospamc.incremental_parser.parse_body(stream: bytes, content_length: int)bytes[source]

Parses the body of a message.

Parameters
  • stream – Byte stream for the body.

  • content_length – Expected length of the body in bytes.

Returns

Byte stream of the body.

Raises
aiospamc.incremental_parser.header_value_parsers = {'Compress': <function parse_compress_value>, 'Content-length': <function parse_content_length_value>, 'DidRemove': <function parse_set_remove_value>, 'DidSet': <function parse_set_remove_value>, 'Message-class': <function parse_message_class_value>, 'Remove': <function parse_set_remove_value>, 'Set': <function parse_set_remove_value>, 'Spam': <function parse_spam_value>, 'User': <function parse_user_value>}

Mapping for header names to their parsing functions.

class aiospamc.incremental_parser.RequestParser[source]

Bases: aiospamc.incremental_parser.Parser

Sub-class of the parser for requests.

__init__()[source]

Parser constructor.

Parameters
  • delimiter – Byte string to split the different sections of the message.

  • status_parser – Callable to parse the status line of the message.

  • header_parser – Callable to parse each header line of the message.

  • body_parser – Callable to parse the body of the message.

  • start – The state to start the parser on. Allowed for easier testing.

class aiospamc.incremental_parser.ResponseParser[source]

Bases: aiospamc.incremental_parser.Parser

Sub-class of the parser for responses.

__init__()[source]

Parser constructor.

Parameters
  • delimiter – Byte string to split the different sections of the message.

  • status_parser – Callable to parse the status line of the message.

  • header_parser – Callable to parse each header line of the message.

  • body_parser – Callable to parse the body of the message.

  • start – The state to start the parser on. Allowed for easier testing.

aiospamc.options module

Data structures used for function parameters.

class aiospamc.options.MessageClassOption(value)[source]

Bases: enum.IntEnum

Option to be used for the MessageClass header.

spam = 1
ham = 2
class aiospamc.options.ActionOption(local, remote)

Bases: tuple

Option to be used in the DidRemove, DidSet, Set, and Remove headers.

localbool

An action will be performed on the SPAMD service’s local database.

remotebool

An action will be performed on the SPAMD service’s remote database.

property local

Alias for field number 0

property remote

Alias for field number 1

aiospamc.requests module

Contains all requests that can be made to the SPAMD service.

class aiospamc.requests.Request(verb: str = None, version: str = '1.5', headers: Mapping[str, Union[str, aiospamc.header_values.HeaderValue]] = None, body: Union[bytes, SupportsBytes] = b'', **_)[source]

Bases: object

SPAMC request object.

__init__(verb: str = None, version: str = '1.5', headers: Mapping[str, Union[str, aiospamc.header_values.HeaderValue]] = None, body: Union[bytes, SupportsBytes] = b'', **_)None[source]

Request constructor.

Parameters
  • verb – Method name of the request.

  • version – Version of the protocol.

  • headers – Collection of headers to be added.

  • body – Byte string representation of the body.

body

Provides a descriptor for a bytes-like object.

aiospamc.responses module

Contains classes used for responses.

class aiospamc.responses.Status(value)[source]

Bases: enum.IntEnum

Enumeration of status codes that the SPAMD will accompany with a response.

Reference: https://svn.apache.org/repos/asf/spamassassin/trunk/spamd/spamd.raw Look for the %resphash variable.

EX_OK = 0
EX_USAGE = 64
EX_DATAERR = 65
EX_NOINPUT = 66
EX_NOUSER = 67
EX_NOHOST = 68
EX_UNAVAILABLE = 69
EX_SOFTWARE = 70
EX_OSERR = 71
EX_OSFILE = 72
EX_CANTCREAT = 73
EX_IOERR = 74
EX_TEMPFAIL = 75
EX_PROTOCOL = 76
EX_NOPERM = 77
EX_CONFIG = 78
EX_TIMEOUT = 79
class aiospamc.responses.Response(version: str = '1.5', status_code: int = 0, message: str = '', headers: Mapping[str, aiospamc.header_values.HeaderValue] = None, body: bytes = b'', **_)[source]

Bases: object

Class to encapsulate response.

__init__(version: str = '1.5', status_code: int = 0, message: str = '', headers: Mapping[str, aiospamc.header_values.HeaderValue] = None, body: bytes = b'', **_)[source]

Response constructor.

Parameters
  • version – Version reported by the SPAMD service response.

  • status_code – Success or error code.

  • message – Message associated with status code.

  • body – Byte string representation of the body.

  • headers – Collection of headers to be added.

body

Provides a descriptor for a bytes-like object.

raise_for_status()None[source]

Module contents

aiospamc package.

An asyncio-based library to communicate with SpamAssassin’s SPAMD service.

async aiospamc.check(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score.

Raises
async aiospamc.headers(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return the modified message headers.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains the modified message headers, but not the content of the message.

Raises
async aiospamc.ping(*, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Sends a ping to the SPAMD service.

Parameters
  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A response with “PONG”.

Raises
async aiospamc.process(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a modified copy of the message.

Raises
async aiospamc.report(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a report.

Raises
async aiospamc.report_if_spam(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a report if the message is considered spam.

Raises
async aiospamc.symbols(message: Union[bytes, SupportsBytes], *, host: str = 'Localhost', port: int = 783, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with a “Spam” header showing if the message is considered spam as well as the score. The body contains a comma-separated list of the symbols that were hit.

Raises
async aiospamc.tell(message: Union[bytes, SupportsBytes], message_class: Union[str, aiospamc.options.MessageClassOption], *, host: str = 'Localhost', port: int = 783, remove_action: Union[str, aiospamc.options.ActionOption] = None, set_action: Union[str, aiospamc.options.ActionOption] = None, loop: asyncio.events.AbstractEventLoop = None, **kwargs)aiospamc.responses.Response[source]

Checks a message if it’s spam and return a response with a score header.

Parameters
  • message – Copy of the message.

  • message_class – How to classify the message, either “ham” or “spam”.

  • host – Hostname or IP address of the SPAMD service, defaults to localhost.

  • port – Port number for the SPAMD service, defaults to 783.

  • loop – The asyncio event loop.

  • kwargs – Additional options to pass to the aiospamc.client.Client instance.

Returns

A successful response with “DidSet” and/or “DidRemove” headers along with the actions that were taken.

Raises