7.1.1.1.6. isbg.spamproc module
Spam processing module for isbg.
- isbg.spamproc.__spamc_msg__ = {'already': 'Message was already un/learned', 'success': 'Message successfully un/learned'}
Used to detect already our successfully (un)learned messages.
- 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 of5
means it has been learned or forgotten, a-9999
means an error communicating withspamc
. Ifspamc
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
Number of messages to learn.
- learned
Number of messages learned.
- uids
The list of
uids
.
- newpastuids
The new past
uids
.
- class isbg.spamproc.Sa_Process
Bases:
object
Commodity class to store information about processes.
- __init__()
Initialize SA_Process.
- nummsg
Number of processed messages.
- numspam
Number of spams found.
- spamdeleted
Number of deleted spam.
- uids
The list of
uids
.
- newpastuids
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 toisbg.ISBG.do_spamassassin()
.- _required_kwargs = []
key args required when initialized.
- _kwargs = ['imap', 'spamc', 'logger', 'partialrun', 'dryrun', 'learnthendestroy', 'gmail', 'learnthenflag', 'learnunflagged', 'learnflagged', 'deletehigherthan', 'imapsets', 'maxsize', 'noreport', 'spamflags', 'delete', 'expunge']
Key args that will be used.
- __init__(**kwargs)
Initialize a SpamAssassin object.
- property cmd_save
Is the command that dumps out a munged message including report.
- property 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
- 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
- Raises
isbg.ISBGError – if learn_type is unknown.
Todo
Add suport to
learn_type=forget
.
- _process_spam(uid, score, mail, spamdeletelist, code, spamassassin_result)
- process_inbox(origpastuids)
Run spamassassin in the folder for spam.