\section{Milter Namespace Reference}
\label{namespaceMilter}\index{Milter@{Milter}}


A thin O\+O wrapper for the milter module.  


\subsection*{Namespaces}
\begin{DoxyCompactItemize}
\item 
 {\bf dns}
\begin{DoxyCompactList}\small\item\em Provide a higher level interface to pydns. \end{DoxyCompactList}\item 
 {\bf dsn}
\begin{DoxyCompactList}\small\item\em Support D\+S\+Ns and Call\+Back\+Validations (C\+B\+V). \end{DoxyCompactList}\item 
 {\bf pyip6}
\item 
 {\bf test}
\begin{DoxyCompactList}\small\item\em A test framework for milters. \end{DoxyCompactList}\item 
 {\bf utils}
\begin{DoxyCompactList}\small\item\em Miscellaneous functions. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Classes}
\begin{DoxyCompactItemize}
\item 
class {\bf Base}
\begin{DoxyCompactList}\small\item\em A do \char`\"{}nothing\char`\"{} \doxyref{Milter}{p.}{classMilter_1_1Milter} base class representing an S\+M\+T\+P connection. \end{DoxyCompactList}\item 
class {\bf Disabled\+Action}
\begin{DoxyCompactList}\small\item\em Disabled action exception. \end{DoxyCompactList}\item 
class {\bf Milter}
\begin{DoxyCompactList}\small\item\em A logging but otherwise do nothing \doxyref{Milter}{p.}{classMilter_1_1Milter} base class. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
def {\bf unique\+I\+D} ()
\item 
def {\bfseries decode\+\_\+mask} (bits, names)\label{namespaceMilter_a8fbc342a2665f81340c6b77da04f0fba}

\item 
def {\bf enable\+\_\+protocols} (klass, mask)
\begin{DoxyCompactList}\small\item\em Class decorator to enable optional protocol steps. \end{DoxyCompactList}\item 
def {\bf rejected\+\_\+recipients} (klass)
\begin{DoxyCompactList}\small\item\em \doxyref{Milter}{p.}{namespaceMilter} rejected recipients. \end{DoxyCompactList}\item 
def {\bf header\+\_\+leading\+\_\+space} (klass)
\begin{DoxyCompactList}\small\item\em \doxyref{Milter}{p.}{namespaceMilter} leading space on headers. \end{DoxyCompactList}\item 
def {\bf nocallback} (func)
\begin{DoxyCompactList}\small\item\em Function decorator to disable callback methods. \end{DoxyCompactList}\item 
def {\bf noreply} (func)
\begin{DoxyCompactList}\small\item\em Function decorator to disable callback reply. \end{DoxyCompactList}\item 
def {\bf negotiate\+\_\+callback} (ctx, opts)
\begin{DoxyCompactList}\small\item\em Connect context to connection instance and return enabled callbacks. \end{DoxyCompactList}\item 
def {\bf connect\+\_\+callback}
\begin{DoxyCompactList}\small\item\em Connect context if needed and invoke connect method. \end{DoxyCompactList}\item 
def {\bf close\+\_\+callback} (ctx)
\begin{DoxyCompactList}\small\item\em Disconnect milter\+Context and call close method. \end{DoxyCompactList}\item 
def {\bf dictfromlist} (args)
\begin{DoxyCompactList}\small\item\em Convert E\+S\+M\+T\+P parameters with values to a keyword dictionary. \end{DoxyCompactList}\item 
def {\bf param2dict} (str)
\begin{DoxyCompactList}\small\item\em Convert E\+S\+M\+T\+P parm list to keyword dictionary. \end{DoxyCompactList}\item 
def {\bf envcallback} (c, args)
\item 
def {\bf runmilter}
\begin{DoxyCompactList}\small\item\em Run the milter. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
string {\bfseries \+\_\+\+\_\+version\+\_\+\+\_\+} = \textquotesingle{}0.\+9.\+8\textquotesingle{}\label{namespaceMilter_a52a627e58830372ea605aa1cba4e577b}

\item 
tuple {\bfseries \+\_\+seq\+\_\+lock} = thread.\+allocate\+\_\+lock()\label{namespaceMilter_ab343c4da602871d2b56e42b525360eb1}

\item 
int {\bfseries \+\_\+seq} = 0\label{namespaceMilter_a0e11e271e13282c95839a8fc693c61fd}

\item 
dictionary {\bfseries O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S}
\item 
tuple {\bfseries R} = re.\+compile(r\textquotesingle{}\%+\textquotesingle{})\label{namespaceMilter_a53d904c0a3c14a63ec702786cf7681e7}

\item 
{\bf factory} = {\bf Milter}
\begin{DoxyCompactList}\small\item\em The milter connection factory This factory method is called for each connection to create the python object that tracks the connection. \end{DoxyCompactList}\item 
tuple {\bfseries \+\_\+\+\_\+all\+\_\+\+\_\+} = globals()\label{namespaceMilter_a60a6508c8bafe4050504dda8eb724795}

\end{DoxyCompactItemize}


\subsection{Detailed Description}
A thin O\+O wrapper for the milter module. 

Clients generally subclass \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base} and define callback methods.

\begin{DoxyAuthor}{Author}
Stuart D. Gathman {\tt stuart@bmsi.\+com} Copyright 2001,2009 Business Management Systems, Inc. This code is under the G\+N\+U General Public License. See C\+O\+P\+Y\+I\+N\+G for details. 
\end{DoxyAuthor}


\subsection{Function Documentation}
\index{Milter@{Milter}!close\+\_\+callback@{close\+\_\+callback}}
\index{close\+\_\+callback@{close\+\_\+callback}!Milter@{Milter}}
\subsubsection[{close\+\_\+callback}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+close\+\_\+callback (
\begin{DoxyParamCaption}
\item[{}]{ctx}
\end{DoxyParamCaption}
)}\label{namespaceMilter_aacda23f972ebb12f0ba4364a868b85b8}


Disconnect milter\+Context and call close method. 

\index{Milter@{Milter}!connect\+\_\+callback@{connect\+\_\+callback}}
\index{connect\+\_\+callback@{connect\+\_\+callback}!Milter@{Milter}}
\subsubsection[{connect\+\_\+callback}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+connect\+\_\+callback (
\begin{DoxyParamCaption}
\item[{}]{ctx, }
\item[{}]{hostname, }
\item[{}]{family, }
\item[{}]{hostaddr, }
\item[{}]{nr\+\_\+mask = {\ttfamily P\+\_\+NR\+\_\+CONN}}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a7d086a94429a106292ac438e6bddd406}


Connect context if needed and invoke connect method. 



References factory.

\index{Milter@{Milter}!dictfromlist@{dictfromlist}}
\index{dictfromlist@{dictfromlist}!Milter@{Milter}}
\subsubsection[{dictfromlist}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+dictfromlist (
\begin{DoxyParamCaption}
\item[{}]{args}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a70614463afdd03aa7fefafde049ce003}


Convert E\+S\+M\+T\+P parameters with values to a keyword dictionary. 

\begin{DoxyRefDesc}{Deprecated}
\item[{\bf Deprecated}]You probably want \doxyref{Milter.\+param2dict}{p.}{namespaceMilter_aa7a286dc2615af8a18b4ce61142b69c7} instead. \end{DoxyRefDesc}
\index{Milter@{Milter}!enable\+\_\+protocols@{enable\+\_\+protocols}}
\index{enable\+\_\+protocols@{enable\+\_\+protocols}!Milter@{Milter}}
\subsubsection[{enable\+\_\+protocols}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+enable\+\_\+protocols (
\begin{DoxyParamCaption}
\item[{}]{klass, }
\item[{}]{mask}
\end{DoxyParamCaption}
)}\label{namespaceMilter_adb642b2896800154bfd09a87714270f3}


Class decorator to enable optional protocol steps. 

P\+\_\+\+S\+K\+I\+P is enabled by default when supported, but applications may wish to enable P\+\_\+\+H\+D\+R\+\_\+\+L\+E\+A\+D\+S\+P\+C to send and receive the leading space of header continuation lines unchanged, and/or P\+\_\+\+R\+C\+P\+T\+\_\+\+R\+E\+J to have recipients detected as invalid by the M\+T\+A passed to the envcrpt callback.

Applications may want to check whether the protocol is actually supported by the M\+T\+A in use. \doxyref{Base.\+\_\+protocol}{p.}{classMilter_1_1Base_a2b029cd0e1e8a56340a09cb64425f024} is a bitmask of protocol options negotiated. So, for instance, if {\ttfamily self.\+\_\+protocol \& Milter.\+P\+\_\+\+R\+C\+P\+T\+\_\+\+R\+E\+J} is true, then that feature was successfully negotiated with the M\+T\+A and the application will see recipients the M\+T\+A has flagged as invalid.

Sample use\+: 
\begin{DoxyPre}
 class myMilter(\doxyref{Milter.Base}{p.}{classMilter_1_1Base}):
   def envrcpt(self,to,*params):
     return Milter.CONTINUE
 myMilter = \doxyref{Milter.enable\_protocols}{p.}{namespaceMilter_adb642b2896800154bfd09a87714270f3}(myMilter,Milter.P\_RCPT\_REJ)
 \end{DoxyPre}
 \begin{DoxySince}{Since}
0.\+9.\+3 
\end{DoxySince}

\begin{DoxyParams}{Parameters}
{\em klass} & the milter application class to modify \\
\hline
{\em mask} & a bitmask of protocol steps to enable \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the modified milter class 
\end{DoxyReturn}


Referenced by header\+\_\+leading\+\_\+space(), and rejected\+\_\+recipients().

\index{Milter@{Milter}!envcallback@{envcallback}}
\index{envcallback@{envcallback}!Milter@{Milter}}
\subsubsection[{envcallback}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+envcallback (
\begin{DoxyParamCaption}
\item[{}]{c, }
\item[{}]{args}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a5e8bd5026774a96120d083007a5d4d73}
\begin{DoxyVerb}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.\end{DoxyVerb}
 \index{Milter@{Milter}!header\+\_\+leading\+\_\+space@{header\+\_\+leading\+\_\+space}}
\index{header\+\_\+leading\+\_\+space@{header\+\_\+leading\+\_\+space}!Milter@{Milter}}
\subsubsection[{header\+\_\+leading\+\_\+space}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+header\+\_\+leading\+\_\+space (
\begin{DoxyParamCaption}
\item[{}]{klass}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a7499675835bbccdb9512199a0b170bc2}


\doxyref{Milter}{p.}{namespaceMilter} leading space on headers. 

A class decorator that calls \doxyref{enable\+\_\+protocols()}{p.}{namespaceMilter_adb642b2896800154bfd09a87714270f3} with the P\+\_\+\+H\+E\+A\+D\+\_\+\+L\+E\+A\+D\+S\+P\+C 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 M\+T\+A 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\+: 
\begin{DoxyPre}
 @\doxyref{Milter.header\_leading\_space}{p.}{namespaceMilter_a7499675835bbccdb9512199a0b170bc2}
 class myMilter(\doxyref{Milter.Base}{p.}{classMilter_1_1Base}):
   def header(self,hname,value):
     return Milter.CONTINUE
 \end{DoxyPre}
 \begin{DoxySince}{Since}
0.\+9.\+5 
\end{DoxySince}

\begin{DoxyParams}{Parameters}
{\em klass} & the milter application class to modify \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the modified milter class 
\end{DoxyReturn}


References enable\+\_\+protocols().

\index{Milter@{Milter}!negotiate\+\_\+callback@{negotiate\+\_\+callback}}
\index{negotiate\+\_\+callback@{negotiate\+\_\+callback}!Milter@{Milter}}
\subsubsection[{negotiate\+\_\+callback}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+negotiate\+\_\+callback (
\begin{DoxyParamCaption}
\item[{}]{ctx, }
\item[{}]{opts}
\end{DoxyParamCaption}
)}\label{namespaceMilter_ad3598adf6489982e50979239ef7df4e9}


Connect context to connection instance and return enabled callbacks. 



References factory.

\index{Milter@{Milter}!nocallback@{nocallback}}
\index{nocallback@{nocallback}!Milter@{Milter}}
\subsubsection[{nocallback}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+nocallback (
\begin{DoxyParamCaption}
\item[{}]{func}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a4bcf5eccbf8694a1c259fa6681557d6b}


Function decorator to disable callback methods. 

If the M\+T\+A supports it, tells the M\+T\+A not to invoke this callback, increasing efficiency. All the callbacks (except negotiate) are disabled in \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base}, 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.\+C\+O\+N\+T\+I\+N\+U\+E, in case the M\+T\+A does not support protocol negotiation, and for when called from a test harness. \begin{DoxySince}{Since}
0.\+9.\+2 
\end{DoxySince}
\index{Milter@{Milter}!noreply@{noreply}}
\index{noreply@{noreply}!Milter@{Milter}}
\subsubsection[{noreply}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+noreply (
\begin{DoxyParamCaption}
\item[{}]{func}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a5bc0cfa03c567347b622acda6f6b6d42}


Function decorator to disable callback reply. 

If the M\+T\+A supports it, tells the M\+T\+A not to wait for a reply from this callback, and assume C\+O\+N\+T\+I\+N\+U\+E. The method should still return C\+O\+N\+T\+I\+N\+U\+E in case the M\+T\+A does not support protocol negotiation. The decorator arranges to change the return code to N\+O\+R\+E\+P\+L\+Y when supported by the M\+T\+A. \begin{DoxySince}{Since}
0.\+9.\+2 
\end{DoxySince}
\index{Milter@{Milter}!param2dict@{param2dict}}
\index{param2dict@{param2dict}!Milter@{Milter}}
\subsubsection[{param2dict}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+param2dict (
\begin{DoxyParamCaption}
\item[{}]{str}
\end{DoxyParamCaption}
)}\label{namespaceMilter_aa7a286dc2615af8a18b4ce61142b69c7}


Convert E\+S\+M\+T\+P parm list to keyword dictionary. 

Params with no value are set to None in the dictionary. \begin{DoxySince}{Since}
0.\+9.\+3 
\end{DoxySince}

\begin{DoxyParams}{Parameters}
{\em str} & list of param strings of the form \char`\"{}\+N\+A\+M\+E\char`\"{} or \char`\"{}\+N\+A\+M\+E=\+V\+A\+L\+U\+E\char`\"{} \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
a dictionary of E\+S\+M\+T\+P param names and values 
\end{DoxyReturn}
\index{Milter@{Milter}!rejected\+\_\+recipients@{rejected\+\_\+recipients}}
\index{rejected\+\_\+recipients@{rejected\+\_\+recipients}!Milter@{Milter}}
\subsubsection[{rejected\+\_\+recipients}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+rejected\+\_\+recipients (
\begin{DoxyParamCaption}
\item[{}]{klass}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a51b93684e65400f11b94b517bead1552}


\doxyref{Milter}{p.}{namespaceMilter} rejected recipients. 

A class decorator that calls \doxyref{enable\+\_\+protocols()}{p.}{namespaceMilter_adb642b2896800154bfd09a87714270f3} with the P\+\_\+\+R\+C\+P\+T\+\_\+\+R\+E\+J flag. By default, the M\+T\+A 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 M\+T\+A. Use like this with python-\/2.\+6 and later\+: 
\begin{DoxyPre}
 @\doxyref{Milter.rejected\_recipients}{p.}{namespaceMilter_a51b93684e65400f11b94b517bead1552}
 class myMilter(\doxyref{Milter.Base}{p.}{classMilter_1_1Base}):
   def envrcpt(self,to,*params):
     return Milter.CONTINUE
 \end{DoxyPre}
 \begin{DoxySince}{Since}
0.\+9.\+5 
\end{DoxySince}

\begin{DoxyParams}{Parameters}
{\em klass} & the milter application class to modify \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
the modified milter class 
\end{DoxyReturn}


References enable\+\_\+protocols().

\index{Milter@{Milter}!runmilter@{runmilter}}
\index{runmilter@{runmilter}!Milter@{Milter}}
\subsubsection[{runmilter}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+runmilter (
\begin{DoxyParamCaption}
\item[{}]{name, }
\item[{}]{socketname, }
\item[{}]{timeout = {\ttfamily 0}, }
\item[{}]{rmsock = {\ttfamily True}}
\end{DoxyParamCaption}
)}\label{namespaceMilter_a8ae61554a7e4dc83916f5325024a53f0}


Run the milter. 


\begin{DoxyParams}{Parameters}
{\em name} & the name of the milter known to the M\+T\+A \\
\hline
{\em socketname} & the socket to be passed to \doxyref{milter.\+setconn()}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb} \\
\hline
{\em timeout} & the time in secs the M\+T\+A should wait for a response before considering this milter dead \\
\hline
\end{DoxyParams}


References milter.\+getversion(), milter.\+main(), milter.\+opensocket(), milter.\+register(), milter.\+setconn(), and milter.\+settimeout().

\index{Milter@{Milter}!unique\+I\+D@{unique\+I\+D}}
\index{unique\+I\+D@{unique\+I\+D}!Milter@{Milter}}
\subsubsection[{unique\+I\+D}]{\setlength{\rightskip}{0pt plus 5cm}def Milter.\+unique\+I\+D (
\begin{DoxyParamCaption}
{}
\end{DoxyParamCaption}
)}\label{namespaceMilter_ad789f93f62d6c9e96fdd9be997204cf0}
\begin{DoxyVerb}Return a unique sequence number (incremented on each call).
\end{DoxyVerb}
 

\subsection{Variable Documentation}
\index{Milter@{Milter}!factory@{factory}}
\index{factory@{factory}!Milter@{Milter}}
\subsubsection[{factory}]{\setlength{\rightskip}{0pt plus 5cm}Milter.\+factory = {\bf Milter}}\label{namespaceMilter_ad9d443c6e5b7fd46770435e7656e7d39}


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 \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base}.

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. 

Referenced by connect\+\_\+callback(), and negotiate\+\_\+callback().

\index{Milter@{Milter}!O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S@{O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S}}
\index{O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S@{O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S}!Milter@{Milter}}
\subsubsection[{O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S}]{\setlength{\rightskip}{0pt plus 5cm}dictionary Milter.\+O\+P\+T\+I\+O\+N\+A\+L\+\_\+\+C\+A\+L\+L\+B\+A\+C\+K\+S}\label{namespaceMilter_afabb800c9ae9018dfa1d176710fe9386}
{\bfseries Initial value\+:}
\begin{DoxyCode}
1 = \{
2   \textcolor{stringliteral}{'connect'}:(P\_NR\_CONN,P\_NOCONNECT),
3   \textcolor{stringliteral}{'hello'}:(P\_NR\_HELO,P\_NOHELO),
4   \textcolor{stringliteral}{'envfrom'}:(P\_NR\_MAIL,P\_NOMAIL),
5   \textcolor{stringliteral}{'envrcpt'}:(P\_NR\_RCPT,P\_NORCPT),
6   \textcolor{stringliteral}{'data'}:(P\_NR\_DATA,P\_NODATA),
7   \textcolor{stringliteral}{'unknown'}:(P\_NR\_UNKN,P\_NOUNKNOWN),
8   \textcolor{stringliteral}{'eoh'}:(P\_NR\_EOH,P\_NOEOH),
9   \textcolor{stringliteral}{'body'}:(P\_NR\_BODY,P\_NOBODY),
10   \textcolor{stringliteral}{'header'}:(P\_NR\_HDR,P\_NOHDRS)
11 \}
\end{DoxyCode}
