7.1.1.1.6. isbg.spamproc module

Spam processing module for isbg.

isbg.spamproc.learn_mail(mail, learn_type)

Process a email and try to learn or unlearn it.

Parameters:
  • mail (email.message.Message) – email to learn.
  • learn_type (str) – `spam` to learn spam, `ham` to learn nonspam or `forget`.
Returns:

It returns a pair of int

The first integer:

A return code of 6 means it was already learned or forgotten, a return code of 5 means it has been learned or forgotten, a -9999 means an error communicating with spamc. If spamc returns an exit code, it returns it.

The second integer:

It’s the original exit code from spamc

Return type:

int, int

Notes

See Exit Codes section of the man page of spamc for more information about other exit codes.

isbg.spamproc.test_mail(mail, spamc=False, cmd=False)

Test a email with spamassassin.

class isbg.spamproc.Sa_Learn

Bases: object

Commodity class to store information about learning processes.

__init__()

Initialize SA_Learn.

tolearn = None

Number of messages to learn.

learned = None

Number of messages learned.

uids = None

The list of uids.

newpastuids = None

The new past uids.

class isbg.spamproc.Sa_Process

Bases: object

Commodity class to store information about processes.

__init__()

Initialize SA_Process.

nummsg = None

Number of processed messages.

numspam = None

Number of spams found.

spamdeleted = None

Number of deleted spam.

uids = None

The list of uids.

newpastuids = None

The new past uids.

class isbg.spamproc.SpamAssassin(**kwargs)

Bases: object

Learn and process spams from a imap account.

You usually will create an instance of it using create_from_isbg():

>>> sa = isbg.spamproc.SpamAssassin.create_from_isbg(self)

Or, if you are extending ISBG, it is created every time that you call to isbg.ISBG.do_spamassassin().

__init__(**kwargs)

Initialize a SpamAssassin object.

cmd_save

Is the command that dumps out a munged message including report.

cmd_test

Is the command to use to test if the message is spam.

classmethod create_from_isbg(sbg)

Return a instance with the required args from `ISBG`.

Parameters:sbg (isbg.ISBG) – His attributes will be used to initialize a SpamAssassin instance.
Returns:
A new created object with the required attributes
based based sbg attributes.
Return type:SpamAssassin
static get_formated_uids(uids, origpastuids, partialrun)

Get the uids formated.

Parameters:
  • uids (list(str)) – The new uids. It’s formated as: `['1 2 3 4']`
  • origpastuids (list(int)) – The original past uids.
  • partialrun (int) – If not none the number of uids to return.
Returns:

The uids formated.

It sorts the uids, remove those that are in origpastuids and returns the number defined by partialrun. If partialrun is `None` it return all.

Return type:

list(str)

learn(folder, learn_type, move_to, origpastuids)

Learn the spams (and if requested deleted or move them).

Parameters:
  • folder (str) – The IMAP folder.
  • leart_type (str) – `spam` to learn spam, `ham` to learn nonspam.
  • move_to (str) – If not `None`, the imap folder where the emails will be moved.
  • origpastuids (list(int)) – uids to not process.
Returns:

It contains the information about the result of the process.

It will call spamc to learn the emails.

Return type:

Sa_Learn

Raises:

isbg.ISBGError – if learn_type is unknown.

Todo

Add suport to learn_type=forget.

process_inbox(origpastuids)

Run spamassassin in the folder for spam.