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
6means it was already learned or forgotten, a return code of5means it has been learned or forgotten, a-9999means an error communicating withspamc. Ifspamcreturns 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
spamcfor 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:
objectCommodity 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:
objectCommodity 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:
objectLearn 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
uidsto return.
- Returns
The
uidsformated.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)) –
uidsto not process.
- Returns
It contains the information about the result of the process.
It will call
spamcto 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.
-