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.
-
sleep_len
¶ float
– Length of time to wait to retry a connection in seconds.
-
retry_attempts
¶ float
– Number of times to retry a connection.
-
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.- socket_path (
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
coroutine
ping
()¶ Sends a ping request to the SPAMD service and will receive a response if the serivce is alive.
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
coroutine
send
(request)¶ Sends a request to the SPAMD service.
If the SPAMD service gives a temporary failure response, then
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
-
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: Raises: aiospamc.exceptions.BadResponse
– If the response from SPAMD is ill-formed this exception will be raised.aiospamc.exceptions.AIOSpamcConnectionFailed
– Raised if an error occurred when trying to connect.aiospamc.exceptions.UsageException
– Error in command line usage.aiospamc.exceptions.DataErrorException
– Error with data format.aiospamc.exceptions.NoInputException
– Cannot open input.aiospamc.exceptions.NoUserException
– Addressee unknown.aiospamc.exceptions.NoHostException
– Hostname unknown.aiospamc.exceptions.UnavailableException
– Service unavailable.aiospamc.exceptions.InternalSoftwareException
– Internal software error.aiospamc.exceptions.OSErrorException
– System error.aiospamc.exceptions.OSFileException
– Operating system file missing.aiospamc.exceptions.CantCreateException
– Cannot create output file.aiospamc.exceptions.IOErrorException
– Input/output error.aiospamc.exceptions.TemporaryFailureException
– Temporary failure, may reattempt.aiospamc.exceptions.ProtocolException
– Error in the protocol.aiospamc.exceptions.NoPermissionException
– Permission denied.aiospamc.exceptions.ConfigException
– Error in configuration.aiospamc.exceptions.TimeoutException
– Timeout during connection.
- message_class (
-