Skip to main content

An asyncio-based library to communicate with SpamAssassin's SPAMD service.

Project description

https://travis-ci.org/mjcaley/aiospamc.svg?branch=master

Description

Python asyncio-based library that implements the SPAMC/SPAMD client protocol used by SpamAssassin.

Requirements

  • Python 3.5 or higher

Example

import asyncio
import logging

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.
'''

def example():
    import email
    gtube_msg = email.message_from_string(GTUBE)

    async def print_response(title, func, *opts):
        try:
            resp = await func(*opts)
            print('----------------------------------------------------------')
            print(title, ':', repr(resp))
        except Exception as e:
            logging.exception(' '.join(['Error:', str(e)]))

    loop = asyncio.new_event_loop()
    client = aiospamc.Client(loop=loop)

    loop.run_until_complete(
        asyncio.gather(
            print_response('Ping', client.ping),
            print_response('Check', client.check, str(gtube_msg)),
            print_response('Headers', client.headers, str(gtube_msg)),
            loop=loop)
    )

    loop.close()

if __name__ == '__main__':
    example()

Project details


Release history Release notifications

History Node

0.4.1

History Node

0.4.0

History Node

0.3.0

History Node

0.2.1

History Node

0.2.0

This version
History Node

0.1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aiospamc-0.1.0-py3-none-any.whl (15.4 kB) Copy SHA256 hash SHA256 Wheel py3 Jan 11, 2017
aiospamc-0.1.0.tar.gz (10.5 kB) Copy SHA256 hash SHA256 Source None Jan 11, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page