aiospamc.client module

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

class aiospamc.client.Client(socket_path='/var/run/spamassassin/spamd.sock', host=None, port=783, user=None, compress=False, ssl=False, loop=None)

Bases: object

Client object for interacting with SPAMD.

connection

aiospamc.connections.ConnectionManager – Manager instance to open connections.

user

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

compress

bool – If true, the request body will be compressed.

loop

asyncio.AbstractEventLoop – The asyncio event loop.

logger

logging.Logger – Logging instance, logs to ‘aiospamc.client’

__init__(socket_path='/var/run/spamassassin/spamd.sock', host=None, port=783, user=None, compress=False, ssl=False, loop=None)

Client constructor.

Parameters:
  • socket_path (str, optional) – The path to the Unix socket for the SPAMD service.
  • host (str, optional) – Hostname or IP address of the SPAMD service, defaults to localhost.
  • port (int, optional) – Port number for the SPAMD service, defaults to 783.
  • user (str, optional) – Name of the user that SPAMD will run the checks under.
  • compress (bool, optional) – If true, the request body will be compressed.
  • ssl (bool, optional) – If true, will enable SSL/TLS for the connection.
  • loop (asyncio.AbstractEventLoop) – 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.

coroutine check(message)

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

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

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

Parameters:

message (str) –

A 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:

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

Return type:

aiospamc.responses.Response

Raises:
coroutine headers(message)

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

Parameters:

message (str) –

A 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:

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain the modified headers of the message.

Return type:

aiospamc.responses.Response

Raises:
coroutine ping()

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

Returns:

Response message will contain ‘PONG’ if successful.

Return type:

aiospamc.responses.Response

Raises:
coroutine process(message)

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

Parameters:

message (str) –

A 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:

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain a modified version of the message.

Return type:

aiospamc.responses.Response

Raises:
coroutine report(message)

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

Parameters:

message (str) –

A 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:

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain a report composed by the SPAMD service.

Return type:

aiospamc.responses.Response

Raises:
coroutine report_if_spam(message)

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

Parameters:

message (str) –

A 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:

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain a report composed by the SPAMD service only if message is marked as being spam.

Return type:

aiospamc.responses.Response

Raises:
coroutine send(request)

Sends a request to the SPAMD service.

If the SPAMD service gives a temporary failure response, then

Parameters:

request (aiospamc.requests.Request) – Request object to send.

Returns:

Return type:

aiospamc.responses.Response

Raises:
coroutine symbols(message)

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

The response will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

Parameters:

message (str) –

A 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:

Will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain a comma separated list of all the rule names.

Return type:

aiospamc.responses.Response

Raises:
coroutine tell(message_class, message, remove_action=None, set_action=None)

Instruct the SPAMD service to to mark the message

Parameters:
  • message_class (aiospamc.options.MessageClassOption) – An enumeration to classify the message as ‘spam’ or ‘ham.’
  • message (str) –

    A 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.

  • remove_action (aiospamc.options.ActionOption) – Remove message class for message in database.
  • set_action (aiospamc.options.ActionOption) – Set message class for message in database.
Returns:

Will contain a ‘Spam’ header if the message is marked as spam as well as the score and threshold.

The body will contain a report composed by the SPAMD service only if message is marked as being spam.

Return type:

aiospamc.responses.Response

Raises: