maildirmake [ options ] maildir
The maildirmake
command is used to create Maildirs, and
Maildir folders. This maildirmake
command also creates several
extensions to the base Maildir format.
A Maildir is a directory that's used to store mail messages. Not just any
directory will do - a Maildir must be of a specific structure, and have
specific access permissions. The maildirmake
command is a
convenient way to create a new Maildir, or a new folder within an existing
Maildir, with the correct permission and structure.
-S
- create a "sharable" maildir. A sharable maildir has
slightly different permissions which allows creating publicly-shared
folders.-f folder
- do not create a maildir, but create a folder in
an existing maildir.-s mode
- create a publicly accessible folder in an
existing sharable maildir. First, use the -S
option to
create a sharable maildir, then use the -s
option to create
publicly accessible folders. "mode" is a comma-separated list of
the following keywords: read
- readonly folder, only you can
write messages to this folder; write
- anyone can read and
write messages to this folder; group
- only allow members of
your own system group to access messages in this folder (instead of
everyone).--add name=/shared/maildir/path
, --del
name
- create or delete the directories and links needed to
access shared folders. See below for more information.This maildirmake
command supports enhanced maildirs that
contain folders.
By itself, maildirmake
makes a new subdirectory
maildir, and creates all the necessary structures. The -f option
creates a new "folder" within an existing maildir. maildir must
already exist, and the maildirmake
command will create a new
folder inside it.
Folders are simply subdirectories inside the main maildir whose names start
with a period, and which are themselves maildirs. For example, the command
"maildirmake -f Drafts mail/Maildir
" creates
mail/Maildir/.Drafts
, with the usual tmp
,
new
, and cur
. You MUST use the -f option, instead of
specifying mail/Maildir/.Drafts
directly, in order to correctly
initialize certain enhanced maildir features.
Folders cannot be created directly within other folders. Running
maildirmake -f Urgent mail/Maildir/.Drafts
will not work.
Instead, the period character is designated as a hierarchy separator, run
maildirmake -f Drafts.Urgent mail/Maildir
instead. This creates
mail/Maildir/.Drafts.Urgent
, and all mail software that supports
enhanced maildirs will interpret it as a subfolder Urgent of the Drafts
folder.
This is another extension to the Maildir format that allows folders to be shared between multiple clients. First, you need to create a collection of sharable folders, as a separate maildir:
maildirmake -S /usr/local/share/maildirs/notices
Then, you create individuals folders that will be accessed in shared mode:
maildirmake -s write -f Weekly /usr/local/share/maildirs/notices
The "Weekly" folder is created, with read/write access to everyone.
Multiple folders can be created in the same maildir, with different access
permissions. Everyone can create a sharable maildir. The access privileges
for individual folders are set by the -s
option, and are
implemented using traditional filesystem permissions.
Use the --add and --del options to add a sharable maildir to an existing maildir. Client software that implement this extension will now know where to find sharable folders:
maildirmake --add notices=/usr/local/share/maildirs/notices $HOME/Maildir$HOME/Maildir is your main maildir. The argument to
-add
is nick=path. nick is the nickname you give to the collection of
all the sharable folders, and path is the location of the sharable
maildir. All folders in the sharable maildir that you have access to -- such
as "Weekly", in this case, will now be accessible by compliant software.
Multiple sharable maildirs can be added, by giving each one a unique name.
The --del
option "disconnects" the sharable maildir from your
main maildir.
Normally the -add command must be run for every maildir which needs
to access a sharable maildir. Alternatively the file
/usr/local/etc/maildirshared
can be created, which will be used for
a default set of sharable maildirs. Each line in this file takes the following
form:
nick<tab>path
nick is a short nickname for the sharable maildir, <tab> is a single tab character, path is the pathname to the sharable maildir.
You may have read or write access to a shared folder. If you have write access, you can add messages to the shared folder. You can also delete messages that you've added, but nobody else's.
Anyone can create a sharable maildir, so if the sharable maildir is actually created by you, can can delete any message, not just your own.
The rest of this manual page is a technical description of Maildirs. The first implementation and definition of Maildirs were in Dan Bernstein's Qmail mail server, and it described a single, flat, mail repository. Since then, independent developers added additional features on top of it, such as folders and voluntary mail quotas. This document describes the enhanced Maildir implementation without noting the specific enhancements to the original Maildir implementation. See http://www.qmail.org/man/man5/maildir.html for the original specifications of Maildirs.
Maildirs offer several improvements over traditional mailbox files. Unlike mailbox files, no locking is necessary in order to deliver new messages to maildirs, or to read mail in maildirs. Multiple agents can deliver new mail to maildirs, in parallel, and read mail from maildirs. Locking is often problematic with certain network file system. Maildirs require no locking, and can be implemented on top of almost any file system.
A maildir is an ordinary subdirectory, with group and world access
permissions revoked, of course. A maildir contains three subdirectories:
tmp
, new
, and cur
. Folders are
additional subdirectories whose names begin with a period: such as
.Drafts
or .Sent
. Each folder itself contains the
same three subdirectories, tmp
, new
, and
cur
, and can be thought of as a maildir in of itself, except that
it itself cannot contain nested folder subdirectories, as explained above.
A folder subdirectory also contains an extra, zero-length file named
maildirfolder
, whose purpose is to simply inform any mail
delivery agent that it really is delivery directly to a subfolder, and that
the mail delivery agent should look in the parent directory for any required
housekeeping information. Software that uses maildirs may also create
additional files besides the tmp
, new
, and
cur
subdirectories -- in the main maildir or a folder
"submaildir" -- for their own use.
E-mail messages are stored in separate, individual files as defined below,
one E-mail message per file. The tmp
subdirectories is used to
temporarily store E-mail messages that are in the process of being delivered
to this maildir. It can also be used for storing other kinds of temporary
files, as long as they follow the same naming convention for creating new
files in tmp
. The new
subdirectory stores messages
that have been delivered to this maildir, but have not yet been seen by any
mail application. The cur
subdirectory stores messages that have
already been seen by mail applications.
The following process is used to deliver mail to a maildir:
A new unique filename is created using one of two possible forms: "time.pid.host", or "time.pid_unique.host". "time" is the current system time, in seconds. "pid" is the process number of the process that is delivering this message to the maildir. "host" is the name of the machine where the mail is being delivered. In the event that the same process will create multiple messages, it should append a unique suffix to the process id, preferrably an underscore, followed by an increasing counter. This applies whether messages created by a process are all in the same, or different, maildirs. This protocol allows multiple processes running on multiple machines on the same network to simultaneously create new messages without stomping on each other.
The filename created in the previous step is checked for existence by
executing the stat(2) system call, against the tmp
subdirectory. If the result of the stat system call is ANYTHING OTHER
than the system error ENOENT
, the process must sleep for two
seconds, then go back and create a new unique filename. This is an extra step
to insure that each new message has a completely unique filename.
Other applications that wish to use tmp
for temporary storage
should observe the same protocol (but see READING MAIL FROM MAILDIRS below,
because old files in tmp
will be eventually deleted).
If the stat system call returned ENOENT
, the process
can go ahead, create the file in the tmp
subdirectory, and save
the entire message in the new file. The message saved MUST NOT have the
traditional "From_" line that is used to separate individual messages in the
traditional mailbox files. The message also MUST NOT have any "From_" lines
in the contents of the message prefixed by the ">" character, as messages in
traditional mailbox files are.
Saving the message means to reliably save it in a file. The number of
bytes returned by the write
system call must be checked, in order
to make sure that the complete message has been written out.
After the message is saved, the file is closed and is then immediately
moved/renamed into the new
subdirectory. The name of the file
should be the same name it had in the tmp
subdirectory.
It is HIGHLY RECOMMENDED that new implementations of software that creates
messages in maildirs would also append the suffix ",S=nnn" to the name of the
file when it is moved into the new
subdirectory, where "nnn"
represents the size of the message, in bytes. This optimizes the voluntary
maildir quota enhancement, as it permits the size of all the mail stored in
the maildir to be added up without issuing the stat
system call
for each individual message (which can be quite a performance drain with
certain network filesystems).
Applications that read mail from maildirs should do it in the following order:
When opening a maildir or a maildir folder, read the tmp
subdirectory and delete anything in there that's at least 36 hours old.
Look for new messages in the new
subdirectory. For each new
message found, new/filename, rename it as cur/filename:2,info,
where info is used to represent the state of the message, and it
consists of zero or more boolean flags chosen from the following: R - this
message has been replied to, S - this message has been viewed (seen), T - this
message has been marked to be deleted (trashed), but is not yet completely
removed (messages are removed from maildirs simply by deleting their file), F
- this message has been marked by the user, for some purpose. These flags must
be stored in alphabetic order. New messages contain only the :2,
suffix, with no flags, indicating that the messages haven't been seen,
replied, marked, or deleted.
Maildirs may have maximum size quotas defined, but these quotas are purely voluntary. If you need to implement mandatory quotas, you should use any quota facilities provided by the underlying filesystem that is used to store the maildirs. The maildir quota enhancement is designed to be used in certain situations where filesystem-based quotas cannot be used for some reason. The implementation is designed to avoid the use of any locking. As such, at certain times the calculated quota may be imprecise, and certain anomalous situations may result in the maildir actually going over the stated quota. One such situation would be when applications create messages without updating the quota estimate for the maildir. Eventually it will be precisely recalculated, but wherever possible new messages should be created in compliance with the voluntary quota protocol.
The voluntary quota protocol involves some additional procedures that must
be followed when creating or deleting messages within a given maildir or its
subfolders. The deliverquota(8) command is a
tiny application that delivers a single message to a maildir using the
voluntary quota protocol, and hopefully it can be used as a measure of last
resort. Alternatively, applications can use the libmaildir.a
library to handle all the low-level dirty details for them. The voluntary
quota enhancement is specified in a separate README.