xref: /netbsd-src/external/ibm-public/postfix/dist/proto/MILTER_README.html (revision 924795e69c8bb3f17afd8fcbb799710cc1719dc4)
1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"
2        "http://www.w3.org/TR/html4/loose.dtd">
3
4<html>
5
6<head>
7
8<title>Postfix before-queue Milter support </title>
9
10<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11
12</head>
13
14<body>
15
16<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix before-queue Milter support </h1>
17
18<hr>
19
20<h2>Introduction</h2>
21
22<p> Postfix implements support for the Sendmail version 8 Milter
23(mail filter) protocol. This protocol is used by applications that
24run outside the MTA to inspect SMTP events (CONNECT, DISCONNECT),
25SMTP commands (HELO, MAIL FROM, etc.) as well as mail content
26(headers and body).  All this happens before mail is queued.  </p>
27
28<p> The reason for adding Milter support to Postfix is that there
29exists a large collection of applications, not only to block unwanted
30mail, but also to verify authenticity (examples: <a
31href="http://www.opendkim.org/">OpenDKIM</a> and <a
32href="http://www.trusteddomain.org/opendmarc/">DMARC </a>)
33or to digitally sign mail (example: <a
34href="http://www.opendkim.org/">OpenDKIM</a>).
35Having yet another Postfix-specific version of all that software
36is a poor use of human and system resources. </p>
37
38<p> The Milter protocol has evolved over time, and different Postfix
39versions implement different feature sets.  See the <a
40href="#workarounds">workarounds</a> and <a
41href="#limitations">limitations</a> sections at the end of this
42document for differences between Postfix and Sendmail implementations.
43</p>
44
45<p> This document provides information on the following topics: </p>
46
47<ul>
48
49<li><a href="#plumbing">How Milter applications plug into Postfix </a>
50
51<li><a href="#building">Building Milter applications</a>
52
53<li><a href="#running">Running Milter applications</a>
54
55<li><a href="#config">Configuring Postfix</a>
56
57<li><a href="#workarounds">Workarounds</a>
58
59<li><a href="#limitations">Limitations</a>
60
61</ul>
62
63<h2><a name="plumbing">How Milter applications plug into Postfix </a> </h2>
64
65<p> The Postfix Milter implementation uses two different lists of
66mail filters: one list of filters for SMTP mail only,
67and one list of filters for non-SMTP mail. The two
68lists have different capabilities, which is unfortunate.  Avoiding
69this would require major restructuring of Postfix. </p>
70
71<ul>
72
73<li> <p> The SMTP-only filters handle mail that arrives via the
74Postfix smtpd(8) server. They are typically used to filter unwanted
75mail and to sign mail from authorized SMTP clients. You specify
76SMTP-only Milter applications with the smtpd_milters parameter as
77described in a later section.  Mail that arrives via the Postfix
78smtpd(8) server is not filtered by the non-SMTP filters that are
79described next. </p>
80
81<li> <p> The non-SMTP filters handle mail that arrives via the
82Postfix sendmail(1) command-line or via the Postfix qmqpd(8) server.
83They are typically used to digitally sign mail only. Although
84non-SMTP filters can be used to filter unwanted mail, they have
85limitations compared to the SMTP-only filters. You specify non-SMTP
86Milter applications with the non_smtpd_milters parameter as described
87in a later section.  </p>
88
89</ul>
90
91<p> For those who are familiar with the Postfix architecture, the
92figure below shows how Milter applications plug into Postfix.  Names
93followed by a number are Postfix commands or server programs, while
94unnumbered names inside shaded areas represent Postfix queues.  To
95avoid clutter, the path for local submission is simplified (the
96OVERVIEW document has a more complete description of the Postfix
97architecture).  </p>
98
99<blockquote>
100
101<table>
102
103<tr>
104
105<td colspan="2"> </td>
106
107<td align="center"> SMTP-only <br> filters </td>
108
109<td> </td>
110
111<td align="center"> non-SMTP <br> filters </td>
112
113</tr>
114
115<tr>
116
117<td colspan="2"> </td>
118
119<td align="center"> <table> <tr> <td align="center">
120^<br> <tt> | </tt> </td> <td align="center"> <tt> |<br> v </tt>
121</td> </tr> </table> </td>
122
123<td rowspan="2"> </td>
124
125<td rowspan="3" align="center"> <table> <tr> <td align="center">
126^<br> <tt> |<br> |<br> | </tt> </td> <td align="center"> <tt> |<br>
127|<br> |<br> v </tt> </td> </tr> </table> </td>
128
129</tr>
130
131<tr>
132
133<td> Network </td> <td> <tt> -&gt; </tt> </td>
134
135<td bgcolor="#f0f0ff" align="center" valign="middle"> smtpd(8)
136</td>
137
138</tr>
139
140<tr>
141
142<td colspan="3"> </td> <td> <tt> \ </tt> </td>
143
144</tr>
145
146<tr>
147
148<td> Network </td> <td> <tt> -&gt; </tt> </td>
149
150<td bgcolor="#f0f0ff" align="center" valign="middle"> qmqpd(8)
151</td>
152
153<td> <tt> -&gt; </tt> </td>
154
155<td bgcolor="#f0f0ff" align="center" valign="middle"> cleanup(8)
156</td>
157
158<td> <tt> -&gt; </tt> </td>
159
160<td bgcolor="#f0f0ff" align="center" valign="middle"> <a
161href="QSHAPE_README.html#incoming_queue"> incoming </a> </td>
162
163</tr>
164
165<tr>
166
167<td colspan="3"> </td> <td> <tt> / </tt> </td>
168
169</tr>
170
171<tr>
172
173<td colspan="2"> </td>
174
175<td bgcolor="#f0f0ff" align="center" valign="middle"> pickup(8)
176</td>
177
178</tr>
179
180<tr> <td colspan="2"> </td> <td align="center"> : </td> </tr>
181
182<tr>
183
184<td> Local </td> <td> <tt> -&gt; </tt> </td>
185
186<td bgcolor="#f0f0ff" align="center" valign="middle"> sendmail(1)
187</td>
188
189</tr>
190
191</table>
192
193</blockquote>
194
195<h2><a name="building">Building Milter applications</a></h2>
196
197<p> Milter applications have been written in C, JAVA and Perl, but
198this document deals with C applications only.   For these, you need
199an object library that implements the Sendmail 8 Milter protocol.
200Postfix currently does not provide such a library, but Sendmail
201does. </p>
202
203<p> Some
204systems install the Sendmail libmilter library by default.  With
205other systems, libmilter may be provided by a package (called
206"sendmail-devel" on some Linux systems).  </p>
207
208<p> Once libmilter is installed, applications such as <a
209href="http://www.opendkim.org/">OpenDKIM</a> and
210<a href="http://www.trusteddomain.org/opendmarc/">OpenDMARC</a>
211build out of the box without requiring any tinkering:</p>
212
213<blockquote>
214<pre>
215$ <b>gzcat opendkim-<i>x.y.z</i>.tar.gz | tar xf -</b>
216$ <b>cd opendkim-<i>x.y.z</i></b>
217$ <b>./configure ...<i>options</i>...</b>
218$ <b>make</b>
219[...<i>lots of output omitted</i>...]
220$ <b>make install</b>
221</pre>
222</blockquote>
223
224<h2><a name="running">Running Milter applications</a></h2>
225
226<p> To run a Milter application, see the documentation of the filter
227for options.  A typical command looks like this:</p>
228
229<blockquote>
230<pre>
231# <b>/some/where/opendkim -l -u <i>userid</i> -p inet:<i>portnumber</i>@localhost ...<i>other options</i>...</b>
232</pre>
233</blockquote>
234
235<p> Please specify a <i>userid</i> value that isn't used for other
236applications (not "postfix", not "www", etc.). </p>
237
238<h2><a name="config">Configuring Postfix</a></h2>
239
240<p> Like Sendmail, Postfix has a lot of configuration options that
241control how it talks to Milter applications. Besides global options
242that apply to all Milter applications, Postfix 3.0 and later
243support per-Milter timeouts, per-Milter error handling, etc. </p>
244
245<p> Information in this section: </p>
246
247<ul>
248
249<li><a href="#smtp-only-milters">SMTP-Only Milter applications </a>
250
251<li><a href="#non-smtp-milters">Non-SMTP Milter applications </a>
252
253<li><a href="#errors">Milter error handling </a>
254
255<li><a href="#version">Milter protocol version</a>
256
257<li><a href="#timeouts">Milter protocol timeouts</a>
258
259<li><a href="#per-milter">Different settings for different Milter
260applications </a>
261
262<li><a href="#per-client">Different settings for different SMTP
263clients </a>
264
265<li><a href="#macros">Sendmail macro emulation</a>
266
267<li><a href="#send-macros">What macros will Postfix send to Milters?</a>
268
269</ul>
270
271<h3><a name="smtp-only-milters">SMTP-Only Milter applications</a></h3>
272
273<p>  The SMTP-only Milter applications handle mail that arrives via
274the Postfix smtpd(8) server. They are typically used to filter
275unwanted mail, and to sign mail from authorized SMTP clients.  Mail
276that arrives via the Postfix smtpd(8) server is not filtered by the
277non-SMTP filters that are described in the next section. </p>
278
279<blockquote> NOTE for Postfix versions that have a mail_release_date
280before 20141018: do not use the header_checks(5) IGNORE action to remove
281Postfix's own Received: message header. This causes problems with
282mail signing filters. Instead, keep Postfix's own Received: message
283header and use the header_checks(5) REPLACE action to sanitize
284information. </blockquote>
285
286<p> You specify SMTP-only Milter applications (there can be more
287than one) with the smtpd_milters parameter.  Each Milter application
288is identified by the name of its listening socket; other Milter
289configuration options will be discussed in later sections.  Milter
290applications are applied in the order as specified, and the first
291Milter application that rejects a command will override the responses
292from other Milter applications.  </p>
293
294<blockquote>
295<pre>
296/etc/postfix/main.cf:
297    # Milters for mail that arrives via the smtpd(8) server.
298    # See below for socket address syntax.
299    smtpd_milters = inet:localhost:<i>portnumber</i> ...<i>other filters</i>...
300</pre>
301</blockquote>
302
303<p> The general syntax for listening sockets is as follows: </p>
304
305<blockquote>
306
307<dl>
308
309<dt> <b>unix:</b><i>pathname</i> </dt> <dd><p>Connect to the local
310UNIX-domain server that is bound to the specified pathname. If the
311smtpd(8) or cleanup(8) process runs chrooted, an absolute pathname
312is interpreted relative to the Postfix queue directory. On many
313systems, <b>local</b> is a synonym for <b>unix</b></p> </dd>
314
315<dt> <b> inet:</b><i>host</i><b>:</b><i>port</i> </dt> <dd> <p>
316Connect to the specified TCP port on the specified local or remote
317host.  The host and port can be specified in numeric or symbolic
318form.</p>
319
320<p> NOTE: Postfix syntax differs from Milter syntax which has the
321form <b>inet:</b><i>port</i><b>@</b><i>host</i>. </p>  </dd>
322
323</dl>
324
325</blockquote>
326
327<p> For advanced configuration see "<a href="#per-client">Different
328settings for different SMTP clients</a>" and "<a
329href="#per-milter">Different settings for different Milter
330applications</a>". </p>
331
332<h3> <a name="non-smtp-milters">Non-SMTP Milter applications </a> </h3>
333
334<p> The non-SMTP Milter applications handle mail that arrives via
335the Postfix sendmail(1) command-line or via the Postfix qmqpd(8)
336server. They are typically used to digitally sign mail. Although
337non-SMTP filters can be used to filter unwanted mail, there are
338limitations as discussed later in this section.  Mail that arrives
339via the Postfix smtpd(8) server is not filtered by the non-SMTP
340filters.  </p>
341
342<p> NOTE: Do not use the header_checks(5) IGNORE action to remove
343Postfix's own Received: message header. This causes problems with
344mail signing filters. Instead, keep Postfix's own Received: message
345header and use the header_checks(5) REPLACE action to sanitize
346information. </p>
347
348<p> You specify non-SMTP Milter applications with the non_smtpd_milters
349parameter. This parameter uses the same syntax as the smtpd_milters
350parameter in the previous section. As with the SMTP-only filters,
351you can specify more than one Milter application; they are applied
352in the order as specified, and the first Milter application that
353rejects a command will override the responses from the other
354applications.  </p>
355
356<blockquote>
357<pre>
358/etc/postfix/main.cf:
359    # Milters for non-SMTP mail.
360    # See below for socket address syntax.
361    non_smtpd_milters = inet:localhost:<i>portnumber</i> ...<i>other filters</i>...
362</pre>
363</blockquote>
364
365<p> There's one small complication when using Milter applications
366for non-SMTP mail: there is no SMTP session.  To keep Milter
367applications happy, the Postfix cleanup(8) server actually has to
368simulate the SMTP client CONNECT and DISCONNECT events, and the
369SMTP client EHLO, MAIL FROM, RCPT TO and DATA commands. </p>
370
371<ul>
372
373<li> <p> When new mail arrives via the sendmail(1) command line,
374the Postfix cleanup(8) server pretends that the mail arrives with
375ESMTP from "localhost" with IP address "127.0.0.1". The result is
376very similar to what happens with command line submissions in
377Sendmail version 8.12 and later, although Sendmail uses a different
378mechanism to achieve this result.  </p>
379
380<li> <p> When new mail arrives via the qmqpd(8) server, the Postfix
381cleanup(8) server pretends that the mail arrives with ESMTP, and
382uses the QMQPD client hostname and IP address. </p>
383
384<li> <p> When old mail is re-injected into the queue with "postsuper
385-r", the Postfix cleanup(8) server uses the same client information
386that was used when the mail arrived as new mail. </p>
387
388</ul>
389
390<p> This generally works as expected, with only one exception:
391non-SMTP filters must not REJECT or TEMPFAIL simulated RCPT TO
392commands.  When a non_smtpd_milters application REJECTs or TEMPFAILs
393a recipient, Postfix will report a configuration error, and mail
394will stay in the queue.  </p>
395
396<h4> Signing internally-generated bounce messages </h4>
397
398<p> Postfix normally does not apply content filters to mail
399that is generated internally such as bounces or Postmaster
400notifications. Filtering internally-generated bounces would result
401in loss of mail when a filter rejects a message, as the resulting
402double-bounce message would almost certainly also be blocked. </p>
403
404<p>  To sign Postfix's own bounce messages, enable filtering of
405internally-generated bounces (line 2 below), and don't reject any
406internally-generated bounces with non_smtpd_milters, header_checks
407or body_checks (lines 3-5 below).  </p>
408
409<blockquote>
410<pre>
4111 /etc/postfix/main.cf:
4122     internal_mail_filter_classes = bounce
4133     non_smtpd_milters = <i>don't reject internally-generated bounces</i>
4144     header_checks = <i>don't reject internally-generated bounces</i>
4155     body_checks = <i>don't reject internally-generated bounces</i>
416</pre>
417</blockquote>
418
419<h3><a name="errors">Milter error handling</a></h3>
420
421<p> The milter_default_action parameter specifies how Postfix handles
422Milter application errors. The default action is to respond with a
423temporary error status, so that the client will try again later.
424Specify "accept" if you want to receive mail as if the filter does
425not exist, and "reject" to reject mail with a permanent status.
426The "quarantine" action is like "accept" but freezes the message
427in the "hold" queue, and is available with Postfix 2.6 or later.
428</p>
429
430<blockquote>
431<pre>
432/etc/postfix/main.cf:
433    # What to do in case of errors? Specify accept, reject, tempfail,
434    # or quarantine (Postfix 2.6 or later).
435    milter_default_action = tempfail
436</pre>
437</blockquote>
438
439<p> See "<a href="#per-milter">Different settings for different
440Milter applications</a>" for advanced configuration options. </p>
441
442<h3><a name="version">Milter protocol version</a></h3>
443
444<p> As Postfix is not built with the Sendmail libmilter library,
445you may need to configure the Milter protocol version that Postfix
446should use.  The default version is 6 (before Postfix 2.6 the default
447version is 2). </p>
448
449<blockquote>
450<pre>
451/etc/postfix/main.cf:
452    # Postfix &ge; 2.6
453    milter_protocol = 6
454    # 2.3 &le; Postfix &le; 2.5
455    milter_protocol = 2
456</pre>
457</blockquote>
458
459<p> If the Postfix milter_protocol setting specifies a too low
460version, the libmilter library will log an error message like this:
461</p>
462
463<blockquote>
464<pre>
465<i>application name</i>: st_optionneg[<i>xxxxx</i>]: 0x<i>yy</i> does not fulfill action requirements 0x<i>zz</i>
466</pre>
467</blockquote>
468
469<p> The remedy is to increase the Postfix milter_protocol version
470number.  See, however, the <a href="#limitations">limitations</a>
471section below for features that aren't supported by Postfix. </p>
472
473<p> With Postfix 2.7 and earlier, if the Postfix milter_protocol
474setting specifies a too high
475version, the libmilter library simply hangs up without logging a
476warning, and you see a Postfix warning message like one of the
477following: </p>
478
479<blockquote>
480<pre>
481warning: milter inet:<i>host</i>:<i>port</i>: can't read packet header: Unknown error : 0
482warning: milter inet:<i>host</i>:<i>port</i>: can't read packet header: Success
483warning: milter inet:<i>host</i>:<i>port</i>: can't read SMFIC_DATA reply packet header: No such file or directory
484</pre>
485</blockquote>
486
487<p> The remedy is to lower the Postfix milter_protocol version
488number. Postfix 2.8 and later will automatically turn off protocol
489features that the application's libmilter library does not expect.
490</p>
491
492<p> See "<a href="#per-milter">Different settings for different
493Milter applications</a>" for advanced configuration options. </p>
494
495<h3><a name="timeouts">Milter protocol timeouts</a></h3>
496
497<p> Postfix uses different time limits at different Milter protocol
498stages. The table shows the timeout settings and the corresponding
499protocol stages
500(EOH = end of headers; EOM = end of message).  </p>
501
502<blockquote>
503
504<table border="1">
505
506<tr> <th> Postfix parameter </th> <th> Time limit </th> <th> Milter
507protocol stage</th> </tr>
508
509<tr> <td> milter_connect_timeout </td> <td> 30s </td> <td> CONNECT
510</td> </tr>
511
512<tr> <td> milter_command_timeout </td> <td> 30s </td> <td> HELO,
513MAIL, RCPT, DATA, UNKNOWN </td> </tr>
514
515<tr> <td> milter_content_timeout </td> <td> 300s </td> <td> HEADER,
516EOH, BODY, EOM </td> </tr>
517
518</table>
519
520</blockquote>
521
522<p> Beware: 30s may be too short for Milter applications that do
523lots of DNS lookups.  However, if you increase the above timeouts
524too much, remote SMTP clients may hang up and mail may be delivered
525multiple times. This is an inherent problem with before-queue
526filtering. </p>
527
528<p> See "<a href="#per-milter">Different settings for different
529Milter applications</a>" for advanced configuration options. </p>
530
531<h3><a name="per-milter">Different settings for different Milter
532applications </a></h3>
533
534<p> The previous sections list a number of Postfix main.cf parameters
535that control time limits and other settings for all Postfix Milter
536clients. This is sufficient for simple configurations. With more
537complex configurations it becomes desirable to have different
538settings for different Milter clients. This is supported with Postfix
5393.0 and later. </p>
540
541<p> The following example shows a "non-critical" Milter client with
542a short connect timeout, and with "accept" as default action when
543the service is unvailable. </p>
544
545<blockquote>
546<pre>
5471 /etc/postfix/main.cf:
5482     smtpd_milters = { inet:host:port,
5493         connect_timeout=10s, default_action=accept }
550</pre>
551</blockquote>
552
553<p> Instead of a server endpoint, we now have a list enclosed in {}. </p>
554
555<ul>
556
557<li> <p> Line 2: The first item in the list is the server endpoint.
558This supports the exact same "inet" and "unix" syntax as described
559earlier. </p>
560
561<li> <p> Line 3: The remainder of the list contains per-Milter
562settings. These settings override global main.cf parameters, and
563have the same name as those parameters, without the "milter_" prefix.
564The per-Milter settings that are supported as of Postfix 3.0 are
565command_timeout, connect_timeout, content_timeout, default_action,
566and protocol.  </p>
567
568</ul>
569
570<p> Inside the list, syntax is similar to what we already know from
571main.cf: items separated by space or comma. There is one difference:
572<b>you must enclose a setting in parentheses, as in "{ name = value
573}", if you want to have space or comma within a value or around
574"="</b>.  </p>
575
576<h3><a name="per-client">Different settings for different SMTP
577clients </a></h3>
578
579<p> The smtpd_milter_maps feature supports different Milter settings
580for different client IP addresses. Lookup results override the the
581global smtpd_milters setting, and have the same syntax. For example,
582to disable Milter settings for local address ranges: </p>
583
584<pre>
585/etc/postfix/main.cf:
586    smtpd_milter_maps = cidr:/etc/postfix/smtpd_milter_map
587    smtpd_milters = inet:host:port, { inet:host:port, ... }, ...
588
589/etc/postfix/smtpd_milter_map:
590    # Disable Milters for local clients.
591    127.0.0.0/8    DISABLE
592    192.168.0.0/16 DISABLE
593    ::/64          DISABLE
594    2001:db8::/32  DISABLE
595</pre>
596
597<p> This feature is available with Postfix 3.2 and later. </p>
598
599<h3><a name="macros">Sendmail macro emulation</a></h3>
600
601<p> Postfix emulates a limited number of Sendmail macros, as shown
602in the table. Some macro values depend on whether a recipient is
603rejected (rejected recipients are available on request by the Milter
604application). Different macros are available at different Milter
605protocol stages (EOH = end-of-header, EOM = end-of-message); their
606availability is not
607always the same as in Sendmail. See the <a
608href="#workarounds">workarounds</a> section below for solutions.
609</p>
610
611<blockquote>
612
613<table border="1">
614
615<tr> <th> Sendmail macro </th> <th> Milter protocol stage </th>
616<th> Description </th> </tr>
617
618<tr> <td> i </td> <td> DATA, EOH, EOM </td> <td> Queue ID, also
619Postfix queue file name </td> </tr>
620
621<tr> <td> j </td> <td> Always </td> <td> Value of myhostname </td>
622</tr>
623
624<tr> <td> _ </td> <td> Always </td> <td> The validated client name
625and address </td> </tr>
626
627<tr> <td> {auth_authen} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
628login name </td> </tr>
629
630<tr> <td> {auth_author} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
631sender </td> </tr>
632
633<tr> <td> {auth_type} </td> <td> MAIL, DATA, EOH, EOM </td> <td> SASL
634login method </td> </tr>
635
636<tr> <td> {client_addr} </td> <td> Always </td> <td> Remote client
637IP address </td> </tr>
638
639<tr> <td> {client_connections} </td> <td> CONNECT </td> <td>
640Connection concurrency for this client (zero if the client is
641excluded from all smtpd_client_* limits). </td> </tr>
642
643<tr> <td> {client_name} </td> <td> Always </td> <td> Remote client
644hostname <br> When address &rarr; name lookup or name &rarr; address
645verification fails: "unknown" </td> </tr>
646
647<tr> <td> {client_port} </td> <td> Always (Postfix &ge;2.5) </td>
648<td> Remote client TCP port </td> </tr>
649
650<tr> <td> {client_ptr} </td> <td> CONNECT, HELO, MAIL, DATA </td>
651<td> Client name from address &rarr; name lookup <br> When address
652&rarr; name lookup fails: "unknown" </td> </tr>
653
654<tr> <td> {cert_issuer} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td>
655TLS client certificate issuer </td> </tr>
656
657<tr> <td> {cert_subject} </td> <td> HELO, MAIL, DATA, EOH, EOM </td>
658<td> TLS client certificate subject </td> </tr>
659
660<tr> <td> {cipher_bits} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td>
661TLS session key size </td> </tr>
662
663<tr> <td> {cipher} </td> <td> HELO, MAIL, DATA, EOH, EOM </td> <td> TLS
664cipher </td> </tr>
665
666<tr> <td> {daemon_addr} </td> <td> Always (Postfix &ge;3.2) </td>
667<td> Local server IP address </td> </tr>
668
669<tr> <td> {daemon_name} </td> <td> Always </td> <td> value of
670milter_macro_daemon_name </td> </tr>
671
672<tr> <td> {daemon_port} </td> <td> Always (Postfix &ge;3.2) </td>
673<td> Local server TCP port </td> </tr>
674
675<tr> <td> {mail_addr} </td> <td> MAIL </td> <td> Sender address
676</td> </tr>
677
678<tr> <td> {mail_host} </td> <td> MAIL (Postfix &ge; 2.6, only with
679smtpd_milters) </td> <td> Sender next-hop destination </td> </tr>
680
681<tr> <td> {mail_mailer} </td> <td> MAIL (Postfix &ge; 2.6, only with
682smtpd_milters) </td> <td> Sender mail delivery transport </td> </tr>
683
684<tr> <td> {rcpt_addr} </td> <td> RCPT </td> <td> Recipient address
685<br> With rejected recipient: descriptive text </td> </tr>
686
687<tr> <td> {rcpt_host} </td> <td> RCPT (Postfix &ge; 2.6, only with
688smtpd_milters) </td> <td> Recipient next-hop destination <br> With
689rejected recipient: enhanced status code </td> </tr>
690
691<tr> <td> {rcpt_mailer} </td> <td> RCPT (Postfix &ge; 2.6, only with
692smtpd_milters) </td> <td> Recipient mail delivery transport <br>
693With rejected recipient: "error" </td> </tr>
694
695<tr> <td> {tls_version} </td> <td> HELO, MAIL, DATA, EOH, EOM </td>
696<td> TLS protocol version </td> </tr>
697
698<tr> <td> v </td> <td> Always </td> <td> value of milter_macro_v
699</td> </tr>
700
701</table>
702
703</blockquote>
704
705<h3><a name="send-macros">What macros will Postfix send to Milters?</a></h3>
706
707<p> Postfix sends specific sets of macros at different Milter protocol
708stages.  The sets are configured with the parameters as shown in the
709table below (EOH = end of headers; EOM = end of message). The
710protocol version is a number that Postfix sends at the beginning
711of the Milter protocol handshake. </p>
712
713<p> As of Sendmail 8.14.0, Milter applications can specify what
714macros they want to receive at different Milter protocol stages.
715An application-specified list takes precedence over a Postfix-specified
716list. </p>
717
718<blockquote>
719
720<table border="1">
721
722<tr> <th> Postfix parameter </th> <th> Milter protocol version </th>
723<th> Milter protocol stage </th> </tr>
724
725<tr> <td> milter_connect_macros </td> <td> 2 or higher </td> <td>
726CONNECT </td> </tr>
727
728<tr> <td> milter_helo_macros </td> <td> 2 or higher </td> <td>
729HELO/EHLO </td> </tr>
730
731<tr> <td> milter_mail_macros </td> <td> 2 or higher </td> <td> MAIL
732FROM </td> </tr>
733
734<tr> <td> milter_rcpt_macros </td> <td> 2 or higher </td> <td> RCPT
735TO </td> </tr>
736
737<tr> <td> milter_data_macros </td> <td> 4 or higher </td> <td> DATA
738</td> </tr>
739
740<tr> <td> milter_end_of_header_macros </td> <td> 6 or higher </td>
741<td> EOH </td> </tr>
742
743<tr> <td> milter_end_of_data_macros </td> <td> 2 or higher </td>
744<td> EOM </td> </tr>
745
746<tr> <td> milter_unknown_command_macros </td> <td> 3 or higher </td>
747<td> unknown command </td> </tr>
748
749</table>
750
751</blockquote>
752
753<p> By default, Postfix will send only macros whose values have been
754updated with information from main.cf or master.cf, from an SMTP session
755(for example; SASL login, or TLS certificates) or from a Mail delivery
756transaction (for example; queue ID, sender, or recipient). </p>
757
758<p> To force a macro to be sent even when its value has not been updated,
759you may specify macro default values with the milter_macro_defaults
760parameter. Specify zero or more <i>name=value</i> pairs separated by
761comma or whitespace; you may even specify macro names that Postfix does
762not know about! </p>
763
764<h2><a name="workarounds">Workarounds</a></h2>
765
766<ul>
767
768<li> <p> To avoid breaking DKIM etc. signatures with an SMTP-based
769content filter, update the before-filter SMTP client in master.cf,
770and add a line with "-o disable_mime_output_conversion=yes" (note:
771no spaces around the "="). For details, see the <a
772href="FILTER_README.html#advanced_filter">advanced content filter</a>
773example. </p>
774
775<pre>
776/etc/postfix/master.cf:
777    # =============================================================
778    # service type  private unpriv  chroot  wakeup  maxproc command
779    #               (yes)   (yes)   (yes)   (never) (100)
780    # =============================================================
781    scan      unix  -       -       n       -       10      smtp
782        -o smtp_send_xforward_command=yes
783        -o disable_mime_output_conversion=yes
784        -o smtp_generic_maps=
785</pre>
786
787<li> <p> Some Milter applications use the "<tt>{if_addr}</tt>" macro
788to recognize local mail; this macro does not exist in Postfix.
789Workaround: use the "<tt>{daemon_addr}</tt>" (Postfix &ge; 3.2) or
790"<tt>{client_addr}</tt>" macro instead. </p>
791
792<li> <p> Some Milter applications log a warning that looks like
793this: </p>
794
795<blockquote> <pre>
796sid-filter[36540]: WARNING: sendmail symbol 'i' not available
797</pre>
798</blockquote>
799
800<p> And they may insert an ugly message header with "unknown-msgid"
801like this: </p>
802
803<blockquote>
804<pre>
805X-SenderID: Sendmail Sender-ID Filter vx.y.z host.example.com &lt;unknown-msgid&gt;
806</pre>
807</blockquote>
808
809<p> The problem is that Milter applications expect that the queue
810ID is known <i>before</i> the MTA accepts the MAIL FROM (sender)
811command.  Postfix does not choose a queue ID, which is used as the
812queue file name, until <i>after</i> it accepts the first valid RCPT
813TO (recipient) command. </p>
814
815<p> If you experience the ugly header problem, see if a recent
816version of the Milter application fixes it. For example, current
817versions of dkim-filter and dk-filter already have code that looks
818up the Postfix queue ID at a later protocol stage, and sid-filter
819version 1.0.0 no longer includes the queue ID in the message header.
820</p>
821
822<p> To fix the ugly message header, you will need to add code that
823looks up the Postfix queue ID at some later point in time. The
824example below adds the lookup after the end-of-message.  </p>
825
826<ul>
827
828<li> <p> Edit the filter source file (typically named
829<tt>xxx-filter/xxx-filter.c</tt> or similar). </p>
830
831<li> <p> Look up the <tt>mlfi_eom()</tt> function and add code near
832the top shown as <b>bold</b> text below: </p>
833
834</ul>
835
836<blockquote>
837<pre>
838dfc = cc->cctx_msg;
839assert(dfc != NULL);
840<b>
841/* Determine the job ID for logging. */
842if (dfc->mctx_jobid == 0 || strcmp(dfc->mctx_jobid, JOBIDUNKNOWN) == 0) {
843        char *jobid = smfi_getsymval(ctx, "i");
844        if (jobid != 0)
845                dfc->mctx_jobid = jobid;
846}</b>
847</pre>
848</blockquote>
849
850<p> NOTES: </p>
851
852<ul>
853
854<li> <p> Different mail filters use slightly different names for
855variables. If the above code does not compile, look elsewhere in
856the mail filter source file for code that looks up the "i" macro
857value, and copy that code.  </p>
858
859<li> <p> This change fixes only the ugly message header, but not
860the WARNING message.  Fortunately, many Milters log that message
861only once. </p>
862
863</ul>
864
865</ul>
866
867<h2><a name="limitations">Limitations</a></h2>
868
869<p> This section lists limitations of the Postfix Milter implementation.
870Some limitations will be removed as the implementation is extended
871over time. Of course the usual limitations of before-queue filtering
872will always apply. See the CONTENT_INSPECTION_README document for
873a discussion. </p>
874
875<ul>
876
877<li> <p> The Milter protocol has evolved over time. Therefore,
878different Postfix versions implement different feature sets. </p>
879
880<table border="1">
881
882<tr> <th> Postfix </th> <th> Supported Milter requests </th>
883</tr>
884
885<tr> <td align="center"> 2.6 </td> <td> All Milter requests of
886Sendmail 8.14.0 (see notes below).  </td> </tr>
887
888<tr> <td align="center"> 2.5 </td> <td> All Milter requests of
889Sendmail 8.14.0, except: <br> SMFIP_RCPT_REJ (report rejected
890recipients to the mail filter), <br> SMFIR_CHGFROM (replace sender,
891with optional ESMTP parameters), <br> SMFIR_ADDRCPT_PAR (add
892recipient, with optional ESMTP parameters). </td> </tr>
893
894<tr> <td align="center"> 2.4 </td> <td> All Milter requests of
895Sendmail 8.13.0.  </td> </tr>
896
897<tr> <td align="center"> 2.3 </td> <td> All Milter requests of
898Sendmail 8.13.0, except: <br> SMFIR_REPLBODY (replace message body).
899
900</table>
901
902<li> <p> For Milter applications that are written in C, you need
903to use the Sendmail libmilter library. </p>
904
905<li> <p> Postfix has TWO sets of mail filters: filters that are used
906for SMTP mail only (specified with the smtpd_milters parameter),
907and filters for non-SMTP mail (specified with the non_smtpd_milters
908parameter).  The non-SMTP filters are primarily for local submissions.
909</p>
910
911<p> When mail is filtered by non_smtpd_milters, the Postfix cleanup(8)
912server has to simulate SMTP client requests.  This works as expected,
913with only one exception: non_smtpd_milters must not REJECT or
914TEMPFAIL simulated RCPT TO commands. When this rule is violated,
915Postfix will report a configuration error, and mail will stay in
916the queue.  </p>
917
918<li> <p> When you use the before-queue content filter for incoming
919SMTP mail (see SMTPD_PROXY_README), Milter applications have access
920only to the SMTP command information; they have no access to the
921message header or body, and cannot make modifications to the message
922or to the envelope. </p>
923
924<li> <p> Postfix 2.6 ignores the optional ESMTP parameters in
925requests to replace the sender (SMFIR_CHGFROM) or to append a
926recipient (SMFIR_ADDRCPT_PAR). Postfix logs a warning message when
927a Milter application supplies such ESMTP parameters: </p>
928
929<pre>
930warning: <i>queue-id</i>: cleanup_chg_from: ignoring ESMTP arguments "<i>whatever</i>"
931warning: <i>queue-id</i>: cleanup_add_rcpt: ignoring ESMTP arguments "<i>whatever</i>"
932</pre>
933
934<li> <p> Postfix 2.3 does not implement requests to replace the
935message body. Milter applications log a warning message when they
936need this unsupported operation: </p>
937
938<pre>
939st_optionneg[134563840]: 0x3d does not fulfill action requirements 0x1e
940</pre>
941
942<p> The solution is to use Postfix version 2.4 or later. </p>
943
944<li> <p> Most Milter configuration options are global. Future Postfix
945versions may support per-Milter timeouts, per-Milter error handling,
946etc. </p>
947
948</ul>
949
950</body>
951
952</html>
953