In addition to its own initialization, libmilter expects a filter to initialize several parameters before calling <ahref="smfi_main.html">smfi_main</a>:
<ul>
<li>The callbacks the filter wishes to be called, and the types of
message modification it intends to perform (required, see <a
href="smfi_register.html">smfi_register</a>).
<li>The socket address to be used when communicating with the MTA
(required, see <ahref="smfi_setconn.html">smfi_setconn</a>).
<li>The number of seconds to wait for MTA connections before
timing out (optional, see <a
href="smfi_settimeout.html">smfi_settimeout</a>).
</ul>
<p>
If the filter fails to initialize libmilter, or if one or more of the
parameters it has passed are invalid, a subsequent call to smfi_main
will fail.
<h2>Control flow</h2>
<p>
The following pseudocode describes the filtering process from the
perspective of a set of <code>N</code> MTA's, each corresponding to a
connection. Callbacks are shown beside the processing stages in which
they are invoked; if no callbacks are defined for a particular stage,
that stage may be bypassed. Though it is not shown, processing may be
aborted at any time during a message, in which case the <a
href="xxfi_abort.html">xxfi_abort</a> callback is invoked and control
returns to <code>MESSAGE</code>.
<p>
<pre>
For each of N connections
{
For each filter
process connection/helo (<ahref="xxfi_connect.html">xxfi_connect</a>, <ahref="xxfi_helo.html">xxfi_helo</a>)
MESSAGE:For each message in this connection (sequentially)
{
For each filter
process sender (<ahref="xxfi_envfrom.html">xxfi_envfrom</a>)
For each recipient
{
For each filter
process recipient (<ahref="xxfi_envrcpt.html">xxfi_envrcpt</a>)
}
For each filter
{
For each header
process header (<ahref="xxfi_header.html">xxfi_header</a>)
process end of headers (<ahref="xxfi_eoh.html">xxfi_eoh</a>)
For each body block
process this body block (<ahref="xxfi_body.html">xxfi_body</a>)
process end of message (<ahref="xxfi_eom.html">xxfi_eom</a>)
}
}
For each filter
process end of connection (<ahref="xxfi_close.html">xxfi_close</a>)
}
</pre>
<P>Note: Filters are contacted in order defined in config file.</P>
<P>
To write a filter, a vendor supplies callbacks to process relevant
parts of a message transaction. The library then controls all
sequencing, threading, and protocol exchange with the MTA. <a
href="#figure-3">Figure 3</a> outlines control flow for a filter
process, showing where different callbacks are invoked.