pydspam  1.4
Classes | Functions | Variables
dspam Namespace Reference

Classes

class  ctx
 Hold context for a DSPAM message operation Each context creates a new DSPAM_CTX struct within libdspam. More...
 
class  error
 

Functions

def userdir (home, user, ext=None)
 Return path of user or group specific file. More...
 
def get_fcntl_lock (fd)
 Get fnctl lock for open file using libdspam conventions. More...
 
def free_fcntl_lock (fd)
 Free the fnctl lock for an open file using libdspam conventions. More...
 
def set_debug (mode)
 Set debugging output mode. More...
 
def set_verified_user (flag)
 Set verified_user flag. More...
 
def libdspam_init (driver)
 Initialize libdspam. More...
 
def libdspam_shutdown ()
 Shutdown libdspam. More...
 

Variables

tuple LIBDSPAM_VERSION = (3,6,0)
 The compile time libdspam version. More...
 
string CONFIGURE_ARGS = " '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--enable-long-usernames' '--enable-syslog' '--enable-large-scale' '--enable-clamav' '--disable-domain-scale' '--disable-homedir' '--enable-virtual-users' '--enable-preferences-extension' '--with-mysql-includes=/usr/include/mysql' '--with-mysql-libraries=/usr/lib64/mysql' '--with-pgsql-includes=/usr/include/pgsql' '--with-pgsql-libraries=/usr/lib64' '--enable-daemon' '--enable-external-lookup' '--with-storage-driver=hash_drv,mysql_drv,pgsql_drv,sqlite3_drv' '--with-dspam-home=/var/lib/dspam' '--with-dspam-owner=dspam' '--with-dspam-group=mail' '--with-dspam-home-group=mail' '--with-dspam-mode=2511' '--with-logdir=/var/log/dspam' '--sysconfdir=/etc' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'"
 Arguments passed to configure when building libdspam. More...
 

Detailed Description

A thin wrapper around libdspam. Most users will not import dspam directly, but will instead import Dspam. This module gives you ultimate low level control from python.

Function Documentation

◆ free_fcntl_lock()

def dspam.free_fcntl_lock (   fd)

Free the fnctl lock for an open file using libdspam conventions.

Parameters
fdthe fileno of an open file

◆ get_fcntl_lock()

def dspam.get_fcntl_lock (   fd)

Get fnctl lock for open file using libdspam conventions.

Parameters
fdthe fileno of an open file

◆ libdspam_init()

def dspam.libdspam_init (   driver)

Initialize libdspam.

Currently this just means dynamically loading the storage driver. The driver path can be None only if it was statically configured when libdspam was compiled.

libdspam_init calls dspam_init_driver(NULL), and will actually pass a DRIVER_CTX * when I figure out the multi-threading API.

Parameters
driverstr pathname to storage driver

◆ libdspam_shutdown()

def dspam.libdspam_shutdown ( )

Shutdown libdspam.

Currently this just means unloading the storage driver, unless statically configured at libdspam compile time.

libdspam_shutdown calls dspam_shutdown_driver(NULL), with the DRIVER_CTX * used in libdspam_init.

◆ set_debug()

def dspam.set_debug (   mode)

Set debugging output mode.

Mode 2 is more efficient, but mode 1 ensures that you see all the output. This only works if libdspam was configured with –enable-debug when compiled, and pydspam has DEBUG uncommented at the top. I will recommend to upstream that DO_DEBUG be always exported - or perhaps dspam_set_debug(int).

◆ set_verified_user()

def dspam.set_verified_user (   flag)

Set verified_user flag.

Set to true for libdspam to autocreate user directories, and other behaviour I haven't speced out yet. I defaulted this to True, since that is the dspam default when external lookup is not configured.

◆ userdir()

def dspam.userdir (   home,
  user,
  ext = None 
)

Return path of user or group specific file.

This calls the internal libdspam function _ds_userdir_path(), which has compile time options for how the path name is computed (for example LARGEFILE, HOMEDIR, DOMAINSCALE). If the extension is None, the user directory is returned, otherwise the path of a user file is returned. For a user file with no extension, use an empty string for the extension.

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

Variable Documentation

◆ CONFIGURE_ARGS

string dspam.CONFIGURE_ARGS = " '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--target=x86_64-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--enable-long-usernames' '--enable-syslog' '--enable-large-scale' '--enable-clamav' '--disable-domain-scale' '--disable-homedir' '--enable-virtual-users' '--enable-preferences-extension' '--with-mysql-includes=/usr/include/mysql' '--with-mysql-libraries=/usr/lib64/mysql' '--with-pgsql-includes=/usr/include/pgsql' '--with-pgsql-libraries=/usr/lib64' '--enable-daemon' '--enable-external-lookup' '--with-storage-driver=hash_drv,mysql_drv,pgsql_drv,sqlite3_drv' '--with-dspam-home=/var/lib/dspam' '--with-dspam-owner=dspam' '--with-dspam-group=mail' '--with-dspam-home-group=mail' '--with-dspam-mode=2511' '--with-logdir=/var/log/dspam' '--sysconfdir=/etc' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'target_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'"

Arguments passed to configure when building libdspam.

The format is a space separated list of quoted strings. The example is a build for x86_64-redhat-linux-gnu.

Since
1.3.1

◆ LIBDSPAM_VERSION

tuple dspam.LIBDSPAM_VERSION = (3,6,0)

The compile time libdspam version.

Python code might need to deal with several iterations of the libdspam API. This module constant is a tuple with the major, minor, and patch level of the library API at the time pydspam was compiled. This is not necessarily the same as the version of dspam running.

dspam.ctx.__init__
def __init__(self, username, mode, flags=0, group=None, home=None)
Initialize dspam context.
Definition: dspam.py:143
dspam.ctx.probability
probability
Probability.
Definition: dspam.py:166
Dspam.DSpamDirectory.userdir
userdir
DSPAM home.
Definition: Dspam.py:272
Dspam.put_signature
def put_signature(ds, sig, sigfile=None)
Add signature to database.
Definition: Dspam.py:107
Dspam.DSpamDirectory.mbox
mbox
Path of quarantine mailbox used by pydspam for user.
Definition: Dspam.py:300
dspam.ctx.totals
totals
Totals.
Definition: dspam.py:163
Dspam.DSpamDirectory.dspam_ctx
def dspam_ctx(self, op, flags=0, user=None)
Create dspam.ctx using configured defaults.
Definition: Dspam.py:317
Dspam.DSpamDirectory.__init__
def __init__(self, userdir)
Initialize DSpamDirectory.
Definition: Dspam.py:270
Dspam.DSpamDirectory.groupfile
groupfile
Path of group definition file.
Definition: Dspam.py:274
Dspam.DSpamDirectory._add_sig
def _add_sig(self, txt, sig, recipients=None)
Add signature key to message, and quarantine if spammy.
Definition: Dspam.py:423
Dspam.DSpamDirectory
Operations on the DSPAM directory.
Definition: Dspam.py:263
Dspam.parse_groups
def parse_groups(groupfile, dups=False)
Parse old group file.
Definition: Dspam.py:238
Dspam.DSpamDirectory.result
result
Classification from last check_spam.
Definition: Dspam.py:296
dspam.ctx
Hold context for a DSPAM message operation Each context creates a new DSPAM_CTX struct within libdspa...
Definition: dspam.py:135
Dspam.DSpamDirectory.user_files
def user_files(self, user)
Set username and return common pathnames.
Definition: Dspam.py:340
Dspam.DSpamDirectory.check_spam
def check_spam(self, user, txt, recipients=None, classify=False, quarantine=True, force_result=None)
Check spaminess of a message.
Definition: Dspam.py:366
dspam.ctx.factors
factors
Factors.
Definition: dspam.py:170
dspam.error
Definition: dspam.py:226
Dspam.DSpamDirectory.lock
lock
Path of lock file used by libdspam.
Definition: Dspam.py:303
Dspam.DSpamDirectory.totals
totals
DSPAM totals for user from last operation.
Definition: Dspam.py:294
Dspam.DSpamDirectory.headerchange
headerchange
Hook for changing mail headers in the MTA to mirror changes by Dspam.
Definition: Dspam.py:279
dspam.ctx.detach
def detach(self)
Detaches storage driver from context.
Definition: dspam.py:217
Dspam.DSpamDirectory._innoc
def _innoc(self, user, sigs, op)
Definition: Dspam.py:522
dspam.ctx.source
source
Source of callers classification.
Definition: dspam.py:149
Dspam.DSpamDirectory.write_web_stats
def write_web_stats(self, totals)
Update dspam stats stored as text for the web interface.
Definition: Dspam.py:453
dspam.ctx.training_mode
training_mode
Training mode.
Definition: dspam.py:156
Dspam.DSpamDirectory.algorithms
algorithms
Default spam score algorithms to use.
Definition: Dspam.py:287
Dspam.DSpamDirectory.dspam_dict
dspam_dict
Definition: Dspam.py:348
Dspam.DSpamDirectory.sigfile
sigfile
Definition: Dspam.py:350
Dspam._tag_part
def _tag_part(msg, sigkey)
Add tag to a non-multipart message.
Definition: Dspam.py:136
Dspam.DSpamDirectory.false_positive
def false_positive(self, user, txt)
Report a false positive.
Definition: Dspam.py:563
Dspam.DSpamDirectory.training
training
Training mode.
Definition: Dspam.py:292
Dspam.add_signature_tag
def add_signature_tag(msg, sigkey, prob=None, factors=None, trace=False)
Add DSPAM tag to message.
Definition: Dspam.py:165
Dspam.DSpamDirectory.dspam_stats
dspam_stats
Definition: Dspam.py:349
Dspam.DSpamDirectory.username
username
The dspam user current being processed.
Definition: Dspam.py:281
dspam.ctx.attach
def attach(self, dbh=None)
Attaches storage driver to context.
Definition: dspam.py:190
Dspam.DSpamDirectory.add_spam
def add_spam(self, user, txt)
Report a false negative.
Definition: Dspam.py:546
Dspam.DSpamDirectory._lognull
def _lognull(self, *msg)
Definition: Dspam.py:265
dspam.ctx.clearattributes
def clearattributes(self)
Clear configuration attributes from this context.
Definition: dspam.py:184
Dspam.DSpamDirectory.tokenizer
tokenizer
Default tokenizer.
Definition: Dspam.py:289
dspam.ctx.classification
classification
Callers classification.
Definition: dspam.py:147
dspam.set_verified_user
def set_verified_user(flag)
Set verified_user flag.
Definition: dspam.py:262
dspam.ctx.tokenizer
tokenizer
Tokenizer algorithm.
Definition: dspam.py:151
dspam.ctx.algorithms
algorithms
Classification algorithms to employ.
Definition: dspam.py:154
dspam.free_fcntl_lock
def free_fcntl_lock(fd)
Free the fnctl lock for an open file using libdspam conventions.
Definition: dspam.py:247
dspam.get_fcntl_lock
def get_fcntl_lock(fd)
Get fnctl lock for open file using libdspam conventions.
Definition: dspam.py:243
Dspam.create_signature_id
def create_signature_id()
Create a mostly unique tag for a signature.
Definition: Dspam.py:93
dspam.ctx.tokenize
def tokenize(self, header, body)
Tokenize the header and body of a message, and return a dictionary of token,freq tuples by hash.
Definition: dspam.py:221
dspam.ctx.get_signature
def get_signature(self, tag)
Retrieve a signature stored using the attached storage driver.
Definition: dspam.py:203
dspam.set_debug
def set_debug(mode)
Set debugging output mode.
Definition: dspam.py:256
Dspam.DSpamDirectory.factors
factors
The top tokens that determined the spam score.
Definition: Dspam.py:285
Dspam.DSpamDirectory.probability
probability
The spam score from 0.0 to 1.0.
Definition: Dspam.py:283
dspam.userdir
def userdir(home, user, ext=None)
Return path of user or group specific file.
Definition: dspam.py:239
dspam.libdspam_shutdown
def libdspam_shutdown()
Shutdown libdspam.
Definition: dspam.py:280
Dspam.extract_signature_tags
def extract_signature_tags(txt)
Extract all DSPAM tags from a message.
Definition: Dspam.py:202
Dspam.DSpamDirectory.log
log
Logging method.
Definition: Dspam.py:276
dspam.ctx.verify_signature
def verify_signature(self, tag)
Verify a signature stored using the attached storage driver.
Definition: dspam.py:214
dspam.ctx.addattribute
def addattribute(self, key, val)
Add configuration attribute to context.
Definition: dspam.py:181
dspam.ctx.result
result
Result of DSPAM classification.
Definition: dspam.py:145
Dspam.convert_eol
def convert_eol(txt)
Convert message to unix end of line conventions.
Definition: Dspam.py:257
dspam.ctx.delete_signature
def delete_signature(self, tag)
Delete a signature stored using the attached storage driver.
Definition: dspam.py:208
dspam.ctx.process
def process(self, msg, sig=None)
Calls dspam_process(DSPAM_CTX ctx, const char *msg)
Definition: dspam.py:175
dspam.ctx.set_signature
def set_signature(self, tag, sig)
Store a signature using the attached storage driver.
Definition: dspam.py:196
dspam.libdspam_init
def libdspam_init(driver)
Initialize libdspam.
Definition: dspam.py:273
Dspam.DSpamDirectory.get_group
def get_group(self, user)
Return group user belongs to.
Definition: Dspam.py:334
dspam.ctx.destroy
def destroy(self)
Destroy context, releasing all resources.
Definition: dspam.py:224
Dspam.DSpamDirectory._feedback
def _feedback(self, user, txt, op, queue=False)
Definition: Dspam.py:467