Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > fa5e22015e1f2396d5d803cb1fafdafc > files > 37

courier-base-4.5.0-1mdv2010.0.i586.rpm

<?xml version="1.0"?>
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><title>maildir</title><link rel="stylesheet" href="style.css" type="text/css"/><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"/><link rel="home" href="#maildir" title="maildir"/><link xmlns="" rel="stylesheet" type="text/css" href="manpage.css"/><meta xmlns="" name="MSSmartTagsPreventParsing" content="TRUE"/><link xmlns="" rel="icon" href="icon.gif" type="image/gif"/><!--

Copyright 1998 - 2009 Double Precision, Inc.  See COPYING for distribution
information.

--></head><body><div class="refentry" lang="en" xml:lang="en"><a id="maildir" shape="rect"> </a><div class="titlepage"/><div class="refnamediv"><h2>Name</h2><p>maildir — E-mail directory</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><p>$HOME/Maildir</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id363912" shape="rect"> </a><h2>DESCRIPTION</h2><p>
A “<span class="quote">Maildir</span>” is a structured directory that holds E-mail
messages.
Maildirs were first implemented by the
<span class="application">Qmail</span> mail server.
Qmail's maildirs were a simple data structure, nothing more than a single
collection of E-mail messages.
The <span class="application">Courier</span> mail server builds upon
<span class="application">Qmail</span>'s maildirs to provide
extended functionality, such as folders and quotas.
This document describes
the <span class="application">Courier</span> mail server's extended
maildirs,
without explicitly identifying
The <span class="application">Courier</span> mail server-specific
extensions.
See
<span class="citerefentry"><span class="refentrytitle">maildir</span>(5)</span>
in Qmail's documentation for the original definition of
maildirs.</p><p>
Traditionally, E-mail folders were saved as plain text files, called
“<span class="quote">mboxes</span>”.
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.</p><p>
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.</p><div class="refsect2" lang="en" xml:lang="en"><a id="id373381" shape="rect"> </a><h3>Maildir contents</h3><p>
A “<span class="quote">maildir</span>” is a directory that's created by
<a class="ulink" href="maildirmake.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">maildirmake</span>(1)</span></a>.
Naturally, maildirs should not have any group or world permissions,
unless you want other people to read your mail.
A maildir contains three subdirectories:
<code class="filename">tmp</code>, <code class="filename">new</code>, and
<code class="filename">cur</code>.
These three subdirectories comprise the primary folder, where new mail
is delivered by the system.</p><p>
Folders are
additional subdirectories in the maildir
whose names begin with a period: such as
<code class="filename">.Drafts</code> or <code class="filename">.Sent</code>.
Each folder itself contains the
same three subdirectories, <code class="filename">tmp</code>, <code class="filename">new</code>,
and <code class="filename">cur</code>,
and an additional zero-length file named
<code class="filename">maildirfolder</code>, 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.</p><p>
Folders are not physically nested.
A folder subdirectory,
such as <code class="filename">.Sent</code>
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, <code class="filename">.Sent.2002</code> is considered to be a subfolder
called “<span class="quote">2002</span>” which is a subfolder of “<span class="quote">Sent</span>”.</p><div class="refsect3" lang="en" xml:lang="en"><a id="id346463" shape="rect"> </a><h4>Folder name encoding</h4><p>
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 “<span class="quote">&amp;-</span>”.
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.</p><p>
The “<span class="quote">&amp;</span>”
character starts the modified base64-encoded sequence; the sequence
is
terminated by the “<span class="quote">-</span>” character.
The sequence of 16-bit Unicode characters is
written in big-endian order, and
encoded using the base64-encoding method described in section 5.2
of <a class="ulink" href="http://www.rfc-editor.org/rfc/rfc1521.txt" target="_top" shape="rect">RFC 1521</a>,
with the following modifications:</p><div class="itemizedlist"><ul type="disc"><li><p>
The “<span class="quote">=</span>” padding character is omitted.
When decoding, an incomplete 16-bit character is discarded.</p></li><li><p>
The comma character, “<span class="quote">,</span>” is used in place of the
“<span class="quote">/</span>” character in the base64 alphabet.</p></li></ul></div><p>
For example, the word “<span class="quote">Resume</span>” with both "e"s being the
e-acute character, U+0x00e9,
is encoded as
“<span class="quote">R&amp;AOk-sum&amp;AOk-</span>”
(so a folder of that name would be a maildir subdirectory called
“<span class="quote">.R&amp;AOk-sum&amp;AOk-</span>”).</p></div><div class="refsect3" lang="en" xml:lang="en"><a id="id347135" shape="rect"> </a><h4>Other maildir contents</h4><p>
Software that uses maildirs may also create
additional files besides the
<code class="filename">tmp</code>, <code class="filename">new</code>, and
<code class="filename">cur</code> subdirectories -- in the main maildir or a
subfolder -- for its own purposes.</p></div></div><div class="refsect2" lang="en" xml:lang="en"><a id="id347163" shape="rect"> </a><h3>Messages</h3><p>
E-mail messages are stored in separate, individual files,
one E-mail message per file.
The <code class="filename">tmp</code> subdirectory temporarily
stores E-mail messages that are in the process of being delivered
to this maildir.  <code class="filename">tmp</code> may also
store other kinds of temporary
files, as long as they are created in the same way that message files are
created in <code class="filename">tmp</code>.
The <code class="filename">new</code> subdirectory stores messages
that have been delivered to this maildir, but have not yet been seen by any
mail application.
The <code class="filename">cur</code> subdirectory stores messages that have
already been seen by mail applications.</p></div><div class="refsect2" lang="en" xml:lang="en"><a id="id346702" shape="rect"> </a><h3>Adding new mail to maildirs</h3><p>The following process delivers a new message to the maildir:</p><p>A new unique filename is created using one of two possible forms:
“<span class="quote">time.MusecPpid.host</span>”, or
“<span class="quote">time.MusecPpid_unique.host</span>”.
“<span class="quote">time</span>” and
“<span class="quote">usec</span>”
is the current system
time, obtained from
<span class="citerefentry"><span class="refentrytitle">gettimeofday</span>(2)</span>.
“<span class="quote">pid</span>” is the process number of the process that is
delivering this message to the maildir.
“<span class="quote">host</span>” is the name of the machine
where the mail is being delivered.  In the event that the same process
creates multiple messages, a suffix unique to each message
is appended to the process id;
preferrably an underscore, followed by an increasing counter. This applies
whether messages created by a process are all added
to 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.</p><p>The filename created in the previous step is checked for
existence by
executing the
<span class="citerefentry"><span class="refentrytitle">stat</span>(2)</span>
system call.
If
<span class="citerefentry"><span class="refentrytitle">stat</span>(2)</span>
results in ANYTHING OTHER
than the system error <code class="literal">ENOENT</code>,
the process must sleep for two
seconds, then go back and create another unique filename.
This is an extra step
to insure that each new message has a completely unique filename.</p><p>
Other applications that wish to use <code class="filename">tmp</code>
for temporary storage
should observe the same protocol (but see READING MAIL FROM MAILDIRS below,
because old files in <code class="filename">tmp</code> will be eventually
deleted).</p><p>
If the
<span class="citerefentry"><span class="refentrytitle">stat</span>(2)</span>
system call returned <code class="literal">ENOENT</code>, the process
may proceed to create the file in the <code class="filename">tmp</code>
subdirectory, and save
the entire message in the new file.  The message saved MUST NOT have the
“<span class="quote">From_</span>” header that is used to mboxes.
The message also MUST NOT have any “<span class="quote">From_</span>” lines
in the contents of the message prefixed by the
“<span class="quote">&gt;</span>” character.</p><p>When saving the message,
the number of
bytes returned by the
<span class="citerefentry"><span class="refentrytitle">write</span>(2)</span>
system call must be checked, in order
to make sure that the complete message has been written out.</p><p>After the message is saved,
the file descriptor is
<span class="citerefentry"><span class="refentrytitle">fstat</span>(2)</span>-ed.
The file's device number, inode number, and the its byte size, are saved.
The file is closed and is then
immediately
moved/renamed into the <code class="filename">new</code> subdirectory.
The name of the file in <code class="filename">new</code>
should be
“<span class="quote">time.MusecPpidVdevIino.host,S=<em class="replaceable"><code>cnt</code></em></span>”, or
“<span class="quote">time.MusecPpidVdevIino_unique.host,S=<em class="replaceable"><code>cnt</code></em></span>”.
“<span class="quote">dev</span>” is the message's device number,
“<span class="quote">ino</span>” is the message's inode number
(from the previous
<span class="citerefentry"><span class="refentrytitle">fstat</span>(2)</span>
call);
and “<span class="quote">cnt</span>” is the message's size, in bytes.</p><p>
The “<span class="quote">,S=<em class="replaceable"><code>cnt</code></em></span>”
part optimizes the <a class="ulink" href="http://www.courier-mta.org" target="_top" shape="rect"><span class="application">Courier</span></a> mail server's
maildir quota enhancement; it allows the size of all the mail stored in
the maildir to be added up without issuing the
<span class="citerefentry"><span class="refentrytitle">stat</span>(2)</span>
system call
for each individual message (this can be quite a performance drain with
certain network filesystems).</p></div><div class="refsect2" lang="en" xml:lang="en"><a id="id391155" shape="rect"> </a><h3>READING MAIL FROM MAILDIRS</h3><p>
Applications that read mail from maildirs should do it in the following
order:</p><p>
When opening a maildir or a maildir folder, read the <code class="filename">tmp</code>
subdirectory and delete any files in there that are at least 36 hours
old.</p><p>
Look for new messages in the <code class="filename">new</code> subdirectory.
Rename <em class="replaceable"><code>new/filename</code></em>,
as <em class="replaceable"><code>cur/filename:2,info</code></em>.
Here, <em class="replaceable"><code>info</code></em> represents the state of the message,
and it
consists of zero or more boolean flags chosen from the following:
“<span class="quote"><code class="literal">D</code></span>” - this is a 'draft' message,
“<span class="quote"><code class="literal">R</code></span>” - this message has been replied to,
“<span class="quote"><code class="literal">S</code></span>” - this message has been viewed (seen),
“<span class="quote"><code class="literal">T</code></span>” - this
message has been marked to be deleted (trashed), but is not yet
removed (messages are removed from maildirs simply by deleting their file),
“<span class="quote"><code class="literal">F</code></span>” - this message has been marked by the
user, for some purpose.
These flags must be stored in alphabetical order.
New messages contain only the <code class="literal">:2,</code>
suffix, with no flags, indicating that the messages were not seen,
replied, marked, or deleted.</p><p>
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.</p><p>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
<a class="ulink" href="deliverquota.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">deliverquota</span>(8)</span></a>
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
<code class="filename">libmaildir.a</code>
library to handle all the low-level dirty details for them. The voluntary
quota enhancement is described in the
<a class="ulink" href="maildirquota.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">maildirquota</span>(7)</span></a>
man page.</p></div><div class="refsect2" lang="en" xml:lang="en"><a id="id391276" shape="rect"> </a><h3>Maildir Quotas</h3><p>
This is a voluntary mechanism for enforcing "loose" quotas on the maximum
sizes of maildirs.  This mechanism is enforced in software, and not by the
operating system.  Therefore it is only effective as long as the maildirs
themselves are not directly accessible by their users, since this mechanism
is trivially disabled.</p><p>
If possible, operating system-enforced quotas are preferrable.
Where operating system quota enforcement is not available, or not possible,
this voluntary quota enforcement mechanism might be an acceptable
compromise.  Since it's enforced in software, all software that modifies
or accesses the maildirs is required to voluntary obey and enforce a
quota.  The voluntary quota implementation is flexible enough to allow
non quota-aware applications to also access the maildirs, without any
drastic consequences.  There will be some non-drastic consequences, though.
Of course, non quota-aware applications will not enforce any defined quotas.
Furthermore, this voluntary maildir quota mechanism works by estimating the
current size of the maildir, with periodic exact recalculation.
Obviously non quota-aware maildir applications will not update the maildir
size estimation, so the estimate will be thrown off for some period of time,
until the next recalculation.</p><p>
This voluntary quota mechanism is designed to be a reasonable compromise
between effectiveness, and performance.  The entire purpose of using
maildir-based mail storage is to avoid any kind of locking, and to permit
parallel access to mail by multiple applications.  In order to compute the
exact size of a maildir, the maildir must be locked somehow to prevent any
modifications while its contents are added up.  Obviously something like
that defeats the original purpose of using maildirs, therefore the voluntary
quota mechanism does not use locking, and that's why the current recorded
maildir size is always considered to be an estimate.  Regular size
recalculations will compensate for any occasional race conditions that result
in the estimate to be thrown off.</p><p>
A quota for an existing maildir is installed by running maildirmake with the
<code class="literal">-q</code> option, and naming an existing maildir.

The <code class="literal">-q</code> option takes a parameter,
<em class="replaceable"><code>quota</code></em>, which
is a comma-separated list of quota specifications. A quota specification
consists of a number followed by either 'S', indicating the maximum message
size in bytes, or 'C', maximum number of messages. For example:</p><p>
</p><div class="blockquote"><blockquote class="blockquote"><div class="informalexample"><div class="literallayout"><p><span class="command"><strong>maildirmake -q 5000000S,1000C ./Maildir</strong></span></p></div></div></blockquote></div><p>
This sets the quota to
5,000,000 bytes or 1000 messages, whichever comes first.</p><p>
</p><div class="blockquote"><blockquote class="blockquote"><div class="informalexample"><div class="literallayout"><p><span class="command"><strong>maildirmake -q 1000000S ./Maildir</strong></span></p></div></div></blockquote></div><p>
This sets the quota
to 1,000,000 bytes, without limiting the number of messages.</p><p>
A quota of an existing maildir can be changed by rerunning the
<span class="command"><strong>maildirmake</strong></span> command with a new <code class="literal">-q</code>
option.
To delete a quota entirely, delete the
<code class="filename"><em class="replaceable"><code>Maildir</code></em>/maildirsize</code>
file.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id391399" shape="rect"> </a><h2>SEE ALSO</h2><p>
<a class="ulink" href="maildirmake.html" target="_top" shape="rect"><span class="citerefentry"><span class="refentrytitle">maildirmake</span>(1)</span></a>.</p></div></div></body></html>