debian/rules: Use `git' potty wrapper.
[qmail] / mbox.5
CommitLineData
2117e02e
MW
1.TH mbox 5
2.SH "NAME"
3mbox \- file containing mail messages
4.SH "INTRODUCTION"
5The most common format for storage of mail messages is
6.I mbox
7format.
8An
9.I mbox
10is a single file containing zero or more mail messages.
11.SH "MESSAGE FORMAT"
12A message encoded in
13.I mbox
14format begins with a
15.B From_
16line, continues with a series of
17.B \fRnon-\fBFrom_
18lines,
19and ends with a blank line.
20A
21.B From_
22line means any line that begins with the characters
23F, r, o, m, space:
24
25.EX
26 From god@heaven.af.mil Sat Jan 3 01:05:34 1996
27.br
28 Return-Path: <god@heaven.af.mil>
29.br
30 Delivered-To: djb@silverton.berkeley.edu
31.br
32 Date: 3 Jan 1996 01:05:34 -0000
33.br
34 From: God <god@heaven.af.mil>
35.br
36 To: djb@silverton.berkeley.edu (D. J. Bernstein)
37.br
38
39.br
40 How's that mail system project coming along?
41.br
42
43.EE
44
45The final line is a completely blank line (no spaces or tabs).
46Notice that blank lines may also appear elsewhere in the message.
47
48The
49.B From_
50line always looks like
51.B From
52.I envsender
53.I date
54.IR moreinfo .
55.I envsender
56is one word, without spaces or tabs;
57it is usually the envelope sender of the message.
58.I date
59is the delivery date of the message.
60It always contains exactly 24 characters in
61.B asctime
62format.
63.I moreinfo
64is optional; it may contain arbitrary information.
65
66Between the
67.B From_
68line and the blank line is a message in RFC 822 format,
69as described in
70.BR qmail-header(5) ,
71subject to
72.B >From quoting
73as described below.
74.SH "HOW A MESSAGE IS DELIVERED"
75Here is how a program appends a message to an
76.I mbox
77file.
78
79It first creates a
80.B From_
81line given the message's envelope sender and the current date.
82If the envelope sender is empty (i.e., if this is a bounce message),
83the program uses
84.B MAILER-DAEMON
85instead.
86If the envelope sender contains spaces, tabs, or newlines,
87the program replaces them with hyphens.
88
89The program then copies the message, applying
90.B >From quoting
91to each line.
92.B >From quoting
93ensures that the resulting lines are not
94.B From_
95lines:
96the program prepends a
97.B >
98to any
99.B From_
100line,
101.B >From_
102line,
103.B >>From_
104line,
105.B >>>From_
106line,
107etc.
108
109Finally the program appends a blank line to the message.
110If the last line of the message was a partial line,
111it writes two newlines;
112otherwise it writes one.
113.SH "HOW A MESSAGE IS READ"
114A reader scans through an
115.I mbox
116file looking for
117.B From_
118lines.
119Any
120.B From_
121line marks the beginning of a message.
122The reader should not attempt to take advantage of the fact that every
123.B From_
124line (past the beginning of the file)
125is preceded by a blank line.
126
127Once the reader finds a message,
128it extracts a (possibly corrupted) envelope sender
129and delivery date out of the
130.B From_
131line.
132It then reads until the next
133.B From_
134line or end of file, whichever comes first.
135It strips off the final blank line
136and
137deletes the
138quoting of
139.B >From_
140lines and
141.B >>From_
142lines and so on.
143The result is an RFC 822 message.
144.SH "COMMON MBOX VARIANTS"
145There are many variants of
146.I mbox
147format.
148The variant described above is
149.I mboxrd
150format, popularized by Rahul Dhesi in June 1995.
151
152The original
153.I mboxo
154format quotes only
155.B From_
156lines, not
157.B >From_
158lines.
159As a result it is impossible to tell whether
160
161.EX
162 From: djb@silverton.berkeley.edu (D. J. Bernstein)
163.br
164 To: god@heaven.af.mil
165.br
166
167.br
168 >From now through August I'll be doing beta testing.
169.br
170 Thanks for your interest.
171.EE
172
173was quoted in the original message.
174An
175.I mboxrd
176reader will always strip off the quoting.
177
178.I mboxcl
179format is like
180.I mboxo
181format, but includes a Content-Length field with the
182number of bytes in the message.
183.I mboxcl2
184format is like
185.I mboxcl
186but has no
187.B >From
188quoting.
189These formats are used by SVR4 mailers.
190.I mboxcl2
191cannot be read safely by
192.I mboxrd
193readers.
194.SH "UNSPECIFIED DETAILS"
195There are many locking mechanisms for
196.I mbox
197files.
198.B qmail-local
199always uses
200.B flock
201on systems that have it, otherwise
202.BR lockf .
203
204The delivery date in a
205.B From_
206line does not specify a time zone.
207.B qmail-local
208always creates the delivery date in GMT
209so that
210.I mbox
211files can be safely transported from one time zone to another.
212
213If the mtime on a nonempty
214.I mbox
215file is greater than the atime,
216the file has new mail.
217If the mtime is smaller than the atime,
218the new mail has been read.
219If the atime equals the mtime,
220there is no way to tell whether the file has new mail,
221since
222.B qmail-local
223takes much less than a second to run.
224One solution is for a mail reader to artificially set the
225atime to the mtime plus 1.
226Then the file has new mail if and only if the atime is
227less than or equal to the mtime.
228
229Some mail readers place
230.B Status
231fields in each message to indicate which messages have been read.
232.SH "SEE ALSO"
233maildir(5),
234qmail-header(5),
235qmail-local(8)