Milter.Base Class Reference

A do "nothing" Milter base class. More...

Inheritance diagram for Milter.Base:

Milter.Milter

List of all members.

Public Member Functions

def log
 Defined by subclasses to write log messages.
def connect
 Called for each connection to the MTA.
def hello
 Called when the SMTP client says HELO.
def envfrom
 Called when the SMTP client says MAIL FROM.
def envrcpt
 Called when the SMTP client says RCPT TO.
def data
 Called when the SMTP client says DATA.
def header
 Called for each header field in the message body.
def eoh
 Called at the blank line that terminates the header fields.
def body
 Called to supply the body of the message to the Milter by chunks.
def unknown
 Called when the SMTP client issues an unknown command.
def eom
 Called at the end of the message body.
def abort
 Called when the connection is abnormally terminated.
def close
 Called when the connection is closed.
def protocol_mask
 Return mask of SMFIP_N.
def negotiate
 Negotiate milter protocol options.
def getsymval
 Return the value of an MTA macro.
def setreply
 Set the SMTP reply code and message.
def setsmlist
 Tell the MTA which macro names will be used.
def addheader
 Add a mail header field.
def chgheader
 Change the value of a mail header field.
def addrcpt
 Add a recipient to the message.
def delrcpt
 Delete a recipient from the message.
def replacebody
 Replace the message body.
def chgfrom
 Change the SMTP envelope sender address.
def quarantine
 Quarantine the message.
def progress
 Tell the MTA to wait a bit longer.

Private Member Functions

def _setctx
 Attach this Milter to the low level milter.milterContext object.

Private Attributes

 _ctx
 _actions
 A bitmask of actions this milter has negotiated to use.
 _protocol
 A bitmask of protocol options this milter has negotiated.


Detailed Description

A do "nothing" Milter base class.

Python milters should derive from this class unless they are using the low lever milter module directly. All optional callbacks are disabled, and automatically reenabled when overridden.

Since:
0.9.2

Member Function Documentation

def Milter.Base._setctx (   self,
  ctx 
) [private]

Attach this Milter to the low level milter.milterContext object.

def Milter.Base.abort (   self  ) 

Called when the connection is abnormally terminated.

The close callback is still called also.

Reimplemented in Milter.Milter.

def Milter.Base.addheader (   self,
  field,
  value,
  idx = -1 
)

Add a mail header field.

The Milter.ADDHDRS action flag must be set.

May be called from eom callback only.

Parameters:
field the header field name
value the header field value
idx header field index from the top of the message to insert at

def Milter.Base.addrcpt (   self,
  rcpt,
  params = None 
)

Add a recipient to the message.

If no corresponding mail header is added, this is like a Bcc. The syntax of the recipient is the same as used in the SMTP RCPT TO command (and as delivered to the envrcpt callback), for example "self.addrcpt('<foo@example.com>')". The Milter.ADDRCPT action flag must be set. If the optional params argument is used, then the Milter.ADDRCPT_PAR action flag must be set.

May be called from eom callback only.

Parameters:
rcpt the message recipient
params an optional list of ESMTP parameters

def Milter.Base.body (   self,
  blk 
)

Called to supply the body of the message to the Milter by chunks.

Parameters:
blk a block of message bytes

def Milter.Base.chgfrom (   self,
  sender,
  params = None 
)

Change the SMTP envelope sender address.

The syntax of the sender is that same as used in the SMTP MAIL FROM command (and as delivered to the envfrom callback), for example self.chgfrom('<bar@example.com>'). The Milter.CHGFROM action flag must be set.

May be called from eom callback only.

Since:
0.9.1
Parameters:
sender the new sender address
params an optional list of ESMTP parameters

def Milter.Base.chgheader (   self,
  field,
  idx,
  value 
)

Change the value of a mail header field.

The Milter.CHGHDRS action flag must be set.

May be called from eom callback only.

Parameters:
field the name of the field to change
idx index of the field to change when there are multiple instances
value the new value of the field

def Milter.Base.close (   self  ) 

Called when the connection is closed.

Reimplemented in Milter.Milter.

def Milter.Base.connect (   self,
  hostname,
  family,
  hostaddr 
)

Called for each connection to the MTA.

The hostname provided by the local MTA is either the PTR name or the IP in the form "[1.2.3.4]" if no PTR is available. The format of hostaddr depends on the socket family:

socket.AF_INET
A tuple of (IP as string in dotted quad form, integer port)
socket.AF_INET6
A tuple of (IP as a string in standard representation, integer port, integer flow info, integer scope id)
socket.AF_UNIX
A string with the socketname
Parameters:
hostname the PTR name or bracketed IP of the SMTP client
family socket.AF_INET, socket.AF_INET6, or socket.AF_UNIX
hostaddr a tuple or string with peer IP or socketname

Reimplemented in Milter.Milter.

def Milter.Base.data (   self  ) 

Called when the SMTP client says DATA.

Returning REJECT rejects the message without wasting bandwidth on the unwanted message.

Since:
0.9.2

def Milter.Base.delrcpt (   self,
  rcpt 
)

Delete a recipient from the message.

The recipient should match one passed to the envrcpt callback. The Milter.DELRCPT action flag must be set.

May be called from eom callback only.

Parameters:
rcpt the message recipient to delete

def Milter.Base.envfrom (   self,
  f,
  str 
)

Called when the SMTP client says MAIL FROM.

Returning REJECT rejects the message, but not the connection.

Reimplemented in Milter.Milter.

def Milter.Base.envrcpt (   self,
  to,
  str 
)

Called when the SMTP client says RCPT TO.

Returning REJECT rejects the current recipient, not the entire message.

Reimplemented in Milter.Milter.

def Milter.Base.eoh (   self  ) 

Called at the blank line that terminates the header fields.

Reimplemented in Milter.Milter.

def Milter.Base.eom (   self  ) 

Called at the end of the message body.

Most of the message manipulation actions can only take place from the eom callback.

Reimplemented in Milter.Milter.

def Milter.Base.getsymval (   self,
  sym 
)

Return the value of an MTA macro.

Sendmail macro names are either single chars (e.g. "j") or multiple chars enclosed in braces (e.g. "{auth_type}"). Macro names are MTA dependent.

Parameters:
sym the macro name

def Milter.Base.header (   self,
  field,
  value 
)

Called for each header field in the message body.

Reimplemented in Milter.Milter.

def Milter.Base.hello (   self,
  hostname 
)

Called when the SMTP client says HELO.

Returning REJECT prevents progress until a valid HELO is provided; this almost always results in terminating the connection.

Reimplemented in Milter.Milter.

def Milter.Base.log (   self,
  msg 
)

Defined by subclasses to write log messages.

Reimplemented in Milter.Milter.

def Milter.Base.negotiate (   self,
  opts 
)

Negotiate milter protocol options.

Default negotiation sets P_NO* and P_NR* for callbacks marked @nocallback and @noreply respectively, leaves all actions enabled, and enables Milter.SKIP.

Since:
0.9.2

def Milter.Base.progress (   self  ) 

Tell the MTA to wait a bit longer.

Resets timeouts in the MTA that detect a "hung" milter.

def Milter.Base.protocol_mask (   klass  ) 

Return mask of SMFIP_N.

. protocol option bits to clear for this class The @nocallback and @noreply decorators set the milter_protocol function attribute to the protocol mask bit to pass to libmilter, causing that callback or its reply to be skipped. Overriding a method creates a new function object, so that milter_protocol defaults to 0. Libmilter passes the protocol bits that the current MTA knows how to skip. We clear the ones we don't want to skip. The negation is somewhat mind bending, but it is simple.

Since:
0.9.2

def Milter.Base.quarantine (   self,
  reason 
)

Quarantine the message.

When quarantined, a message goes into the mailq as if to be delivered, but delivery is deferred until the message is unquarantined. The Milter.QUARANTINE action flag must be set.

May be called from eom callback only.

Parameters:
reason a string describing the reason for quarantine

def Milter.Base.replacebody (   self,
  body 
)

Replace the message body.

The entire message body must be replaced. Call repeatedly with blocks of data until the entire body is transferred. The Milter.MODBODY action flag must be set.

May be called from eom callback only.

Parameters:
body a chunk of body data

def Milter.Base.setreply (   self,
  rcode,
  xcode = None,
  msg = None,
  ml 
)

Set the SMTP reply code and message.

If the MTA does not support setmlreply, then only the first msg line is used.

def Milter.Base.setsmlist (   self,
  stage,
  macros 
)

Tell the MTA which macro names will be used.

The Milter.SETSMLIST action flag must be set.

May only be called from negotiate callback.

Since:
0.9.2
Parameters:
stage the protocol stage to set to macro list for
macros a string with a space delimited list of macros

def Milter.Base.unknown (   self,
  cmd 
)

Called when the SMTP client issues an unknown command.

Parameters:
cmd the unknown command
Since:
0.9.2


Member Data Documentation

A bitmask of actions this milter has negotiated to use.

By default, all actions are enabled. This may be changed by calling milter.set_flags, or by overriding the negotiate callback. The bits include: ADDHDRS,CHGBODY,MODBODY,ADDRCPT,ADDRCPT_PAR,DELRCPT CHGHDRS,QUARANTINE,CHGFROM,SETSMLIST. The Milter.CURR_ACTS bitmask is all actions known when the milter module was compiled.

Since:
0.9.2

A bitmask of protocol options this milter has negotiated.

The bits generally indicate that a particular step should be skipped, since previous versions of the milter protocol had no provision for skipping steps. The bits include: P_RCPT_REJ P_NR_CONN P_NR_HELO P_NR_MAIL P_NR_RCPT P_NR_DATA P_NR_UNKN P_NR_EOH P_NR_BODY P_NR_HDR P_NOCONNECT P_NOHELO P_NOMAIL P_NORCPT P_NODATA P_NOUNKNOWN P_NOEOH P_NOBODY P_NOHDRS P_HDR_LEADSPC P_SKIP (all under the Milter namespace).

Since:
0.9.2


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

Generated on Tue Jul 28 18:31:38 2009 for pymilter by  doxygen 1.5.9