maildir

Name

maildir -- E-mail directory

Synopsis

$HOME/Maildir

DESCRIPTION

A "Maildir" is a structured directory that holds E-mail messages. Maildirs were first implemented by the Qmail mail server. Qmail's maildirs were a simple data structure, nothing more than a single collection of E-mail messages. Courier builds upon Qmail's maildirs to provide extended functionality, such as folders and quotas. This document describes Courier's extended maildirs, without explicitly identify Courier-specific extensions. See maildir(5) in Qmail's documentation for the original definition of maildirs.

Traditionally, E-mail folders were saved as plain text files, called "mboxes". Mboxes have known limitations. Only one application can use an mbox at the same time. Locking is required in order to allow simultaneous concurrent access by different applications. Locking is often problematic, and not very reliable in network-based filesystem requirements. Some network-based filesystems don't offer any reliable locking mechanism at all. Furthermore, even bulletproof locking won't prevent occasional mbox corruption. A process can be killed or terminated in the middle of updating an mbox. This will likely result in corruption, and a loss of most messages in the mbox.

Maildirs allow multiple concurrent access by different applications. Maildirs do not require locking. Multiple applications can update a maildir at the same time, without stepping on each other's feet.

Maildir contents

A "maildir" is a directory that's created by maildirmake(1). Naturally, maildirs should not have any group or world permissions, unless you want other people to read your mail. A maildir contains three subdirectories: tmp, new, and cur. These three subdirectories comprise the primary folder, where new mail is delivered by the system.

Folders are additional subdirectories in the maildir whose names begin with a period: such as .Drafts or .Sent. Each folder itself contains the same three subdirectories, tmp, new, and cur, and an additional zero-length file named maildirfolder, whose purpose is to inform any mail delivery agent that it's really delivering to a folder, and that the mail delivery agent should look in the parent directory for any maildir-related information.

Folders are not physically nested. A folder subdirectory, such as .Sent does not itself contain any subfolders. The main maildir contains a single, flat list of subfolders. These folders are logically nested, and periods serve to separate folder hierarchies. For example, .Sent.2002 is considered to be a subfolder called "2002" which is a subfolder of "Sent".

Folder name encoding

Folder names can contain any Unicode character, except for control characters. US-ASCII characters, U+0x0020 - U+0x007F, except for the period, forward-slash, and ampersand characters (U+0x002E, U+0x002F, and U+0x0026) represent themselves. The ampersand is represent by the two character sequence "&-". The period, forward slash, and non US-ASCII Unicode characters are represented using the UTF-7 character set, and encoded with a modified form of base64-encoding.

The "&" character starts the md form o NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+ ">

maildropex

Name

maildropex -- maildrop filtering language examples

Synopsis

$HOME/.mailfilter, $HOME/.mailfilters/*

DESCRIPTION

If $HOME/.mailfilter exists, filtering instructions in this file will be carried out prior to delivering the message. The filtering instructions may instruct maildrop to discard the message, save the message in a different mailbox, or forward the message to another address. If $HOME/.mailfilter does not exist, or does not provide explicit delivery instructions, maildrop delivers the message to the user's system mailbox.

The files in $HOME/.mailfilters are used when maildrop is invoked in embedded mode.

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 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 command maintains a list of recently seen Message-IDs in the file duplicate.cache.

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< 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 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.

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" {
    current_time=time;
    if (gdbmopen("vacation.dat", "C") == 0)
    {
       if ( (prev_time=gdbmfetch($MATCH)) ne "" && \
             $prev_time >= $current_time - 60 * 60 * 24 * 7)
       {
           exit
       }
       gdbmstore($MATCH, $current_time)
       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

maildrop(1), maildropfilter(1), reformail(1), egrep(1), grep(1), sendmail(8).

./usr/share/doc/maildrop/html/maildir.html0000644000000000000000000004412110304144131020704 0ustar rootroot00000000000000 maildir

maildir

Name

maildir -- E-mail directory

Synopsis

$HOME/Maildir

DESCRIPTION

A "Maildir" is a structured directory that holds E-mail messages. Maildirs were first implemented by the Qmail mail server. Qmail's maildirs were a simple data structure, nothing more than a single collection of E-mail messages. Courier builds upon Qmail's maildirs to provide extended functionality, such as folders and quotas. This document describes Courier's extended maildirs, without explicitly identify Courier-specific extensions. See maildir(5) in Qmail's documentation for the original definition of maildirs.

Traditionally, E-mail folders were saved as plain text files, called "mboxes". Mboxes have known limitations. Only one application can use an mbox at the same time. Locking is required in order to allow simultaneous concurrent access by different applications. Locking is often problematic, and not very reliable in network-based filesystem requirements. Some network-ba