This is a python wrapper for SpamAssassin's SPAMC deamon. It provides these methods:
- is_spam(level=5) -> bool
- SPAM status from SpamAssassin deamon
- get_score() -> float
- final score from SpamAssassin deamon
- get_fulltext() -> str
- full report from SpamAssassin deamon
- get_report_json() -> dict
- full report as JSON from SpamAssassin deamon
Install the SpamAssassin
daemon and pytest
:
sudo apt install spamassassin python-pytest
Use the PIP package manager to install this module:
python -m pip install spamassassin_client
Module can be used in following way:
import os
from spamassassin_client import SpamAssassin
FILES = [dict(type='spam', name='sample-spam.txt'),
dict(type='ham', name='sample-nonspam.txt')]
def main():
path = os.path.dirname(__file__)
for test in FILES:
filename = os.path.join(path, test['name'])
with open(filename,"rb") as f:
print("\nProcessing file: {}".format(filename))
assassin = SpamAssassin(f.read())
print(assassin)
if assassin.is_spam():
print("The received message is considered spam with a score of {0}".format(assassin.get_score()))
print('\nreport_fulltext:', assassin.get_fulltext())
print('score:', assassin.get_score())
print('report_json:', assassin.get_report_json())
if __name__ == "__main__":
main()
pytest -v
To run tests through docker, run the test.sh
script. (Linux)
chmod +x test.sh
./test.sh