mailmunge - Milter for writing mail policy in Perl
mailmunge prcap mailmunge -p connection -m mx_socket_name -U user [options]
mailmunge is a filter built around Sendmail 8.11 and later's Milter API for mail filters. It lets you write Milter filtering policy in Perl.
mailmunge does not actually run the Perl filter; instead, it communicates with
mailmunge-multiplexor, which manages a pool of persistent Perl processes. See the mailmunge-multiplexor man page for additional information.
If you invoke
mailmunge with the single argument
prcap, it prints information about the version of Milter it is linked against and exits. Otherwise, you should invoke
mailmunge as shown in the second line of the SYNOPSIS.
Conserve file descriptors by opening and closing disk files more often. Disk files will be closed when a Milter callback ends and reopened when another callback is invoked. While this shortens the length of time a file descriptor is open, it also leaves more opportunities for the open to fail. We do not recommend the use of this flag except on very busy systems that exhibit failures due to a shortage of file descriptors.
Do not fork into the background and become a daemon. Instead, stay in the foreground. Useful mainly for debugging or if you have a supervisory process such as
mailmungeuses a umask of 077 when creating the milter socket and files. If you would like the socket to be readable and writeable by the group and files to be group-readable, supply the
-Goption. This causes the umask to be 007 whenever UNIX-domain sockets are created and 027 whenever files are created. Note: if your milter library is too old to have the smfi_opensocket() function, the
mailmungeto use a umask of 007 throughout its execution.
mailmungeto perform a HELO check when the SMTP client issues a HELO or EHLO command. It causes the filter's
filter_helomethod to be invoked. (See Mailmunge::Filter for details.)
mailmungesees all envelope recipients, even ones that Sendmail knows to be invalid. If you don't want Sendmail to perform a milter callback for recipients it knows to be invalid, invoke
mailmungewith the -N flag. Please note that this flag only works with Sendmail and Milter 8.14.0 and newer. It has no effect if you're running an older version of Sendmail or Milter.
- -P fileName
mailmungeto write its process-ID (after becoming a daemon) to the specified file. The file will be owned by root.
- -R num
mailmungetempfails a new SMTP connection if there are no free workers. Supplying the
-Rnum option makes
mailmungetempfail new connections if there are fewer than num free workers, unless the connection is from the local host. This allows you to favour connections from localhost so your clientmqueue doesn't build up. Note that supplying
-R 0is subtly different from omitting the option; in this case,
mailmungepermits new connections from localhost to queue, but not connections from other hosts (unless you also supply the
The purpose of the
-Roption is to reserve resources for clientmqueue runs. Otherwise, on a very busy mail server, clientmqueue runs can starve for a long time, leading to delays for locally-generated or streamed mail. We recommend using a small number for num; probably no more than 3 or 10% of the total number of workers (whichever is smaller.)
Note that this option and the
-qoption are mutually-exclusive. If you supply
- -S facility
Specifies the syslog facility for log messages. The default is mail. See the
openlogman page for a list of valid facilities. You can use either the short name ("mail") or long name ("LOG_MAIL") for the facility name.
mailmungeto log the run-time of the Perl filter using syslog.
- -U user
mailmungeas user rather than root. The user argument must match the argument to
-Uoption as well.
Do not add an X-Scanned-By: header. Specifying -X is equivalent to specifying -x "".
- -a macro
Pass the value of the specified Sendmail macro through to the Perl filter. You can repeat the -a option to write more macros than the built-in defaults. Note that in addition to asking
mailmungeto pass the macro value to the filter, you must configure Sendmail to pass the macro through to
mailmungeusing the confMILTER_MACROS_ENVFROM definition in Sendmail's m4 configuration file.
- -b backlog
Sets the "backlog" argument to the
listensystem call to backlog. If this option is omitted, then the operating-system default backlog is used.
Strip "bare" carriage-returns (CR) characters from the message body. A bare CR should never appear in an e-mail message. Older versions of
mailmungeused to strip them out automatically, but now they are left in by default. The
-coption enables the older behavior.
mailmungenot to delete the temporary spool files it creates for incoming messages. This is for debugging purposes only and should never be used on a production mail server.
Print usage information and exit.
mailmungenot to delete working directories if a filter fails. This lets you obtain the message which caused the filter to fail and determine what went wrong.
mailmungelogs the directory containing the failed message using syslog.
- -m mx_socket_name
Specifies the socket for communicating with
mailmunge-multiplexor. The mx_socket_name specifies the path of the UNIX-domain socket. See mailmunge-multiplexor for details and "SOCKET SPECIFICATION" for the format of mx_socket_name.
- -o fileName
mailmungeto use fileName as a lock file to avoid multiple instances from running. If you supply
mailmungeconstructs a lock file by appending ".lock" to the pid file. However, this is less secure than having a root-owned pid file in a root-owned directory and a lock file writable by the user named by the
-Uoption. (The lock file must be writable by the
- -p connection
-pswitch is required and specifies the milter connection type. Typically, you should run
mailmungeon the same computer as
sendmail. Therefore, you may use a UNIX-domain socket or an INET socket for the connection type. The suggested value for the
mailmunge.sockunder the spool directory if you are running Sendmail, or an INET socket on a convenient port if you are running Postfix. Postfix often runs in a chroot environment, so using UNIX-domain sockets is a problem if the socket is not in Postfix's chroot jail.
The format of connection is determined by the Sendmail Milter library, and is one of the following:
A local UNIX-domain socket.
The same thing as unix:/path/to/file
The same thing as unix:/path/to/file
Listen on the TCP port port over IPv4. If the @host portion is given, listen on the specified address. Normally, you should listen only on the localhost address and should specify a Milter TCP socket as inet:firstname.lastname@example.org.
Similar to inet:port[@host], but use an IPv6 socket.
Permits the multiplexor to queue new connections. See the section QUEUEING REQUESTS in the mailmunge-multiplexor man page. Note that this option and the
-Roption are mutually-exclusive. If you supply
mailmungeto perform a relay check before processing any messages. It causes the filter's
filter_relaymethod to be invoked. (See Mailmunge::Filter for details.)
mailmungeto perform a sender check before processing the message body. It causes the filter's
filter_sendermethod to be invoked. (See Mailmunge::Filter for details.)
mailmungeto perform recipient checks before processing the message body. It causes the filter's
filter_recipientmethod to be invoked. (See Mailmunge::Filter for details.)
- -x string
Add string as the content of the X-Scanned-By: header. If you set string to the empty string (i.e. -x ""), then no X-Scanned-By: header will be added.
-ycommand-line option is given, Mailmunge will call smfi_setsymlist to set the list of macros it wants. This function leaked memory in versions of Sendmail prior to 8.14.4 so by default we do not call it. If you are running an older version of sendmail, you should explicitly set the list of macros you want in the Sendmail configuration file.
- -z spooldir
Set the spool directory to spooldir. If this option is omitted, the spool directory defaults to /var/spool/mailmunge.
-m option takes a socket as an argument. This socket can be specified as:
A UNIX-domain socket
A TCP socket bound to port portnum, but that accepts connections only from the IPv4 loopback address (127.0.0.1).
A TCP socket bound to port portnum that will accept connections from any address. Use inet_any with caution!
A TCP socket bound to port portnum listening on the IPv6 loopback address.
A TCP socket bound to port portnum listening on the IPv6 wildcard address.
mailmunge starts, it creates a listening socket to which Sendmail or Postfix can connect; the MTA communicates with
mailmunge using the Milter protocol.
For each incoming message,
mailmunge creates a temporary directory and saves information in the directory. At various phases during the SMTP conversation,
mailmunge communicates with
mailmunge-multiplexor to perform various operations.
mailmunge-multiplexor manages a pool of persistent Perl processes that actually perform the mail scanning operations.
mailmunge then communicates the results of those operations back to the MTA over the milter socket.
When a Perl process scans an e-mail, the temporary spool directory contains certain files; details of the communication protocol between
mailmunge and the Perl script are in mailmunge-protocol.
mailmunge was written by Dianne Skoll <email@example.com>.
This code is licensed under the terms of the GNU General Public License, version 2.
Copyright © 2021 Skoll Software Consulting