MAILDROP(1)
โจ MAILDROP(1) โจ
okay bestie, gather round, because today we're learning about maildrop โ it's a mail delivery filter/agent, and honestly? it's giving main character energy in your mail server's life. ๐
๐ธ SYNOPSIS ๐ธ
maildrop [option...] [-d user] [arg...]
maildrop [option...] [filename] [arg...]
๐ DESCRIPTION ๐
So like, maildrop is a replacement local mail delivery agent, and the way that it also comes with its own whole mail filtering language?? obsessed. You've got two ways your sysadmin can deploy it:
- they swap out your existing mail delivery agent for
maildrop, or - users just run
maildropthrough the old agent's 'forward to program' mechanism.
Either way, iconic. ๐
First things first: maildrop reads the E-mail message off standard input. Trailing carriage return characters? automatically stripped, no cap. And a quick anatomy lesson for you: an E-mail message is header lines, then a blank line, then the contents of the message. periodt.
โ ๏ธ Now here's the tea, and listen closely:maildropdoes not accept an mbox-styleFrom_line before the first header line. It also does not accept leading empty lines before the first non-blank header line. If your message could possibly start with empty lines and aFrom_line, usereformail -f0to strip any initial empty lines, and swap aFrom_line for a properReturn-Path:header โ then pipe it tomaildrop. Because otherwise it's just not gonna work, bestie. ๐ญ
If the file /etc/maildroprc exists, the mail delivery or mail filtering instructions get read from that file. And those instructions can tell maildrop to save the message in a specific mailbox, discard it, return it to sender, or forward it to a different E-mail address. So many choices, so much power. ๐
But if /etc/maildroprc doesn't exist, or its delivery instructions don't completely dispose of the message? Then maildrop moves on and reads the delivery instructions from $HOME/.mailfilter. And if that doesn't exist either, or its instructions still don't completely dispose of the message, maildrop just saves the E-mail in the default mailbox. Simple as that. โจ
maildrop knows how to deliver mail to standard mailbox files, and it also knows how to deliver to maildirs. Quick vocab check: a maildir is a directory-based mail format used by the Courier[1] and Qmail mail servers, and loads of other mail servers know how to read maildirs too. And when it's delivering to mailbox files, maildrop will lock the mailbox for the duration of the delivery. Safety first, always. ๐
That's the general mail delivery behavior. There are minor differences depending on maildrop's delivery mode, which gets determined by how maildrop was started. And there are three different primary operating modes:
๐ Manual mode
A file containing filtering instructions โ filename โ is specified as an argument to the maildrop command. maildrop reads this filename and follows the instructions in it. And unless the message is explicitly forwarded, bounced, deleted, or delivered to a specific mailbox, it will be delivered to the user's system mailbox. ๐
๐ Delivery mode
Here maildrop is the mail server's mail delivery agent. maildrop runs in delivery mode when no filename is specified on the command line. It changes the current directory to the user's home directory, then reads /etc/maildroprc, then $HOME/.mailfilter. Order matters, bestie. ๐
๐ Embedded mode
And now for the fancy one: maildrop functions as a part of another application. Embedded mode is used by the Courier[1] mail server to integrate mail filtering directly into the process of receiving mail from a remote mail relay โ which means it can reject unwanted mail before it is even accepted for local mail delivery. Rude to spammers, kind to you. ๐
Embedded mode is used when either the -m or the -M option is specified, and it's described below. (There's a more extensive description of embedded mode further down too โ see below, iykyk.)
๐ SECURITY ๐
Okay so, is it safe to install maildrop as a root setuid program? Yes. ๐ The Courier mail server[1] installs maildrop as a root setuid program by default, specifically so it can use maildrop in embedded mode. If root runs maildrop (or it's setuided to root), the -d option may be used to specify the message's recipient. And the moment that happens, maildrop immediately resets its userid to the one specified by the -d option. Then the user's $HOME/.mailfilter is read (if it exists), and the message is delivered to the indicated user. Clean. โจ
Your system administrator can also configure maildrop to restrict the -d option for everyone except the mail system itself. Gatekeeping, but make it security. ๐
โ ๏ธ Now for the warnings, and these are real ones, so pay attention:
- If, in delivery mode, the user's home directory has the sticky bit set,
maildropimmediately terminates with an exit code ofEX_TEMPFAIL, without doing anything. Mail servers interpret theEX_TEMPFAILexit code as a request to reschedule the message for another delivery attempt later. Setting the sticky bit lets$HOME/.mailfilterbe edited while temporarily holding all incoming mail. Cute trick, actually. ๐ maildropalso terminates withEX_TEMPFAILif the user's home directory has world write permissions. Nope, absolutely not. ๐maildropimmediately terminates withEX_TEMPFAILif thefilenameis not owned by the user, or if it has any group or world permissions โ and yes, that includes read permissions. The permissions on$HOME/.mailfiltermay only include read and write privileges to the user. Nothing else. ๐- When using the special embedded mode (see below),
maildropimmediately terminates with the exit code set toEX_TEMPFAILif$HOME/.mailfiltersis not owned by the user, or if it has any group or world permissions. Same energy, different file. ๐ซ
๐ง TEMPORARY FILES ๐ง
maildrop is heavily optimized and tries to use as little resources as possible, because it's an efficient queen. ๐
- Small messages?
maildropreads them straight into memory, then filters and/or delivers the message directly from memory. ๐ง โจ - Larger messages?
maildropaccesses the message directly from the file. - Standard input not a file? Then
maildropwrites the message to a temporary file, and accesses the message from that temporary file instead. That temporary file is automatically removed when the message is delivered. Cleanup slay. ๐
โจ OPTIONS โจ
okay bestie, here's the whole menu of flags, and yes, we're going through every single one ๐
-aโ makes using the Courier Authentication Library mandatory, like fr fr required. If the call to the authlib mechanism fails for literally any reason โ sayauthdaemonis inaccessible โmaildropthrows a temporary error code. ๐
Note: this might already be the default depending on how maildrop was configured on your system. So check before you @ me.
-A "Header: value"โ adds an extra header to the message. Writing-A "Foo: Bar"effectively adds that header to the message being delivered. โจ
So here's the tea: the mail transport agent usually adds extra headers when it delivers a message to a local mailbox. The usual way this goes down is the MTA pipes the message to the local delivery agent โ like maildrop โ and tacks on some extra headers in the process. And because maildrop gets the message through a pipe, it has to either hold the whole message in memory or write it out to a temporary file. ๐ญ
The -A option lets the file containing the message be handed to maildrop directly as standard input instead, with the extra headers specified on the command line. And because standard input is a file, maildrop doesn't need a temporary file at all. Iconic. Multiple -A options may be specified. ๐
-d userโ runsmaildropin delivery mode for this user ID.
Your system administrator may optionally restrict the -d option so only the mail system can use it, meaning it might not be available to you. But in all cases, -d is allowed if user is the same user who's running maildrop. Also, for -d to work at all, maildrop must be executed by root, or maildrop must be a root-owned program with the setuid bit set. And if there's no filename on maildrop's command line, that implies the -d option for the user running maildrop.
If -d is not specified, the first argument following all the options is the name of the file containing filtering instructions. Any remaining arguments get assigned to the variables $1, $2, and so on (see "Environment" and "Variable substitution").
-f addressโ sets theFROMvariable (the message envelope sender) to address. Your system administrator may optionally disable the-foption for users, so ngl this one might not be available to you either. ๐ซถ-mโ runsmaildropin embedded mode. You can use both-mand-dtogether, but it really doesn't make much sense. Even if you genuinely wanted to run your message through somebody else's.mailfilter, that.mailfilterprobably has at least one instruction that isn't allowed in embedded mode. ๐
The filename argument to maildrop should be specified. filename is a file that includes filtering instructions to be processed in embedded mode. The -m option is used for debugging filter files that later get placed in $HOME/.mailfilters and used with the -M option.
-M filterfileโ runsmaildropin a special embedded mode. The-doption is implied when-Mis used, and if it's absent it defaults to the userid runningmaildrop.
All the requirements for the -d option apply. maildrop must either be executed by root, or the maildrop program must be owned by root with the setuid bit set. maildrop immediately gives up root privileges by changing its user ID to the one specified by -d, then reads $HOME/.mailfilters/filterfile. For security reasons the name of the file may not begin with a slash or include periods. And maildrop is very paranoid: both $HOME/.mailfilters and $HOME/.mailfilters/filterfile must be owned by the user, and may not have any group or world permissions. ๐จ
The -M option allows for some friendly cooperation between the user running the application and the user who provides a filter for the embedded mode. The user running the application can use someone else's canned filter and be assured that the filter is not going to run amok and start sending mail or create files all over the place. And the user who provides the filter can be assured that the environment variables are clean and that there are no surprises. mutual trust, we love to see it ๐ซถ
maildrop also supports the concept of "default" filter files. If the file specified by the -M option can't be found in $HOME/.mailfilters, maildrop will try to open $HOME/.mailfilters/filterfileprefix-default. Here filterfileprefix is the initial part of filterfile up until the last - character in filterfile.
If $HOME/.mailfilters/filterfileprefix-default doesn't exist, and there are any other dashes left in filterfileprefix, maildrop removes the last dash and everything following it, then tries again.
And as a last resort, maildrop tries to open $HOME/.mailfilters/default. ๐
For example, if the parameter to the -M option is mailfilter-lists-maildrop, maildrop will try to open the following files, in order:
Note:maildroplooks for-defaultfiles ONLY if-Mis used. iykyk ๐
-D uuu/gggโ this option is reserved for use by the version ofmaildropthat comes integrated with the Courier mail server. Not for us, bestie, it's for the Courier girlies. ๐-V levelโ initializes theVERBOSEvariable to level. Becausemaildropparses the entire file before running it, this option is what produces debugging output during the parsing phase. Otherwise, if filename has syntax errors, no debugging output is possible at all, because theVERBOSEvariable isn't set yet. ๐ญ
Pro tip: -V is ignored when maildrop runs in delivery mode.
-w Nโ the-w Noption places a warning message into the maildir if the maildir has a quota setting, and after the message was successfully delivered the maildir was at least N percent full. heads up vibes ๐ธ-W filenameโ copies the warning message from filename, or from/etc/quotawarnmsgif this option isn't specified, with the addition of the"Date:"and"Message-Id:"headers. The warning gets repeated every 24 hours (at least), until the maildir drops below N percent full. โฐ-t socketโ this option is available ifmaildropis compiled with optional Dovecot authentication support. socket specifies the location of the Dovecot master authentication socket, for example/var/run/dovecot/auth-master.
๐ DELIVERY MODE ๐
If a filename isn't specified on the command line, or if the -d option is used, maildrop runs in delivery mode. In delivery mode, maildrop changes to the home directory of the user specified by the -d option (or the user who's running maildrop if -d wasn't given) and reads $HOME/.mailfilter for filtering instructions. $HOME/.mailfilter must be owned by the user and have no group or global permissions โ and bestie, maildrop terminates if it does. no cap. ๐
If $HOME/.mailfilter doesn't exist, maildrop will simply deliver the message to the user's mailbox. easy peasy โจ
And if the file /etc/maildroprc exists, maildrop reads filtering instructions from that file first, before reading $HOME/.mailfilter. This is how the system administrator provides global filtering instructions for all users. ๐
Note: /etc/maildroprc is read only in delivery mode.
๐ฅ VIRTUAL ACCOUNTS ๐ฅ
The -d option can also specify a name of a virtual account or mailbox. Check the makeuserdb(1) manual page in the Courier Authentication library's documentation for more info. ๐
๐ง EMBEDDED MODE ๐ง
Embedded mode is what you use when you want maildrop's filtering abilities but no actual mail delivery is needed. In embedded mode, maildrop is executed by another application and is passed the -m or the -M option. maildrop reads the message, then runs the filtering rules specified in filename.
filename may contain any filtering instructions EXCEPT the following, bestie โ these are the forbidden ones:
` ... `โ text strings delimited by back-tick characters (run shell command) are not allowed.ccโ thecccommand is not allowed in embedded mode.dotlockโ thedotlockcommand is not allowed in embedded mode.flockโ theflockcommand is not allowed in embedded mode.gdbmopenโ in embedded mode, GDBM databases may be opened only for reading.logโ thelogcommand is not allowed in embedded mode.logfileโ thelogfilecommand is not allowed in embedded mode.systemโ thesystemcommand is not allowed in embedded mode.toโ thetocommand is not allowed in embedded mode.xfilterโ thexfiltercommand is not allowed in embedded mode.
Normally, when filename doesn't explicitly deliver a message, maildrop will deliver the message to the user's default mailbox. That's also disabled in embedded mode. ๐
โ๏ธ
The filename may communicate with the parent application by using the echo statement and the EXITCODE environment variable. cute lil handshake ๐ซถ
๐ธ /etc/maildroprcs ๐ธ
If maildrop encounters an include statement where the filename starts with /etc/maildroprcs/, the normal restrictions for embedded mode are suspended while executing the filter file in the /etc/maildroprcs directory. The restrictions are also suspended for any additional filter files that are included from /etc/maildroprcs. Then the restrictions resume once maildrop finishes executing the file from /etc/maildroprcs. ๐
This lets the system administrator have a controlled environment for running external commands (via the backticks, the system or the xfilter commands).
The name of the file may not contain any periods โ this is so a creative individual can't write include "/etc/maildroprcs/../../home/user/recipe". ๐
nice try though
Before executing the commands in the /etc/maildroprcs file, maildrop automatically resets the following variables to their initial values: DEFAULT, HOME, LOCKEXT, LOCKSLEEP, LOCKTIMEOUT, LOCKREFRESH, LOGNAME, PATH, SENDMAIL, and SHELL. And please note: the previous values of these variables (if they were changed) will NOT be restored once maildrop finishes executing the commands from /etc/maildroprcs. ๐จ
โฑ๏ธ WATCHDOG TIMER โฑ๏ธ
maildrop has a watchdog timer that attempts to abort runaway filtering. If filtering isn't complete within a predefined time interval (defined by the system administrator, usually five minutes), maildrop terminates. so dramatic. love that for it. ๐
๐ FILES ๐
/etc/passwdโ sets the user's home directory and related variables. If NIS/YP is installed, that will be used as well./etc/maildroprcโ global filtering instructions for delivery mode./var/mailโ system mailbox (the actual directory is defined by the system administrator)./usr/sbin/sendmailโ program to forward mail (the exact program is defined by the system administrator).$HOME/.mailfilterโ filtering instructions in delivery mode.$HOME/.mailfiltersโ directory containing files used in special embedded mode.
โจ SEE ALSO โจ
okay bestie, here's the whole friend group, no cap ๐ โ go read these when you're done slaying with this page:
lockmail(1)<sup>[15]</sup>maildropfilter(7)<sup>[16]</sup>makedat(1)<sup>[17]</sup>maildropgdbm(7)<sup>[8]</sup>maildropex(7)<sup>[18]</sup>reformail(1)<sup>[19]</sup>makemime(1)<sup>[20]</sup>reformime(1)<sup>[21]</sup>egrep(1)grep(1)- (yes, there's a lil stray empty one right there in the original, she's iconic, we stan her) ,
courier(8)<sup>[22]</sup> sendmail(8)
๐ AUTHOR ๐
- Sam Varshavchik โ Author
like, actual legend behavior fr fr ๐ซถ
๐ธ NOTES ๐ธ
the footnotes!! everything below is the exact tea, one numbered receipt at a time โจ
- Courier โ https://www.courier-mta.org
- "Environment" โ http://www.courier-mta.org/maildrop/maildropfilter.html#environment
- "Variable substitution" โ http://www.courier-mta.org/maildrop/maildropfilter.html#varsubst
is passed the โm or the โM option.โ http://www.courier-mta.org/maildrop/#options- cc โ http://www.courier-mta.org/maildrop/maildropfilter.html#cc
- dotlock โ http://www.courier-mta.org/maildrop/maildropfilter.html#dotlock
- flock โ http://www.courier-mta.org/maildrop/maildropfilter.html#flock
- gdbmopen โ http://www.courier-mta.org/maildrop/maildropgdbm.html
- log โ http://www.courier-mta.org/maildrop/maildropfilter.html#log
- system โ http://www.courier-mta.org/maildrop/maildropfilter.html#system
- to โ http://www.courier-mta.org/maildrop/maildropfilter.html#to
- xfilter โ http://www.courier-mta.org/maildrop/maildropfilter.html#xfilter
- echo โ http://www.courier-mta.org/maildrop/maildropfilter.html#echo
- include โ http://www.courier-mta.org/maildrop/maildropfilter.html#include
lockmail(1)โ http://www.courier-mta.org/maildrop/lockmail.htmlmaildropfilter(7)โ http://www.courier-mta.org/maildrop/maildropfilter.htmlmakedat(1)โ http://www.courier-mta.org/maildrop/makedat.htmlmaildropex(7)โ http://www.courier-mta.org/maildrop/maildropex.htmlreformail(1)โ http://www.courier-mta.org/maildrop/reformail.htmlmakemime(1)โ http://www.courier-mta.org/maildrop/makemime.htmlreformime(1)โ http://www.courier-mta.org/maildrop/reformime.htmlcourier(8)โ http://www.courier-mta.org/maildrop/courier.html
and that's the whole page bestie, you read all three parts, that's main character energy ๐ go filter some mail, you absolute icon ๐ญ๐
this lil manual is brought to you by Courier Mail Server, dated 01/10/2026, and it's the MAILDROP(1) page โ periodt โจ๐๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: maildrop 4.0.4-1 ยท GPL-3~with-OpenSSL-exception
- Copyright 1998 - 2009 S. Varshavchik. See COPYING for -->
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms