MAILMUNGE(8)
π MAILMUNGE(8) β aka mailmunge(8), and we're making it make sense π
User Contributed Perl Documentation realness, bestie. This is the MAILMUNGE(8) page, and it's giving "the boss behind the scenes" energy. Let's get into it.
πΈ NAME πΈ
mailmunge β Milter for writing mail policy in Perl
π SYNOPSIS π
okay so the two shapes this command takes are literally:
mailmunge prcap
mailmunge -p connection -m mx_socket_name -U user [options]
That's the vibe check. prcap is its own little solo era; the second line is the main-character invocation.
π DESCRIPTION π
So 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. Perl girlies rise π
But plot twist: 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. That's the whole "I don't do the work, I know the people who do" situation.
β¨ OPTIONS β¨
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. Yes bestie, that line matters.
-Cβ 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.-Dβ 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 assystemdmanagingmailmunge.-Gβ normally,mailmungeuses a umask of077when 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 be007whenever UNIX-domain sockets are created and027whenever files are created. Note: if your milter library is too old to have thesmfi_opensocketfunction, the-Goption causesmailmungeto use a umask of007throughout its execution.-Hβ causesmailmungeto perform a HELO check when the SMTP client issues a HELO or EHLO command. It causes the filter'sfilter_helomethod to be invoked. (SeeMailmunge::Filterfor details.)-Nβ normally,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, invokemailmungewith the-Nflag. Please note that this flag only works with Sendmail and Milter8.14.0and newer. It has no effect if you're running an older version of Sendmail or Milter.-PfileName β causesmailmungeto write its process-ID (after becoming a daemon) to the specified file. The file will be owned by root.-Qnum β sets the libmilter debug level usingsmfi_setdbg. Useful values of num are0(no debugging) through6(extensive debugging.) The libmilter log lines will be prefixed bymilter-mailmunge-3.20.-Rnum β normally,mailmungetempfails a new SMTP connection if there are no free workers. Supplying the-Rnum option makesmailmungetempfail 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-qoption.)
The purpose of the -R option 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 -q option are mutually-exclusive. If you supply -q, then -R is ignored.
-Sfacility β specifies the syslog facility for log messages. The default is mail. See theopenlogman page for a list of valid facilities. You can use either the short name (mail) or long name (LOG_MAIL) for the facility name.-Tβ causesmailmungeto log the run-time of the Perl filter using syslog.-Uuser β runsmailmungeas user rather than root. The user argument must match the argument tomailmunge-multiplexor's-Uoption as well.-Xβ do not add anX-Scanned-By:header. Specifying-Xis equivalent to specifying-x "".-amacro β pass the value of the specified Sendmail macro through to the Perl filter. You can repeat the-aoption to write more macros than the built-in defaults. Note that in addition to askingmailmungeto pass the macro value to the filter, you must configure Sendmail to pass the macro through tomailmungeusing theconfMILTER_MACROS_ENVFROMdefinition in Sendmail's m4 configuration file.-bbacklog β sets thebacklogargument to thelistensystem call to backlog. If this option is omitted, then the operating-system default backlog is used.-cβ strip "bare" carriage-returns (CR) characters from the message body. A bare CR should never appear in an e-mail message. Older versions ofmailmungeused to strip them out automatically, but now they are left in by default. The-coption enables the older behavior.-dβ the-dswitch causesmailmungenot 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.-hβ print usage information and exit.-kβ causesmailmungenot 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.-mmx_socket_name β specifies the socket for communicating withmailmunge-multiplexor. The mx_socket_name specifies the path of the UNIX-domain socket. Seemailmunge-multiplexorfor details andSOCKET SPECIFICATIONfor the format of mx_socket_name.-ofileName β causesmailmungeto use fileName as a lock file to avoid multiple instances from running. If you supply-Pbut not-o, thenmailmungeconstructs a lock file by appending.lockto 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-Uuser.)-pconnection β the-pswitch is required and specifies the milter connection type. Typically, you should runmailmungeon the same computer assendmail. Therefore, you may use a UNIX-domain socket or an INET socket for the connection type. The suggested value for the-pswitch ismailmunge.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:
unix:/path/to/fileβ a local UNIX-domain socket.local:/path/to/fileβ the same thing asunix:/path/to/file./path/to/fileβ the same thing asunix:/path/to/file.inet:port[@host]β listen on the TCP port port over IPv4. If the@hostportion is given, listen on the specified address. Normally, you should listen only on the localhost address and should specify a Milter TCP socket asinet:port@127.0.0.1.inet6:port[@host]β similar toinet:port[@host], but use an IPv6 socket.
-qβ permits the multiplexor to queue new connections. See the sectionQUEUEING REQUESTSin themailmunge-multiplexorman page. Note that this option and the-Roption are mutually-exclusive. If you supply-q, then-Ris ignored.-rβ causesmailmungeto perform a relay check before processing any messages. It causes the filter'sfilter_relaymethod to be invoked. (SeeMailmunge::Filterfor details.)-sβ causesmailmungeto perform a sender check before processing the message body. It causes the filter'sfilter_sendermethod to be invoked. (SeeMailmunge::Filterfor details.)-tβ causesmailmungeto perform recipient checks before processing the message body. It causes the filter'sfilter_recipientmethod to be invoked. (SeeMailmunge::Filterfor details.)-xstring β add string as the content of theX-Scanned-By:header. If you set string to the empty string (i.e.-x ""), then noX-Scanned-By:header will be added.-yβ if the-ycommand-line option is given, Mailmunge will callsmfi_setsymlistto set the list of macros it wants. This function leaked memory in versions of libmilter shipped with Sendmail prior to8.16.1so 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.-zspooldir β set the spool directory to spooldir. If this option is omitted, the spool directory defaults to/var/spool/mailmunge.
π SOCKET SPECIFICATION π
The -m option takes a socket as an argument. This socket can be specified as:
/path/to/socketβ a UNIX-domain socket.inet:portnumβ a TCP socket bound to port portnum, but that accepts connections only from the IPv4 loopback address (127.0.0.1).inet_any:portnumβ a TCP socket bound to port portnum that will accept connections from any address. Useinet_anywith caution!inet6:portnumβ a TCP socket bound to port portnum listening on the IPv6 loopback address.inet6_any:portnumβ a TCP socket bound to port portnum listening on the IPv6 wildcard address.
π OPERATION π
okay so here's the whole pipeline, bestie, and honestly it's giving elegant πβ¨
When mailmunge starts up, it creates a listening socket β and this is the socket that Sendmail or Postfix connects to. The MTA talks to mailmunge using the Milter protocol. That's the whole handshake situation. π«Ά
For each incoming message, mailmunge creates a temporary directory and saves information in that directory. Like, per-message temp dir, no sharing, no chaos. π
Then, at various phases during the SMTP conversation, mailmunge communicates with mailmunge-multiplexor to perform various operations. So mailmunge is basically the go-between β it's not doing the scanning itself, it's coordinating. icon behavior, fr fr π
And mailmunge-multiplexor? It manages a pool of persistent Perl processes that actually perform the mail scanning operations. Persistent = they stick around, they don't get reincarnated for every single email, which is lowkey the whole reason this design slaps π₯
After all that, mailmunge communicates the results of those operations back to the MTA over the milter socket. Full circle. The MTA asked, the MTA received. periodt π
One more thing β when a Perl process scans an e-mail, the temporary spool directory contains certain files. The details of the communication protocol between mailmunge and the Perl script? Those live in mailmunge-protocol. Go read it, iykyk πβ¨
π SEE ALSO π
Mailmungemailmunge-multiplexormailmunge-protocol
the whole squad, all linked up, all iconic π
β¨ AUTHOR β¨
mailmunge was written by Dianne Skoll <dianne@skollsoft.com>. absolute legend behavior, we stan ππ
πΈ LICENSE πΈ
This code is licensed under the terms of the GNU General Public License, version 2. That's the legal tea, bestie β β GPLv2, no cap π
and that's the page!! π¦ this one came from perl v5.42.2, dated 2025-10-05 β like, that's the version and the date of the doc itself, cute right? take care of your mail server and it'll take care of you πβ¨ mwah! π
π¦ where this page comes from
- alpine 3.24: mailmunge-doc 3.20-r0 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms