\doxysection{milter Namespace Reference}
\label{namespacemilter}\index{milter@{milter}}


A thin wrapper around libmilter.  


\doxysubsection*{Classes}
\begin{DoxyCompactItemize}
\item 
class \textbf{ milter\+Context}
\begin{DoxyCompactList}\small\item\em Hold context for a milter connection. \end{DoxyCompactList}\item 
class \textbf{ error}
\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
def \textbf{ set\+\_\+flags} (flags)
\begin{DoxyCompactList}\small\item\em Enable optional milter actions. \end{DoxyCompactList}\item 
\mbox{\label{namespacemilter_a718661a3a66a80bbd81ecdc6558aa6f9}} 
def {\bfseries set\+\_\+connect\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a89ea5090ec85d7b2b61b555680533b03}} 
def {\bfseries set\+\_\+helo\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_ae072291fc2acb0975dea551df7ff3a9b}} 
def {\bfseries set\+\_\+envfrom\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a8cfd7045b7e928e9f627506d9fd6fd66}} 
def {\bfseries set\+\_\+envrcpt\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a2d90d9e897a4b85aefb7af321ddc33ae}} 
def {\bfseries set\+\_\+header\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_afdd3580853559c6e5300ba8d4247dcfc}} 
def {\bfseries set\+\_\+eoh\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a4aea12633c4a40dba28814f6e8fa2737}} 
def {\bfseries set\+\_\+body\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a3c6256d8034903ccfa6dc6445231a855}} 
def {\bfseries set\+\_\+abort\+\_\+callback} (cb)
\item 
\mbox{\label{namespacemilter_a139e902748678df095210028d6082d80}} 
def {\bfseries set\+\_\+close\+\_\+callback} (cb)
\item 
def \textbf{ set\+\_\+exception\+\_\+policy} (code)
\begin{DoxyCompactList}\small\item\em Sets the return code for untrapped Python exceptions during a callback. \end{DoxyCompactList}\item 
def \textbf{ register} (name, negotiate=None, unknown=None, data=None)
\begin{DoxyCompactList}\small\item\em Register python milter with libmilter. \end{DoxyCompactList}\item 
def \textbf{ opensocket} (rmsock)
\begin{DoxyCompactList}\small\item\em Attempt to create the socket used to communicate with the MTA. \end{DoxyCompactList}\item 
def \textbf{ main} ()
\begin{DoxyCompactList}\small\item\em Transfer control to libmilter. \end{DoxyCompactList}\item 
def \textbf{ setdbg} (lev)
\begin{DoxyCompactList}\small\item\em Set the libmilter debugging level. \end{DoxyCompactList}\item 
def \textbf{ settimeout} (secs)
\begin{DoxyCompactList}\small\item\em Set timeout for MTA communication. \end{DoxyCompactList}\item 
def \textbf{ setbacklog} (n)
\begin{DoxyCompactList}\small\item\em Set socket backlog. \end{DoxyCompactList}\item 
def \textbf{ setconn} (s)
\begin{DoxyCompactList}\small\item\em Set the socket used to communicate with the MTA. \end{DoxyCompactList}\item 
\mbox{\label{namespacemilter_acd4b12aff996916919045f0d9be4d4d8}} 
def \textbf{ stop} ()
\begin{DoxyCompactList}\small\item\em Stop the milter gracefully. \end{DoxyCompactList}\item 
def \textbf{ getdiag} ()
\begin{DoxyCompactList}\small\item\em Retrieve diagnostic info. \end{DoxyCompactList}\item 
def \textbf{ getversion} ()
\begin{DoxyCompactList}\small\item\em Retrieve the runtime libmilter version. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\label{namespacemilter_a590b7ab395513af007869ad83e332c14}} 
int \textbf{ CONTINUE} = 0
\begin{DoxyCompactList}\small\item\em Continue processing the current connection, message, or recipient. \end{DoxyCompactList}\item 
int \textbf{ REJECT} = 1
\begin{DoxyCompactList}\small\item\em For a connection-\/oriented routine, reject this connection; call \doxyref{Milter.\+Base.\+close()}{p.}{classMilter_1_1Base_a2644dc855f49da0a9810e8d390c93906}. \end{DoxyCompactList}\item 
int \textbf{ DISCARD} = 2
\begin{DoxyCompactList}\small\item\em For a message-\/ or recipient-\/oriented routine, accept this message, but silently discard it. \end{DoxyCompactList}\item 
int \textbf{ ACCEPT} = 3
\begin{DoxyCompactList}\small\item\em For a connection-\/oriented routine, accept this connection without further filter processing; call \doxyref{Milter.\+Base.\+close()}{p.}{classMilter_1_1Base_a2644dc855f49da0a9810e8d390c93906}. \end{DoxyCompactList}\item 
int \textbf{ TEMPFAIL} = 4
\begin{DoxyCompactList}\small\item\em Return a temporary failure, i.\+e., the corresponding SMTP command will return an appropriate 4xx status code. \end{DoxyCompactList}\item 
int \textbf{ SKIP} = 5
\begin{DoxyCompactList}\small\item\em Skip further callbacks of the same type in this transaction. \end{DoxyCompactList}\item 
int \textbf{ NOREPLY} = 6
\begin{DoxyCompactList}\small\item\em Do not send a reply back to the MTA. \end{DoxyCompactList}\item 
int \textbf{ VERSION} = 0x1000001
\begin{DoxyCompactList}\small\item\em The compile time libmilter version. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
A thin wrapper around libmilter. 

Most users will not import milter directly, but will instead import \doxyref{Milter}{p.}{namespaceMilter} and subclass \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base}. This module gives you ultimate low level control from python. 

\doxysubsection{Function Documentation}
\mbox{\label{namespacemilter_a03013ef1adc45729ac2ebeccc1afd47d}} 
\index{milter@{milter}!getdiag@{getdiag}}
\index{getdiag@{getdiag}!milter@{milter}}
\doxysubsubsection{getdiag()}
{\footnotesize\ttfamily def milter.\+getdiag (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Retrieve diagnostic info. 

Return a tuple with diagnostic info gathered by the milter module. The first two fields are counts of \doxyref{milter\+Context}{p.}{classmilter_1_1milterContext} objects created and deleted. Additional fields may be added later. \begin{DoxyReturn}{Returns}
a tuple of diagnostic data 
\end{DoxyReturn}
\mbox{\label{namespacemilter_a87fde36f3baa77e209fbed7ca2c89796}} 
\index{milter@{milter}!getversion@{getversion}}
\index{getversion@{getversion}!milter@{milter}}
\doxysubsubsection{getversion()}
{\footnotesize\ttfamily def milter.\+getversion (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Retrieve the runtime libmilter version. 

Return the runtime libmilter version. This can be different from the compile time version when sendmail or libmilter is upgraded after pymilter is compiled. \begin{DoxyReturn}{Returns}
a tuple of {\ttfamily (major,minor,patchlevel)} 
\end{DoxyReturn}


Referenced by Milter.\+runmilter().

\mbox{\label{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21}} 
\index{milter@{milter}!main@{main}}
\index{main@{main}!milter@{milter}}
\doxysubsubsection{main()}
{\footnotesize\ttfamily def milter.\+main (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Transfer control to libmilter. 

Calls {\texttt{ smfi\+\_\+main}}. 

Referenced by Milter.\+runmilter().

\mbox{\label{namespacemilter_a25c4b69c2520b1935a816734041db77d}} 
\index{milter@{milter}!opensocket@{opensocket}}
\index{opensocket@{opensocket}!milter@{milter}}
\doxysubsubsection{opensocket()}
{\footnotesize\ttfamily def milter.\+opensocket (\begin{DoxyParamCaption}\item[{}]{rmsock }\end{DoxyParamCaption})}



Attempt to create the socket used to communicate with the MTA. 

\doxyref{milter.\+opensocket()}{p.}{namespacemilter_a25c4b69c2520b1935a816734041db77d} attempts to create the socket specified previously by a call to \doxyref{milter.\+setconn()}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb} which will be the interface between MTAs and the milter. This allows the calling application to ensure that the socket can be created. If this is not called, \doxyref{milter.\+main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21} will do so implicitly. Calls {\texttt{ smfi\+\_\+opensocket}}. While not documented for libmilter, my experiments indicate that you must call \doxyref{register()}{p.}{namespacemilter_ad668b975fc73cf0cf5541607bc6b40c4} before calling \doxyref{opensocket()}{p.}{namespacemilter_a25c4b69c2520b1935a816734041db77d}. 
\begin{DoxyParams}{Parameters}
{\em rmsock} & Try to remove an existing unix domain socket if true. \\
\hline
\end{DoxyParams}


Referenced by Milter.\+runmilter().

\mbox{\label{namespacemilter_ad668b975fc73cf0cf5541607bc6b40c4}} 
\index{milter@{milter}!register@{register}}
\index{register@{register}!milter@{milter}}
\doxysubsubsection{register()}
{\footnotesize\ttfamily def milter.\+register (\begin{DoxyParamCaption}\item[{}]{name,  }\item[{}]{negotiate = {\ttfamily None},  }\item[{}]{unknown = {\ttfamily None},  }\item[{}]{data = {\ttfamily None} }\end{DoxyParamCaption})}



Register python milter with libmilter. 

The name we pass is used to identify the milter in the MTA configuration. Callback functions must be set using the set\+\_\+$\ast$\+\_\+callback() functions before registering the milter. Three additional callbacks are specified as keyword parameters. These were added by recent versions of libmilter. The keyword parameters is a nicer way to do it, I think, since it makes clear that you have to do it before registering. I may move all the callbacks in the future (perhaps keeping the set functions for compatibility). Note that \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base} automatically maps all callbacks to member functions, and negotiates which member functions are actually overridden by an application class. 
\begin{DoxyParams}{Parameters}
{\em name} & the milter name by which the MTA finds us \\
\hline
{\em negotiate} & the {\texttt{ xxfi\+\_\+negotiate}} callback, called to negotiate supported actions, callbacks, and protocol steps. \\
\hline
{\em unknown} & the {\texttt{ xxfi\+\_\+unknown}} callback, called when for SMTP commands not recognized by the MTA. (Extend SMTP in your milter!) \\
\hline
{\em data} & the {\texttt{ xxfi\+\_\+data}} callback, called when the DATA SMTP command is received. \\
\hline
\end{DoxyParams}


Referenced by Milter.\+runmilter().

\mbox{\label{namespacemilter_aa82af42e2b608726a0f7e6d45da5efaa}} 
\index{milter@{milter}!set\_exception\_policy@{set\_exception\_policy}}
\index{set\_exception\_policy@{set\_exception\_policy}!milter@{milter}}
\doxysubsubsection{set\_exception\_policy()}
{\footnotesize\ttfamily def milter.\+set\+\_\+exception\+\_\+policy (\begin{DoxyParamCaption}\item[{}]{code }\end{DoxyParamCaption})}



Sets the return code for untrapped Python exceptions during a callback. 

The default is TEMPFAIL. You should not depend on this handler. Your application should have its own top level exception handler for each callback. You can then choose your own reply message, log the stack track were you please, and so on. However, if you miss one, this last ditch handler will print a standard stack trace to sys.\+stderr, and return to sendmail. ~\newline
 
\begin{DoxyParams}{Parameters}
{\em code} & one of \doxyref{TEMPFAIL}{p.}{namespacemilter_a1b4940e90c267a81cba6be20aa782e85},\doxyref{REJECT}{p.}{namespacemilter_a2345250030581a1639ecf905e1668b0a},\doxyref{CONTINUE}{p.}{namespacemilter_a590b7ab395513af007869ad83e332c14}, or since 1.\+0, \doxyref{ACCEPT}{p.}{namespacemilter_ae40b8bfbb6828233115c61490998f7f4} \\
\hline
\end{DoxyParams}
\mbox{\label{namespacemilter_afe0230448acb391b264e8b5c28d45c3c}} 
\index{milter@{milter}!set\_flags@{set\_flags}}
\index{set\_flags@{set\_flags}!milter@{milter}}
\doxysubsubsection{set\_flags()}
{\footnotesize\ttfamily def milter.\+set\+\_\+flags (\begin{DoxyParamCaption}\item[{}]{flags }\end{DoxyParamCaption})}



Enable optional milter actions. 

Certain milter actions need to be enabled before calling \doxyref{main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21} or they throw an exception. Pymilter enables them all by default (since 0.\+9.\+2), but you may wish to disable unneeded actions as an optimization. 
\begin{DoxyParams}{Parameters}
{\em flags} & Bit or mask of optional actions to enable \\
\hline
\end{DoxyParams}
\mbox{\label{namespacemilter_a54ec699d5822b59094c351be70276110}} 
\index{milter@{milter}!setbacklog@{setbacklog}}
\index{setbacklog@{setbacklog}!milter@{milter}}
\doxysubsubsection{setbacklog()}
{\footnotesize\ttfamily def milter.\+setbacklog (\begin{DoxyParamCaption}\item[{}]{n }\end{DoxyParamCaption})}



Set socket backlog. 

Calls {\texttt{ smfi\+\_\+setbacklog}}. Must be called before calling \doxyref{main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21}. \mbox{\label{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}} 
\index{milter@{milter}!setconn@{setconn}}
\index{setconn@{setconn}!milter@{milter}}
\doxysubsubsection{setconn()}
{\footnotesize\ttfamily def milter.\+setconn (\begin{DoxyParamCaption}\item[{}]{s }\end{DoxyParamCaption})}



Set the socket used to communicate with the MTA. 

The MTA can communicate with the milter by means of a unix, inet, or inet6 socket. By default, a unix domain socket is used. It must not exist, and sendmail will throw warnings if, eg, the file is under a group or world writable directory. \doxyref{milter.\+setconn()}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb} will not fail with an invalid socket -\/ this will be detected only when calling \doxyref{milter.\+main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21} or \doxyref{milter.\+opensocket()}{p.}{namespacemilter_a25c4b69c2520b1935a816734041db77d}. 
\begin{DoxyParams}{Parameters}
{\em s} & the socket address in proto\+:address format 
\begin{DoxyPre}
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('unix:/var/run/pythonfilter')  \# a named pipe
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('local:/var/run/pythonfilter') \# a named pipe
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('inet:8800')                    \# listen on ANY interface
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('inet:7871@publichost')        \# listen on a specific interface
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('inet6:8020')
 \doxyref{milter.setconn}{p.}{namespacemilter_a47dedd3e5972a865bcfaa5163eb481cb}('inet6:8020@[2001:db8:1234::1]')      \# listen on specific IP
 \end{DoxyPre}
 \\
\hline
\end{DoxyParams}


Referenced by Milter.\+runmilter().

\mbox{\label{namespacemilter_a7c4b4f083988abb9c174a152dc0c8fcf}} 
\index{milter@{milter}!setdbg@{setdbg}}
\index{setdbg@{setdbg}!milter@{milter}}
\doxysubsubsection{setdbg()}
{\footnotesize\ttfamily def milter.\+setdbg (\begin{DoxyParamCaption}\item[{}]{lev }\end{DoxyParamCaption})}



Set the libmilter debugging level. 

{\texttt{ smfi\+\_\+setdbg}} sets the milter library\textquotesingle{}s internal debugging level to a new level so that code details may be traced. A level of zero turns off debugging. The greater (more positive) the level the more detailed the debugging. Six is the current, highest, useful value. Must be called before calling \doxyref{main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21}. \mbox{\label{namespacemilter_a560ae93b2946e6405d4e317461db8b4d}} 
\index{milter@{milter}!settimeout@{settimeout}}
\index{settimeout@{settimeout}!milter@{milter}}
\doxysubsubsection{settimeout()}
{\footnotesize\ttfamily def milter.\+settimeout (\begin{DoxyParamCaption}\item[{}]{secs }\end{DoxyParamCaption})}



Set timeout for MTA communication. 

Calls {\texttt{ smfi\+\_\+settimeout}}. Must be called before calling \doxyref{main()}{p.}{namespacemilter_a505352a1ee405fa0bc08c97ed094fb21}. 

Referenced by Milter.\+runmilter().



\doxysubsection{Variable Documentation}
\mbox{\label{namespacemilter_ae40b8bfbb6828233115c61490998f7f4}} 
\index{milter@{milter}!ACCEPT@{ACCEPT}}
\index{ACCEPT@{ACCEPT}!milter@{milter}}
\doxysubsubsection{ACCEPT}
{\footnotesize\ttfamily int milter.\+ACCEPT = 3}



For a connection-\/oriented routine, accept this connection without further filter processing; call \doxyref{Milter.\+Base.\+close()}{p.}{classMilter_1_1Base_a2644dc855f49da0a9810e8d390c93906}. 

For a message-\/ or recipient-\/oriented routine, accept this message without further filtering. \mbox{\label{namespacemilter_a4c8bad190cb7f54cea87f1182732ce83}} 
\index{milter@{milter}!DISCARD@{DISCARD}}
\index{DISCARD@{DISCARD}!milter@{milter}}
\doxysubsubsection{DISCARD}
{\footnotesize\ttfamily int milter.\+DISCARD = 2}



For a message-\/ or recipient-\/oriented routine, accept this message, but silently discard it. 

SMFIS\+\_\+\+DISCARD should not be returned by a connection-\/oriented routine. \mbox{\label{namespacemilter_a45378e0b42f76927adaf504b6082fc7d}} 
\index{milter@{milter}!NOREPLY@{NOREPLY}}
\index{NOREPLY@{NOREPLY}!milter@{milter}}
\doxysubsubsection{NOREPLY}
{\footnotesize\ttfamily int milter.\+NOREPLY = 6}



Do not send a reply back to the MTA. 

The milter must negotiate this behavior with the MTA, i.\+e., it must check whether the appropriate protocol action P\+\_\+\+NR\+\_\+$\ast$ is available and if so, the milter must request it. If you set the P\+\_\+\+NR\+\_\+$\ast$ protocol action for a callback, that callback must always reply with NOREPLY. Using any other reply code is a violation of the API. If in some cases your callback may return another value (e.\+g., due to some resource shortages), then you must not set P\+\_\+\+NR\+\_\+$\ast$ and you must use CONTINUE as the default return code. (Alternatively you can try to delay reporting the problem to a later callback for which P\+\_\+\+NR\+\_\+$\ast$ is not set.)

This is negotiated and returned automatically by the \doxyref{Milter.\+noreply}{p.}{namespaceMilter_a5bc0cfa03c567347b622acda6f6b6d42} function decorator. \mbox{\label{namespacemilter_a2345250030581a1639ecf905e1668b0a}} 
\index{milter@{milter}!REJECT@{REJECT}}
\index{REJECT@{REJECT}!milter@{milter}}
\doxysubsubsection{REJECT}
{\footnotesize\ttfamily int milter.\+REJECT = 1}



For a connection-\/oriented routine, reject this connection; call \doxyref{Milter.\+Base.\+close()}{p.}{classMilter_1_1Base_a2644dc855f49da0a9810e8d390c93906}. 

For a message-\/oriented routine, except \doxyref{Milter.\+Base.\+eom()}{p.}{classMilter_1_1Base_a725f845830639b76f479dc6c0f7f8c00} or \doxyref{Milter.\+Base.\+abort()}{p.}{classMilter_1_1Base_aef01a2465e563ad1435030cfc9b30939}, reject this message. For a recipient-\/oriented routine, reject the current recipient (but continue processing the current message). \mbox{\label{namespacemilter_aa2fa23a83f9bbc204eb14313a6efd4cc}} 
\index{milter@{milter}!SKIP@{SKIP}}
\index{SKIP@{SKIP}!milter@{milter}}
\doxysubsubsection{SKIP}
{\footnotesize\ttfamily int milter.\+SKIP = 5}



Skip further callbacks of the same type in this transaction. 

Currently this return value is only allowed in \doxyref{Milter.\+Base.\+body()}{p.}{classMilter_1_1Base_a963e42c7fcf7bb1a967af48c878b00c7}. It can be used if a milter has received sufficiently many body chunks to make a decision, but still wants to invoke message modification functions that are only allowed to be called from \doxyref{Milter.\+Base.\+eom()}{p.}{classMilter_1_1Base_a725f845830639b76f479dc6c0f7f8c00}. Note\+: the milter must negotiate this behavior with the MTA, i.\+e., it must check whether the protocol action SMFIP\+\_\+\+SKIP is available and if so, the milter must request it. \mbox{\label{namespacemilter_a1b4940e90c267a81cba6be20aa782e85}} 
\index{milter@{milter}!TEMPFAIL@{TEMPFAIL}}
\index{TEMPFAIL@{TEMPFAIL}!milter@{milter}}
\doxysubsubsection{TEMPFAIL}
{\footnotesize\ttfamily int milter.\+TEMPFAIL = 4}



Return a temporary failure, i.\+e., the corresponding SMTP command will return an appropriate 4xx status code. 

For a message-\/oriented routine, except \doxyref{Milter.\+Base.\+envfrom()}{p.}{classMilter_1_1Base_a3d6e5676f4bc54069c996f404d474f41}, fail for this message. For a connection-\/oriented routine, fail for this connection; call \doxyref{Milter.\+Base.\+close()}{p.}{classMilter_1_1Base_a2644dc855f49da0a9810e8d390c93906}. For a recipient-\/oriented routine, only fail for the current recipient; continue message processing. \mbox{\label{namespacemilter_ab678787ccf06b2417a07e7057f7bace4}} 
\index{milter@{milter}!VERSION@{VERSION}}
\index{VERSION@{VERSION}!milter@{milter}}
\doxysubsubsection{VERSION}
{\footnotesize\ttfamily int milter.\+VERSION = 0x1000001}



The compile time libmilter version. 

Python code might need to deal with pymilter compiled against various versions of libmilter. This module constant contains the contents of the {\ttfamily SMFI\+\_\+\+VERSION} macro when the milter module was compiled. 