At the lowest level, the {\ttfamily milter} module provides a thin wrapper around the {\tt sendmail libmilter A\+P\+I}. This A\+P\+I lets you register callbacks for a number of events in the process of sendmail receiving a message via S\+M\+T\+P. These events include the initial connection from a M\+T\+A, the envelope sender and recipients, the top level mail headers, and the message body. There are options to mangle all of these components of the message as it passes through the milter.

At the next level, the {\ttfamily \doxyref{Milter}{p.}{namespaceMilter}} module (note the case difference) provides a Python friendly object oriented wrapper for the low level A\+P\+I. To use the \doxyref{Milter}{p.}{namespaceMilter} module, an application registers a \textquotesingle{}factory\textquotesingle{} to create an object for each connection from a M\+T\+A to sendmail. These connection objects must provide methods corresponding to the libmilter event callbacks.

Each callback method returns a code to tell sendmail whether to proceed with processing the message. This is a big advantage of milters over other mail filtering systems. Unwanted mail can be stopped in its tracks at the earliest possible point. The callback return codes are \doxyref{milter.\+C\+O\+N\+T\+I\+N\+U\+E}{p.}{namespacemilter_a590b7ab395513af007869ad83e332c14}, \doxyref{milter.\+R\+E\+J\+E\+C\+T}{p.}{namespacemilter_a2345250030581a1639ecf905e1668b0a}, \doxyref{milter.\+D\+I\+S\+C\+A\+R\+D}{p.}{namespacemilter_a4c8bad190cb7f54cea87f1182732ce83}, \doxyref{milter.\+A\+C\+C\+E\+P\+T}{p.}{namespacemilter_ae40b8bfbb6828233115c61490998f7f4}, \doxyref{milter.\+T\+E\+M\+P\+F\+A\+I\+L}{p.}{namespacemilter_a1b4940e90c267a81cba6be20aa782e85}, \doxyref{milter.\+S\+K\+I\+P}{p.}{namespacemilter_aa2fa23a83f9bbc204eb14313a6efd4cc}, \doxyref{milter.\+N\+O\+R\+E\+P\+L\+Y}{p.}{namespacemilter_a45378e0b42f76927adaf504b6082fc7d}.

The \doxyref{Milter.\+Base}{p.}{classMilter_1_1Base} class provides default implementations for event methods that do nothing, and also provides wrappers for the libmilter methods to mutate the message. It automatically negotiates with M\+T\+A which protocol steps need to be processed by the milter, based on which callback methods are overridden.

The \doxyref{Milter.\+Milter}{p.}{classMilter_1_1Milter} class provides an alternate default implementation that logs the main milter callbacks, but otherwise does nothing. It is provided for compatibility.

The mime module provides a wrapper for the Python email package that fixes some bugs, and simplifies modifying selected parts of a M\+I\+M\+E message.\section{threading}\label{index_threading}
The libmilter library which pymilter wraps {\tt handles all signals} itself, and expects to be called from a single main thread. It handles S\+I\+G\+T\+E\+R\+M, S\+I\+G\+H\+U\+P, and S\+I\+G\+I\+N\+T, mapping the first two to {\tt smfi\+\_\+stop} and the last to an internal A\+B\+O\+R\+T.

If you use python threads or threading modules, then signal handling gets confused. Threads may still be useful, but you may need to provide an alternate means of causing graceful shutdown.

You may find the {\tt multiprocessing} module useful. It can be a drop-\/in replacement for threading as illustrated in {\tt milter-\/template.\+py}. 