Skip to content

Python SPAMC client for crafting requests and parsing responses

License

Notifications You must be signed in to change notification settings

Otach/spamassassin_client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpamAssassin Client python module

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

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

To run tests through docker, run the test.sh script. (Linux)

chmod +x test.sh
./test.sh

About

Python SPAMC client for crafting requests and parsing responses

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 95.8%
  • Dockerfile 2.8%
  • Shell 1.4%