pydspam  1.4
Public Member Functions | Public Attributes | Private Member Functions | List of all members
Dspam.DSpamDirectory Class Reference

Operations on the DSPAM directory. More...

Inheritance diagram for Dspam.DSpamDirectory:

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)
 

Detailed Description

Operations on the DSPAM directory.

Constructor & Destructor Documentation

◆ __init__()

def Dspam.DSpamDirectory.__init__ (   self,
  userdir 
)

Initialize DSpamDirectory.

The base directory is something like /var/lib/dspam.

Parameters
userdirthe DSPAM base directory

Member Function Documentation

◆ _add_sig()

def Dspam.DSpamDirectory._add_sig (   self,
  txt,
  sig,
  recipients = None 
)
private

Add signature key to message, and quarantine if spammy.

The results of the last check_spam as used.

Parameters
txtthe message bytes
sigthe signature
recipientslist 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().

◆ add_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".

Parameters
userstr - the DSPAM user
txtbytes - the spam message

References Dspam.DSpamDirectory._feedback(), and Dspam.DSpamDirectory.probability.

◆ check_spam()

def Dspam.DSpamDirectory.check_spam (   self,
  user,
  txt,
  recipients = None,
  classify = False,
  quarantine = True,
  force_result = None 
)

Check spaminess of a message.

Parameters
userthe dspam user (email account)
txtthe message as bytes collected from the MTA
recipientsIf provided, a list of recipients to record in quarantined messages to assist later delivery.
classify
quarantineAdd messages classified as spam to mbox quarantine if true.
force_resulttrain as this result
Returns
tagged message, or None if message was quarantined

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().

◆ dspam_ctx()

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
 
Parameters
opdspam operation mode: one of dspam.DSM_*
flagsdspam operation flags: set of dspam.DSF_*
userstr - a different user, e.g. for innoculation
Returns
context manager for dspam.ctx

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().

◆ false_positive()

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

Parameters
userstr - the DSPAM user
txtbytes - the innocent message bytes

References Dspam.DSpamDirectory._feedback(), and Dspam.DSpamDirectory.probability.

◆ get_group()

def Dspam.DSpamDirectory.get_group (   self,
  user 
)

Return group user belongs to.


FIXME: update for new group concepts and syntax.

Parameters
userstr - user name
Returns
str - group name

References Dspam.DSpamDirectory.groupfile, and Dspam.parse_groups().

Referenced by Dspam.DSpamDirectory.user_files(), and Dspam.DSpamDirectory.write_web_stats().

◆ user_files()

def Dspam.DSpamDirectory.user_files (   self,
  user 
)

Set username and return common pathnames.

Parameters
userstr - dspam user for subsequent operations.
Returns
tuple - commonly used pathnames: (dspam_dict,sigfile,mbox)

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().

◆ write_web_stats()

def Dspam.DSpamDirectory.write_web_stats (   self,
  totals 
)

Member Data Documentation

◆ groupfile

Dspam.DSpamDirectory.groupfile

Path of group definition file.

Note, syntax has changed since dspam-2.6.

Referenced by Dspam.DSpamDirectory.get_group().

◆ headerchange

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().

◆ lock

Dspam.DSpamDirectory.lock

Path of lock file used by libdspam.

See also
dspam.get_fcntl_lock

Referenced by Dspam.DSpamDirectory.check_spam(), and Dspam.DSpamDirectory.user_files().

◆ mbox

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().

◆ training

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().

◆ userdir

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().


The documentation for this class was generated from the following file: