Package Milter

A thin OO wrapper for the milter module. More...

Packages

package  dns
 

Provide a higher level interface to pydns.


package  dsn
 

Support DSNs and CallBackValidations (CBV).


package  pyip6
package  test
 

A test framework for milters.


package  utils
 

Miscellaneous functions.


Classes

class  DisabledAction
 Disabled action exception. More...
class  Base
 A do "nothing" Milter base class representing an SMTP connection. More...
class  Milter
 A logging but otherwise do nothing Milter base class. More...

Functions

def uniqueID
def decode_mask
def enable_protocols
 Class decorator to enable optional protocol steps.
def rejected_recipients
 Milter rejected recipients.
def header_leading_space
 Milter leading space on headers.
def nocallback
 Function decorator to disable callback methods.
def noreply
 Function decorator to disable callback reply.
def negotiate_callback
 Connect context to connection instance and return enabled callbacks.
def connect_callback
 Connect context if needed and invoke connect method.
def close_callback
 Disconnect milterContext and call close method.
def dictfromlist
 Convert ESMTP parameters with values to a keyword dictionary.
def param2dict
 Convert ESMTP parm list to keyword dictionary.
def envcallback
def runmilter
 Run the milter.

Variables

string __version__ = '0.9.8'
tuple _seq_lock = thread.allocate_lock()
int _seq = 0
dictionary OPTIONAL_CALLBACKS
tuple R = re.compile(r'%+')
 factory = Milter
 The milter connection factory This factory method is called for each connection to create the python object that tracks the connection.
tuple __all__ = globals()

Detailed Description

A thin OO wrapper for the milter module.

Clients generally subclass Milter.Base and define callback methods.

Author:
Stuart D. Gathman <stuart@bmsi.com> Copyright 2001,2009 Business Management Systems, Inc. This code is under the GNU General Public License. See COPYING for details.

Function Documentation

def Milter.close_callback (   ctx  ) 

Disconnect milterContext and call close method.

def Milter.connect_callback (   ctx,
  hostname,
  family,
  hostaddr,
  nr_mask = P_NR_CONN 
)

Connect context if needed and invoke connect method.

def Milter.dictfromlist (   args  ) 

Convert ESMTP parameters with values to a keyword dictionary.

Deprecated:
You probably want Milter.param2dict instead.
def Milter.enable_protocols (   klass,
  mask 
)

Class decorator to enable optional protocol steps.

P_SKIP is enabled by default when supported, but applications may wish to enable P_HDR_LEADSPC to send and receive the leading space of header continuation lines unchanged, and/or P_RCPT_REJ to have recipients detected as invalid by the MTA passed to the envcrpt callback.

Applications may want to check whether the protocol is actually supported by the MTA in use. Base._protocol is a bitmask of protocol options negotiated. So, for instance, if self._protocol & Milter.P_RCPT_REJ is true, then that feature was successfully negotiated with the MTA and the application will see recipients the MTA has flagged as invalid.

Sample use:

 class myMilter(Milter.Base):
   def envrcpt(self,to,*params):
     return Milter.CONTINUE
 myMilter = Milter.enable_protocols(myMilter,Milter.P_RCPT_REJ)
 
Since:
0.9.3
Parameters:
klass the milter application class to modify
mask a bitmask of protocol steps to enable
Returns:
the modified milter class
def Milter.envcallback (   c,
  args 
)
Call function c with ESMTP parms converted to keyword parameters.
Can be used in the envfrom and/or envrcpt callbacks to process
ESMTP parameters as python keyword parameters.
def Milter.header_leading_space (   klass  ) 

Milter leading space on headers.

A class decorator that calls enable_protocols() with the P_HDR_LEADSPC flag. By default, header continuation lines are collected and joined before getting sent to a milter. Headers modified or added by the milter are folded by the MTA as necessary according to its own standards. With this flag, header continuation lines are preserved with their newlines and leading space. In addition, header folding done by the milter is preserved as well. Use like this with python-2.6 and later:

 @Milter.header_leading_space
 class myMilter(Milter.Base):
   def header(self,hname,value):
     return Milter.CONTINUE
 
Since:
0.9.5
Parameters:
klass the milter application class to modify
Returns:
the modified milter class
def Milter.negotiate_callback (   ctx,
  opts 
)

Connect context to connection instance and return enabled callbacks.

def Milter.nocallback (   func  ) 

Function decorator to disable callback methods.

If the MTA supports it, tells the MTA not to invoke this callback, increasing efficiency. All the callbacks (except negotiate) are disabled in Milter.Base, and overriding them reenables the callback. An application may need to use @nocallback when it extends another milter and wants to disable a callback again. The disabled method should still return Milter.CONTINUE, in case the MTA does not support protocol negotiation, and for when called from a test harness.

Since:
0.9.2
def Milter.noreply (   func  ) 

Function decorator to disable callback reply.

If the MTA supports it, tells the MTA not to wait for a reply from this callback, and assume CONTINUE. The method should still return CONTINUE in case the MTA does not support protocol negotiation. The decorator arranges to change the return code to NOREPLY when supported by the MTA.

Since:
0.9.2
def Milter.param2dict (   str  ) 

Convert ESMTP parm list to keyword dictionary.

Params with no value are set to None in the dictionary.

Since:
0.9.3
Parameters:
str list of param strings of the form "NAME" or "NAME=VALUE"
Returns:
a dictionary of ESMTP param names and values
def Milter.rejected_recipients (   klass  ) 

Milter rejected recipients.

A class decorator that calls enable_protocols() with the P_RCPT_REJ flag. By default, the MTA does not pass recipients that it knows are invalid on to the milter. This decorator enables a milter app to see all recipients if supported by the MTA. Use like this with python-2.6 and later:

 @Milter.rejected_recipients
 class myMilter(Milter.Base):
   def envrcpt(self,to,*params):
     return Milter.CONTINUE
 
Since:
0.9.5
Parameters:
klass the milter application class to modify
Returns:
the modified milter class
def Milter.runmilter (   name,
  socketname,
  timeout = 0,
  rmsock = True 
)

Run the milter.

Parameters:
name the name of the milter known to the MTA
socketname the socket to be passed to milter.setconn()
timeout the time in secs the MTA should wait for a response before considering this milter dead
def Milter.uniqueID (  ) 
Return a unique sequence number (incremented on each call).

Variable Documentation

The milter connection factory This factory method is called for each connection to create the python object that tracks the connection.

It should return an object derived from Milter.Base.

Note that since python is dynamic, this variable can be changed while the milter is running: for instance, to a new subclass based on a change in configuration.

dictionary Milter.OPTIONAL_CALLBACKS
Initial value:
{
  'connect':(P_NR_CONN,P_NOCONNECT),
  'hello':(P_NR_HELO,P_NOHELO),
  'envfrom':(P_NR_MAIL,P_NOMAIL),
  'envrcpt':(P_NR_RCPT,P_NORCPT),
  'data':(P_NR_DATA,P_NODATA),
  'unknown':(P_NR_UNKN,P_NOUNKNOWN),
  'eoh':(P_NR_EOH,P_NOEOH),
  'body':(P_NR_BODY,P_NOBODY),
  'header':(P_NR_HDR,P_NOHDRS)
}

Generated on 11 Jul 2015 for pymilter by  doxygen 1.6.1