An asyncio-based library to communicate with SpamAssassin's SPAMD service.
Project description
aiospamc is a client for SpamAssassin that you can use as a library or command line tool.
The implementation is based on asyncio; so you can use it in your applications for asynchronous calls.
The command line interface provides user-friendly access to SpamAssassin server commands and provides both JSON and user-consumable outputs.
Documentation
Detailed documentation can be found at: https://aiospamc.readthedocs.io/
Requirements
Python 3.10 or higher
certifi for updated certificate authorities
loguru for structured logging
typer for the command line interface
Examples
Command-Line Tool
aiospamc is your interface to SpamAssassin through CLI. To submit a message for a score, use:
# Take the output of gtube.msg and have SpamAssasin return a score
$ cat ./gtube.msg | aiospamc check
1000.0/5.0
# Ping the server
$ aiospamc ping
PONG
Library
import asyncio
import aiospamc
GTUBE = """Subject: Test spam mail (GTUBE)
Message-ID: <GTUBE1.1010101@example.net>
Date: Wed, 23 Jul 2003 23:30:00 +0200
From: Sender <sender@example.net>
To: Recipient <recipient@example.net>
Precedence: junk
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is the GTUBE, the
Generic
Test for
Unsolicited
Bulk
Email
If your spam filter supports it, the GTUBE provides a test by which you
can verify that the filter is installed correctly and is detecting incoming
spam. You can send yourself a test mail containing the following string of
characters (in upper case and with no white spaces and line breaks):
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
You should send this test mail from an account outside of your network.
""".encode("ascii")
# Ping the SpamAssassin server
async def is_alive():
pong = await aiospamc.ping()
return True if pong.status_code == 0 else False
asyncio.run(is_alive())
# True
# Get the spam score of a message
async def get_score(message):
response = await aiospamc.check(message)
return response.headers.spam.score, response.headers.spam.threshold
asyncio.run(get_score(GTUBE))
# (1000.0, 5.0)
# List the modified headers
async def list_headers(message):
response = await aiospamc.headers(message)
for line in response.body.splitlines():
print(line.decode())
asyncio.run(list_headers(GTUBE))
# Received: from localhost by DESKTOP.
# with SpamAssassin (version 4.0.0);
# Wed, 30 Aug 2023 20:11:34 -0400
# From: Sender <sender@example.net>
# To: Recipient <recipient@example.net>
# Subject: Test spam mail (GTUBE)
# Date: Wed, 23 Jul 2003 23:30:00 +0200
# Message-Id: <GTUBE1.1010101@example.net>
# X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-14) on DESKTOP.
# X-Spam-Flag: YES
# X-Spam-Level: **************************************************
# X-Spam-Status: Yes, score=1000.0 required=5.0 tests=GTUBE,NO_RECEIVED,
# NO_RELAYS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no
# version=4.0.0
# MIME-Version: 1.0
# Content-Type: multipart/mixed; boundary="----------=_64EFDAB6.3640FAEF"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiospamc-1.2.0.tar.gz.
File metadata
- Download URL: aiospamc-1.2.0.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3933d5529ef54e48a183d7cdf2e63ca947e53d63645911ed29ece5e19d627183
|
|
| MD5 |
8db0c9977851774f1ad87a1700338a2a
|
|
| BLAKE2b-256 |
4436887f7d742facf1ba5b72b39cd4a24c26c7fbac15af5051be110a3d0c8feb
|
Provenance
The following attestation bundles were made for aiospamc-1.2.0.tar.gz:
Publisher:
release.yml on mjcaley/aiospamc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiospamc-1.2.0.tar.gz -
Subject digest:
3933d5529ef54e48a183d7cdf2e63ca947e53d63645911ed29ece5e19d627183 - Sigstore transparency entry: 610740177
- Sigstore integration time:
-
Permalink:
mjcaley/aiospamc@70fca8aafc2cfe64e4a25c5e22ff1fdecc7ed46e -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/mjcaley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@70fca8aafc2cfe64e4a25c5e22ff1fdecc7ed46e -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiospamc-1.2.0-py3-none-any.whl.
File metadata
- Download URL: aiospamc-1.2.0-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ede83a51f8e4b413c8e6d29bb471f546f16ac2633bd6704105b5da74cab4f9
|
|
| MD5 |
52c7c6912fd8075452c86d5f231e57ab
|
|
| BLAKE2b-256 |
501579fa55c0c7d68a6b13c43658ad24c67acf600caacc56ad38456e85544c71
|
Provenance
The following attestation bundles were made for aiospamc-1.2.0-py3-none-any.whl:
Publisher:
release.yml on mjcaley/aiospamc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiospamc-1.2.0-py3-none-any.whl -
Subject digest:
26ede83a51f8e4b413c8e6d29bb471f546f16ac2633bd6704105b5da74cab4f9 - Sigstore transparency entry: 610740307
- Sigstore integration time:
-
Permalink:
mjcaley/aiospamc@70fca8aafc2cfe64e4a25c5e22ff1fdecc7ed46e -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/mjcaley
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@70fca8aafc2cfe64e4a25c5e22ff1fdecc7ed46e -
Trigger Event:
push
-
Statement type: