pydspam
1.4
|
Operations on the DSPAM directory. More...
Public Member Functions | |
def | __init__ (self, userdir) |
Initialize DSpamDirectory. More... | |
def | dspam_ctx (self, op, flags=0, user=None) |
Create dspam.ctx using configured defaults. More... | |
def | get_group (self, user) |
Return group user belongs to. More... | |
def | user_files (self, user) |
Set username and return common pathnames. More... | |
def | check_spam (self, user, txt, recipients=None, classify=False, quarantine=True, force_result=None) |
Check spaminess of a message. More... | |
def | write_web_stats (self, totals) |
Update dspam stats stored as text for the web interface. More... | |
def | add_spam (self, user, txt) |
Report a false negative. More... | |
def | false_positive (self, user, txt) |
Report a false positive. More... | |
Public Attributes | |
userdir | |
DSPAM home. More... | |
groupfile | |
Path of group definition file. More... | |
log | |
Logging method. | |
headerchange | |
Hook for changing mail headers in the MTA to mirror changes by Dspam. More... | |
username | |
The dspam user current being processed. | |
probability | |
The spam score from 0.0 to 1.0. | |
factors | |
The top tokens that determined the spam score. | |
algorithms | |
Default spam score algorithms to use. | |
tokenizer | |
Default tokenizer. | |
training | |
Training mode. More... | |
totals | |
DSPAM totals for user from last operation. | |
result | |
Classification from last check_spam. | |
mbox | |
Path of quarantine mailbox used by pydspam for user. More... | |
lock | |
Path of lock file used by libdspam. More... | |
dspam_dict | |
dspam_stats | |
sigfile | |
Private Member Functions | |
def | _lognull (self, *msg) |
def | _add_sig (self, txt, sig, recipients=None) |
Add signature key to message, and quarantine if spammy. More... | |
def | _feedback (self, user, txt, op, queue=False) |
def | _innoc (self, user, sigs, op) |
Operations on the DSPAM directory.
def Dspam.DSpamDirectory.__init__ | ( | self, | |
userdir | |||
) |
Initialize DSpamDirectory.
The base directory is something like /var/lib/dspam
.
userdir | the DSPAM base directory |
|
private |
Add signature key to message, and quarantine if spammy.
The results of the last check_spam as used.
txt | the message bytes |
sig | the signature |
recipients | list of recipients for later delivery |
References Dspam.add_signature_tag(), Dspam.DSpamDirectory.dspam_ctx(), Dspam.DSpamDirectory.factors, Dspam.DSpamDirectory.headerchange, Dspam.DSpamDirectory.log, Dspam.DSpamDirectory.mbox, Dspam.DSpamDirectory.probability, Dspam.put_signature(), Dspam.DSpamDirectory.result, and Dspam.DSpamDirectory.write_web_stats().
Referenced by Dspam.DSpamDirectory.check_spam().
def Dspam.DSpamDirectory.add_spam | ( | self, | |
user, | |||
txt | |||
) |
Report a false negative.
Tell DSPAM a message it though was innocent is actually spam. DSPAM looks for signature keys, and looks up stored signatures with them. It trains DSPAM with the signature, setting the source to DSS_ERROR. If no signature is found, it adds the spam as a spam "corpus".
user | str - the DSPAM user |
txt | bytes - the spam message |
References Dspam.DSpamDirectory._feedback(), and Dspam.DSpamDirectory.probability.
def Dspam.DSpamDirectory.check_spam | ( | self, | |
user, | |||
txt, | |||
recipients = None , |
|||
classify = False , |
|||
quarantine = True , |
|||
force_result = None |
|||
) |
Check spaminess of a message.
user | the dspam user (email account) |
txt | the message as bytes collected from the MTA |
recipients | If provided, a list of recipients to record in quarantined messages to assist later delivery. |
classify | |
quarantine | Add messages classified as spam to mbox quarantine if true. |
force_result | train as this result |
References Dspam.DSpamDirectory._add_sig(), Dspam.DSpamDirectory._innoc(), Dspam.convert_eol(), Dspam.DSpamDirectory.dspam_ctx(), Dspam.DSpamDirectory.factors, Dspam.DSpamDirectory.lock, Dspam.DSpamDirectory.probability, Dspam.DSpamDirectory.result, and Dspam.DSpamDirectory.user_files().
def Dspam.DSpamDirectory.dspam_ctx | ( | self, | |
op, | |||
flags = 0 , |
|||
user = None |
|||
) |
Create dspam.ctx using configured defaults.
E.g.
with self.dspam_ctx(dspam.DSM_CLASSIFY) as ds: ds.process(txt) self.result = ds.result
op | dspam operation mode: one of dspam.DSM_* |
flags | dspam operation flags: set of dspam.DSF_* |
user | str - a different user, e.g. for innoculation |
References Dspam.DSpamDirectory.algorithms, Dspam.DSpamDirectory.tokenizer, Dspam.DSpamDirectory.totals, Dspam.DSpamDirectory.training, Dspam.DSpamDirectory.userdir, and Dspam.DSpamDirectory.username.
Referenced by Dspam.DSpamDirectory._add_sig(), Dspam.DSpamDirectory.check_spam(), and Dspam.DSpamDirectory.write_web_stats().
def Dspam.DSpamDirectory.false_positive | ( | self, | |
user, | |||
txt | |||
) |
Report a false positive.
Tell DSPAM a message it though was spam is actually innocent. DSPAM looks for signature keys, and looks up stored signatures with them. It trains DSPAM with the signature, setting the source to DSS_ERROR. If no signature is found, it adds the message as an innocent "corpus" (DSS_CORPUS).
user | str - the DSPAM user |
txt | bytes - the innocent message bytes |
References Dspam.DSpamDirectory._feedback(), and Dspam.DSpamDirectory.probability.
def Dspam.DSpamDirectory.get_group | ( | self, | |
user | |||
) |
Return group user belongs to.
FIXME: update for new group concepts and syntax.
user | str - user name |
References Dspam.DSpamDirectory.groupfile, and Dspam.parse_groups().
Referenced by Dspam.DSpamDirectory.user_files(), and Dspam.DSpamDirectory.write_web_stats().
def Dspam.DSpamDirectory.user_files | ( | self, | |
user | |||
) |
Set username and return common pathnames.
user | str - dspam user for subsequent operations. |
References Dspam.DSpamDirectory.dspam_dict, Dspam.DSpamDirectory.dspam_stats, Dspam.DSpamDirectory.get_group(), Dspam.DSpamDirectory.lock, Dspam.DSpamDirectory.mbox, Dspam.DSpamDirectory.sigfile, dspam.userdir(), Dspam.DSpamDirectory.userdir, and Dspam.DSpamDirectory.username.
Referenced by Dspam.DSpamDirectory.check_spam(), and Dspam.DSpamDirectory.write_web_stats().
def Dspam.DSpamDirectory.write_web_stats | ( | self, | |
totals | |||
) |
Update dspam stats stored as text for the web interface.
totals | totals obtained from dspam.ctx.totals |
References Dspam.DSpamDirectory._feedback(), Dspam.DSpamDirectory._innoc(), Dspam.convert_eol(), Dspam.DSpamDirectory.dspam_ctx(), Dspam.DSpamDirectory.dspam_stats, Dspam.extract_signature_tags(), Dspam.DSpamDirectory.get_group(), Dspam.DSpamDirectory.log, Dspam.parse_groups(), Dspam.DSpamDirectory.totals, Dspam.DSpamDirectory.user_files(), dspam.userdir(), Dspam.DSpamDirectory.userdir, and Dspam.DSpamDirectory.write_web_stats().
Referenced by Dspam.DSpamDirectory._add_sig(), and Dspam.DSpamDirectory.write_web_stats().
Dspam.DSpamDirectory.groupfile |
Path of group definition file.
Note, syntax has changed since dspam-2.6.
Referenced by Dspam.DSpamDirectory.get_group().
Dspam.DSpamDirectory.headerchange |
Hook for changing mail headers in the MTA to mirror changes by Dspam.
See mime module from pymilter for details.
Referenced by Dspam.DSpamDirectory._add_sig().
Dspam.DSpamDirectory.lock |
Path of lock file used by libdspam.
Referenced by Dspam.DSpamDirectory.check_spam(), and Dspam.DSpamDirectory.user_files().
Dspam.DSpamDirectory.mbox |
Path of quarantine mailbox used by pydspam for user.
The dspam LDA and other libdspam clients may have different quarantines.
Referenced by Dspam.DSpamDirectory._add_sig(), and Dspam.DSpamDirectory.user_files().
Dspam.DSpamDirectory.training |
Training mode.
Default to train on everything, since that is what old dspam did, and milter depends on that.
Referenced by Dspam.DSpamDirectory.dspam_ctx().
Dspam.DSpamDirectory.userdir |
DSPAM home.
Base directory where dspam stores dictionaries and configs.
Referenced by Dspam.DSpamDirectory.dspam_ctx(), Dspam.DSpamDirectory.user_files(), and Dspam.DSpamDirectory.write_web_stats().