{
    "mode": "man",
    "parameter": "MAILDROPEX",
    "section": "7",
    "url": "https://www.chedong.com/phpMan.php/man/MAILDROPEX/7/json",
    "generated": "2026-06-15T14:37:50Z",
    "synopsis": "$HOME/.mailfilter, $HOME/.mailfilters/*",
    "sections": {
        "NAME": {
            "content": "maildropex - maildrop filtering language examples\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "$HOME/.mailfilter, $HOME/.mailfilters/*\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "If $HOME/.mailfilter exists, filtering instructions in this file will be carried out prior to\ndelivering the message. The filtering instructions may instruct maildrop to discard the\nmessage, save the message in a different mailbox, or forward the message to another address.\nIf $HOME/.mailfilter does not exist, or does not provide explicit delivery instructions,\nmaildrop delivers the message to the user's system mailbox.\n\nThe files in $HOME/.mailfilters are used when maildrop is invoked in embedded mode.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Take all mail that's sent to the 'auto' mailing list, and save it in Mail/auto. The 'auto'\nmailing list software adds a \"Delivered-To: auto@domain.com\" header to all messages:\n\nif (/^Delivered-To: *auto@domain\\.com$/)\nto Mail/auto\n\nAfter the to command delivers the message, maildrop automatically stops filtering and\nterminates without executing the subsequent instructions in the filter file.\n\nTake all mail from <boss@domain.com> about the current project status, save it in\nMail/project, then forward a copy to John:\n\nif (/^From: *boss@domain\\.com/ \\\n&& /^Subject:.*[:wbreak:]project status[:wbreak:]/)\n{\ncc \"!john\"\nto Mail/project\n}\n\nNote that it is necessary to use a backslash in order to continue the if statement on the\nnext line.\n\nKeep copies of the last 50 messages that you received in the maildir directory 'backup'.\nNOTE: 'backup' must be a maildir directory, not a mailbox. You can create a maildir using the\nmaildirmake command.\n\ncc backup\n`cd backup/new && rm -f dummy \\`ls -t | sed -e 1,50d\\``\n\nPut this at the beginning of your filter file, before any other filtering instructions. This\nis a good idea to have when you are learning maildrop. If you make a mistake and accidentally\ndelete a message, you can recover it from the backup/new subdirectory.\n\nSave messages that are at least 100 lines long (approximately) into Mail/IN.Large::\n\nif ( $LINES > 100 )\nto Mail/IN.Large\n\nSend messages from the auto mailing list to the program 'archive', using a lock file to make\nsure that only one instance of the archive program will be running at the same time:\n\nif (/^Delivered-To: *auto@domain\\.com$/)\ndotlock \"auto.lock\" {\n\nto \"|archive\"\n}\n\nCheck if the Message-ID: header in the message is identical to the same header that was\nrecently seen. Discard the message if it is, otherwise continue to filter the message:\n\n`reformail -D 8000 duplicate.cache`\nif ( $RETURNCODE == 0 )\nexit\n\nThe reformail[1] command maintains a list of recently seen Message-IDs in the file\nduplicate.cache.\n\nNote\nUnlike a similar feature in the formail command, reformail[1] takes care of locking the\nfile, so it's not necessary to implement your own locking mechanism for this option.\n\nHere's a more complicated example. This fragment is intended to go right after the message\nhas been filtered according to your regular rules, and just before the message should be\nsaved in your mailbox:\n\ncc $DEFAULT\nxfilter \"reformail -r -t\"\n/^To:.*/\ngetaddr($MATCH) =~ /^.*/;\n\nMATCH=tolower($MATCH)\nflock \"vacation.lock\" {\n`fgrep -iqx \"$MATCH\" vacation.lst 2>/dev/null || { \\\necho \"$MATCH\" >>vacation.lst ; \\\nexit 1 ; \\\n} `\n}\nif ( $RETURNCODE == 0 )\nexit\nto \"| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL\"\n\nThis code maintains a list of everyone who sent you mail in the file called vacation.lst.\nWhen a message is received from anyone that is not already on the list, the address is added\nto the list, and the contents of the file vacation.msg are mailed back to the sender. This is\nintended to reply notify people that you will not be answering mail for a short period of\ntime.\n\nThe first statement saves the original message in your regular mailbox. Then, xfilter[2] is\nused to generate an autoreply header to the sender. The To: header in the autoreply - which\nwas the sender of the original message - is extracted, and the getaddr[3] function is used to\nstrip the person's name, leaving the address only. The file vacation.lst is checked, using a\nlock file to guarantee atomic access and update (overkill, probably). Note that the\nbackslashes are required.\n\nIf the address is already in the file, maildrop exits, otherwise the contents of vacation.msg\nare appended to the autoreply header, and mailed out.\n\nNote\nAn easier to make a vacation script is with mailbot(1)[4].\n\nHere's a version of the vacation script that uses a GDBM database file instead. The\ndifference between this script and the previous script is that the previous script will send\na vacation message to a given E-mail address only once. The following script will store the\ntime that the vacation message was sent in the GDBM file. If it's been at least a week since\nthe vacation message has been sent to the given address, another vacation message will be\nsent.\n\nEven though a GDBM database file is used, locking is still necessary because the GDBM library\ndoes not allow more than one process to open the same database file for writing:\n\ncc $DEFAULT\nxfilter \"reformail -r -t\"\n/^To:.*/\ngetaddr($MATCH) =~ /^.*/;\nMATCH=tolower($MATCH)\nflock \"vacation.lock\" {\ncurrenttime=time;\nif (gdbmopen(\"vacation.dat\", \"C\") == 0)\n{\nif ( (prevtime=gdbmfetch($MATCH)) ne \"\" && \\\n$prevtime >= $currenttime - 60 * 60 * 24 * 7)\n{\nexit\n}\ngdbmstore($MATCH, $currenttime)\ngdbmclose\n}\n}\nto \"| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL\"\n\nThis script requires that maildrop must be compiled with GDBM support enabled, which is done\nby default if GDBM libraries are present.\n\nAfter you return from vacation, you can use a simple Perl script to obtain a list of everyone\nwho sent you mail (of course, that can also be determined by examining your mailbox).\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "maildrop(1)[5], maildropfilter(7)[6], reformail(1)[1], mailbot(1)[4], egrep(1), grep(1),\nsendmail(8).\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "",
            "subsections": [
                {
                    "name": "Sam Varshavchik",
                    "content": "Author\n"
                }
            ]
        },
        "NOTES": {
            "content": "1. reformail\nhttp://www.courier-mta.org/maildrop/reformail.html\n\n2. xfilter\nhttp://www.courier-mta.org/maildrop/maildropfilter.html#xfilter\n\n3. getaddr\nhttp://www.courier-mta.org/maildrop/maildropfilter.html#getaddr\n\n4. mailbot(1)\nhttp://www.courier-mta.org/maildrop/mailbot.html\n\n5. maildrop(1)\nhttp://www.courier-mta.org/maildrop/maildrop.html\n\n6. maildropfilter(7)\nhttp://www.courier-mta.org/maildrop/maildropfilter.html\n\n\n\nCourier Mail Server                          06/20/2015                                MAILDROPEX(7)",
            "subsections": []
        }
    },
    "summary": "maildropex - maildrop filtering language examples",
    "flags": [],
    "examples": [
        "Take all mail that's sent to the 'auto' mailing list, and save it in Mail/auto. The 'auto'",
        "mailing list software adds a \"Delivered-To: auto@domain.com\" header to all messages:",
        "if (/^Delivered-To: *auto@domain\\.com$/)",
        "to Mail/auto",
        "After the to command delivers the message, maildrop automatically stops filtering and",
        "terminates without executing the subsequent instructions in the filter file.",
        "Take all mail from <boss@domain.com> about the current project status, save it in",
        "Mail/project, then forward a copy to John:",
        "if (/^From: *boss@domain\\.com/ \\",
        "&& /^Subject:.*[:wbreak:]project status[:wbreak:]/)",
        "cc \"!john\"",
        "to Mail/project",
        "Note that it is necessary to use a backslash in order to continue the if statement on the",
        "next line.",
        "Keep copies of the last 50 messages that you received in the maildir directory 'backup'.",
        "NOTE: 'backup' must be a maildir directory, not a mailbox. You can create a maildir using the",
        "maildirmake command.",
        "cc backup",
        "`cd backup/new && rm -f dummy \\`ls -t | sed -e 1,50d\\``",
        "Put this at the beginning of your filter file, before any other filtering instructions. This",
        "is a good idea to have when you are learning maildrop. If you make a mistake and accidentally",
        "delete a message, you can recover it from the backup/new subdirectory.",
        "Save messages that are at least 100 lines long (approximately) into Mail/IN.Large::",
        "if ( $LINES > 100 )",
        "to Mail/IN.Large",
        "Send messages from the auto mailing list to the program 'archive', using a lock file to make",
        "sure that only one instance of the archive program will be running at the same time:",
        "if (/^Delivered-To: *auto@domain\\.com$/)",
        "dotlock \"auto.lock\" {",
        "to \"|archive\"",
        "Check if the Message-ID: header in the message is identical to the same header that was",
        "recently seen. Discard the message if it is, otherwise continue to filter the message:",
        "`reformail -D 8000 duplicate.cache`",
        "if ( $RETURNCODE == 0 )",
        "exit",
        "The reformail[1] command maintains a list of recently seen Message-IDs in the file",
        "duplicate.cache.",
        "Note",
        "Unlike a similar feature in the formail command, reformail[1] takes care of locking the",
        "file, so it's not necessary to implement your own locking mechanism for this option.",
        "Here's a more complicated example. This fragment is intended to go right after the message",
        "has been filtered according to your regular rules, and just before the message should be",
        "saved in your mailbox:",
        "cc $DEFAULT",
        "xfilter \"reformail -r -t\"",
        "/^To:.*/",
        "getaddr($MATCH) =~ /^.*/;",
        "MATCH=tolower($MATCH)",
        "flock \"vacation.lock\" {",
        "`fgrep -iqx \"$MATCH\" vacation.lst 2>/dev/null || { \\",
        "echo \"$MATCH\" >>vacation.lst ; \\",
        "exit 1 ; \\",
        "} `",
        "if ( $RETURNCODE == 0 )",
        "exit",
        "to \"| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL\"",
        "This code maintains a list of everyone who sent you mail in the file called vacation.lst.",
        "When a message is received from anyone that is not already on the list, the address is added",
        "to the list, and the contents of the file vacation.msg are mailed back to the sender. This is",
        "intended to reply notify people that you will not be answering mail for a short period of",
        "time.",
        "The first statement saves the original message in your regular mailbox. Then, xfilter[2] is",
        "used to generate an autoreply header to the sender. The To: header in the autoreply - which",
        "was the sender of the original message - is extracted, and the getaddr[3] function is used to",
        "strip the person's name, leaving the address only. The file vacation.lst is checked, using a",
        "lock file to guarantee atomic access and update (overkill, probably). Note that the",
        "backslashes are required.",
        "If the address is already in the file, maildrop exits, otherwise the contents of vacation.msg",
        "are appended to the autoreply header, and mailed out.",
        "Note",
        "An easier to make a vacation script is with mailbot(1)[4].",
        "Here's a version of the vacation script that uses a GDBM database file instead. The",
        "difference between this script and the previous script is that the previous script will send",
        "a vacation message to a given E-mail address only once. The following script will store the",
        "time that the vacation message was sent in the GDBM file. If it's been at least a week since",
        "the vacation message has been sent to the given address, another vacation message will be",
        "sent.",
        "Even though a GDBM database file is used, locking is still necessary because the GDBM library",
        "does not allow more than one process to open the same database file for writing:",
        "cc $DEFAULT",
        "xfilter \"reformail -r -t\"",
        "/^To:.*/",
        "getaddr($MATCH) =~ /^.*/;",
        "MATCH=tolower($MATCH)",
        "flock \"vacation.lock\" {",
        "currenttime=time;",
        "if (gdbmopen(\"vacation.dat\", \"C\") == 0)",
        "if ( (prevtime=gdbmfetch($MATCH)) ne \"\" && \\",
        "$prevtime >= $currenttime - 60 * 60 * 24 * 7)",
        "exit",
        "gdbmstore($MATCH, $currenttime)",
        "gdbmclose",
        "to \"| ( cat - ; echo ''; cat vacation.msg) | $SENDMAIL\"",
        "This script requires that maildrop must be compiled with GDBM support enabled, which is done",
        "by default if GDBM libraries are present.",
        "After you return from vacation, you can use a simple Perl script to obtain a list of everyone",
        "who sent you mail (of course, that can also be determined by examining your mailbox)."
    ],
    "see_also": [
        {
            "name": "maildrop",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/maildrop/1/json"
        },
        {
            "name": "maildropfilter",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/maildropfilter/7/json"
        },
        {
            "name": "reformail",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/reformail/1/json"
        },
        {
            "name": "mailbot",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/mailbot/1/json"
        },
        {
            "name": "egrep",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/egrep/1/json"
        },
        {
            "name": "grep",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/grep/1/json"
        },
        {
            "name": "sendmail",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/sendmail/8/json"
        }
    ]
}