Use m_tempfile and better errors msg
[apps/madmutt.git] / doc / mbox.man
1 '\" t
2 .\" -*-nroff-*-
3 .\"
4 .\"     Copyright (C) 2000 Thomas Roessler <roessler@does-not-exist.org>
5 .\"
6 .\"     This document is in the public domain and may be distributed and
7 .\"     changed arbitrarily.
8 .\"
9 .TH mbox 5 "February 19th, 2002" Unix "User Manuals"
10 .\"
11 .SH NAME
12 mbox \- Format for mail message storage.
13 .\"
14 .SH DESCRIPTION
15 This document describes the format traditionally used by Unix hosts
16 to store mail messages locally.
17 .B mbox
18 files typically reside in the system's mail spool, under various
19 names in users' Mail directories, and under the name
20 .B mbox
21 in users' home directories.
22 .PP
23 An
24 .B mbox
25 is a text file containing an arbitrary number of e-mail messages.
26 Each message consists of a postmark, followed by an e-mail message
27 formatted according to \fBRFC822\fP, \fBRFC2822\fP. The file format
28 is line-oriented. Lines are separated by line feed characters (ASCII 10).
29 .PP
30 A postmark line consists of the four characters "From", followed by
31 a space character, followed by the message's envelope sender
32 address, followed by whitespace, and followed by a time stamp. This
33 line is often called From_ line.
34 .PP
35 The sender address is expected to be
36 .B addr-spec
37 as defined in \fBRFC2822\fP 3.4.1. The date is expected to be
38 .B date-time
39 as defined in \fBRFC2822\fP 3.3.
40 For compatibility reasons with legacy software, two-digit years
41 greater than or equal to 70 should be interpreted as the years
42 1970+, while two-digit years less than 70 should be interpreted as
43 the years 2000-2069. Software reading files in this format should
44 also be prepared to accept non-numeric timezone information such as
45 "CET DST" for Central European Time, daylight saving time.
46 .PP
47 Example:
48 .IP "" 1
49 >From example@example.com Fri Jun 23 02:56:55 2000
50 .PP
51 In order to avoid misinterpretation of lines in message bodies
52 which begin with the four characters "From", followed by a space
53 character, the mail delivery agent must quote any occurrence
54 of "From " at the start of a body line.
55 .sp
56 There are two different quoting schemes, the first (\fBMBOXO\fP) only
57 quotes plain "From " lines in the body by prepending a '>' to the
58 line; the second (\fBMBOXRD\fP) also quotes already quoted "From "
59 lines by prepending a '>' (i.e. ">From ", ">>From ", ...). The later
60 has the advantage that lines like
61 .IP "" 1
62 >From the command line you can use the '-p' option
63 .PP
64 aren't dequoted wrongly as a \fBMBOXRD\fP-MDA would turn the line
65 into
66 .IP "" 1
67 >>From the command line you can use the '-p' option
68 .PP
69 before storing it. Besides \fBMBOXO\fP and \fBMBOXRD\fP there is also
70 \fBMBOXCL\fP which is \fBMBOXO\fP with a "Content-Length:"-field with the
71 number of bytes in the message body; some MUAs (like
72 .BR madmutt (1))
73 do automatically transform \fBMBOXO\fP mailboxes into \fBMBOXCL\fP ones when
74 ever they write them back as \fBMBOXCL\fP can be read by any \fBMBOXO\fP-MUA
75 without any problems.
76 .PP
77 If the modification-time (usually determined via
78 .BR stat (2))
79 of a nonempty
80 .B mbox
81 file is greater than the access-time the file has new mail. Many MUAs
82 place a Status: header in each message to indicate which messages have
83 already been read.
84 .\"
85 .SH LOCKING
86 Since
87 .B mbox
88 files are frequently accessed by multiple programs in parallel,
89 .B mbox
90 files should generally not be accessed without locking.
91 .PP
92 Three different locking mechanisms (and combinations thereof) are in
93 general use:
94 .IP "\(bu"
95 .BR fcntl (2)
96 locking is mostly used on recent, POSIX-compliant systems. Use of
97 this locking method is, in particular, advisable if
98 .B mbox
99 files are accessed through the Network File System (NFS), since it
100 seems the only way to reliably invalidate NFS clients' caches.
101 .IP "\(bu"
102 .BR flock (2)
103 locking is mostly used on BSD-based systems.
104 .IP "\(bu"
105 Dotlocking is used on all kinds of systems. In order to lock an
106 .B mbox
107 file named \fIfolder\fR, an application first creates a temporary file
108 with a unique name in the directory in which the
109 \fIfolder\fR resides. The application then tries to use the
110 .BR link (2)
111 system call to create a hard link named \fIfolder.lock\fR
112 to the temporary file. The success of the
113 .BR link (2)
114 system call should be additionally verified using
115 .BR stat (2)
116 calls. If the link has succeeded, the mail folder is considered
117 dotlocked. The temporary file can then safely be unlinked.
118 .IP ""
119 In order to release the lock, an application just unlinks the
120 \fIfolder.lock\fR file.
121 .PP
122 If multiple methods are combined, implementors should make sure to
123 use the non-blocking variants of the
124 .BR fcntl (2)
125 and
126 .BR flock (2)
127 system calls in order to avoid deadlocks.
128 .PP
129 If multiple methods are combined, an
130 .B mbox
131 file must not be considered to have been successfully locked before
132 all individual locks were obtained. When one of the individual
133 locking methods fails, an application should release all locks it
134 acquired successfully, and restart the entire locking procedure from
135 the beginning, after a suitable delay.
136 .PP
137 The locking mechanism used on a particular system is a matter of
138 local policy, and should be consistently used by all applications
139 installed on the system which access
140 .B mbox
141 files. Failure to do so may result in loss of e-mail data, and in
142 corrupted
143 .B mbox
144 files.
145 .\"
146 .SH FILES
147 .IR /var/spool/mail/$LOGNAME
148 .RS
149 \fB$LOGNAME\fP's incoming mail folder.
150 .RE
151 .PP
152 .IR $HOME/mbox
153 .RS
154 user's archived mail messages, in his \fB$HOME\fP directory.
155 .RE
156 .PP
157 .IR $HOME/Mail/
158 .RS
159 A directory in user's \fB$HOME\fP directory which is commonly used to hold
160 .B mbox
161 format folders.
162 .RE
163 .PP
164 .\"
165 .SH "SEE ALSO"
166 .BR madmutt (1),
167 .BR fcntl (2),
168 .BR flock (2),
169 .BR link (2),
170 .BR stat (2),
171 .BR maildir (5),
172 .BR mmdf (5),
173 .BR RFC822 ,
174 .BR RFC976 ,
175 .BR RFC2822
176 .\"
177 .SH AUTHOR
178 Thomas Roessler <roessler@does-not-exist.org>, Urs Janssen <urs@tin.org>
179 .\"
180 .SH HISTORY
181 The
182 .B mbox
183 format occurred in Version 6 AT&T Unix.
184 .br
185 A variant of this format was documented in \fBRFC976\fP.