Skip to content

Python SPAMC client for crafting requests and parsing responses

License

Notifications You must be signed in to change notification settings

petermat/spamassassin_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpamAssassin Client python module

This is a python wrapper for SpamAssissin's SPAMC deamon. It provides these methods:

is_spam(level=5) -> bool
SPAM status from SpamAssasin deamon
get_score() -> float
final score from SpamAssasin deamon
get_fulltext() -> str
full report from SpamAssasin deamon
get_report_json() -> dict
full report as JSON from SpamAssasin deamon

Installation

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

Example

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()

Run tests

pytest -v

About

Python SPAMC client for crafting requests and parsing responses

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages