annotate docs/mixfmt.txt @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
1 /* ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
2 * Copyright 1988-2006 University of Washington
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
3 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
4 * Licensed under the Apache License, Version 2.0 (the "License");
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
5 * you may not use this file except in compliance with the License.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
6 * You may obtain a copy of the License at
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
7 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
8 * http://www.apache.org/licenses/LICENSE-2.0
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
9 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
10 *
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
11 * ========================================================================
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
12 */
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
13
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
14 Last update: 18 December 2006
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
15
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
16 INTRODUCTION
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
17
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
18 This file is the descendant of a design document used to specify the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
19 mix format. An attempt is being made to keep this document more or
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
20 less current with the way the mix format actually works.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
21
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
22
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
23 1. Mix mailbox naming
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
24
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
25 Mailbox names correspond to directory names; thus mix format mailboxes
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
26 are "dual-use" (lack both \NoInferiors and \NoSelect). This will
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
27 satisfy some long-standing requests.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
28
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
29
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
30 2. Mailbox files
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
31
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
32 A mix format mailbox is a directory with regular files with filenames
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
33 of:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
34 .mixmeta mailbox metadata file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
35 .mixindex message index file (message static data)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
36 .mixstatus message status file (message dynamic data)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
37 .mix######## (where ######### is a <hex8>) secondary message
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
38 data files.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
39 .mix primary message data file (used in experimental
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
40 versions, supported for compatibility only)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
41
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
42 2.1 Metadata, index, and status files
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
43
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
44 The mailbox metadata, index, and status files contain a sequence of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
45 CRLF-terminated lines. These files have an update sequence, which is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
46 a strictly-ascending sequence value. Any time the file is changed,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
47 the update sequence is increased; this allows easy detection of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
48 whether the file has been changed by another process. For now, this
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
49 update sequence is a modseq (see below).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
50
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
51 2.1.1 Metadata file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
52
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
53 The mailbox metadata file is called ".mixmeta". It contains a series
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
54 of CRLF-terminated lines. The first character of the line is a key that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
55 identifies the payload of the line, and the remainder of the line is the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
56 payload.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
57 Key Payload
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
58 --- -------
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
59 S <hex8> ;; update sequence
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
60 V <hex8> ;; UIDVALIDITY
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
61 L <hex8> ;; UIDLAST
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
62 N <hex8> ;; current new message file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
63 K [atom 0*(SP atom)] ;; keyword list
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
64
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
65 All other keys are reserved for future assignment and must be ignored
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
66 (and may be discarded) by software which does not recognize them. The
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
67 mailbox metadata file is rewritten as part of new mail delivery (so
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
68 APPENDUID/COPYUID can work) and when new keywords are added.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
69
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
70 2.1.2 Message static index file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
71
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
72 The mailbox message static index file is called ".mixindex". It contains
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
73 a series of CRLF-terminated lines. The first character of the line is a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
74 key that identifies the payload of the line, and the remainder of the line
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
75 is the payload.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
76 Key Payload
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
77 --- -------
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
78 S <hex8> ;; update sequence
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
79 : <uid>:<date>:<size>:<file>:<pos>:<isiz>:<hsiz>
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
80 ;; per-message record
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
81
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
82 The per-message records contain the following data:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
83 <uid> = <hex8> ;; message UID
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
84 <date> = <yyyymmddhhmmss+zzzz> ;; internal date
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
85 <size> = <hex8> ;; rfc822.size
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
86 <file> = <hex8> ;; message data file (0 = .mix file)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
87 <pos> = <hex8> ;; message position in file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
88 <isiz> = <hex8> ;; message internal data size
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
89 <hsiz> = <hex8> ;; header size (offset to body)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
90
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
91 All other keys, and subsequent fields in per-message records, are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
92 reserved for future assignment and must be ignored (and may be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
93 discarded) by software which does not recognize them. The mailbox
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
94 metadata file is appended by new mail delivery and rewritten by
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
95 expunge "burping", and otherwise is not altered.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
96
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
97 2.1.3 Message dynamic status file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
98
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
99 The mailbox message dynamic status file is called ".mixstatus". It contains
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
100 a series of CRLF-terminated lines. The first character of the line is a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
101 key that identifies the payload of the line, and the remainder of the line
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
102 is the payload.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
103 Key Payload
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
104 --- -------
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
105 S <hex8> ;; update sequence
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
106 : <uid>:<uf>:<sf>:<mod>: ;; per-message record
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
107
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
108 The per-message records contain the following data:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
109 <uid> = <hex8> ;; message UID
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
110 <keys> = <hex8> ;; keyword flags
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
111 <flag> = <hex4> ;; system flags
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
112 <mod> = <hex8> ;; date/time last modified (modseq)
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
113
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
114 All other keys, and subsequent fields in per-message records, are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
115 reserved for future assignment and must be ignored (and may be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
116 discarded) by software which does not recognize them. The mailbox
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
117 dynamic idex file is rewritten by flag changes (or any future change
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
118 that alters dynamic data) and is re-read when a session sees that the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
119 mtime has changed (atime and ctime are not used).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
120
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
121 The modseq is an unsigned 32-bit date/time, along with a guarantee
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
122 that this value can not go backwards. It currently corresponds to the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
123 time from time(); however, since it is unsigned, it won't run out until
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
124 the year 2106. In the future, this may be used as a basic for implementing
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
125 the IMAP CONDSTORE extension.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
126
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
127 2.2 Message data files
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
128
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
129 A mix message file is a regular file with filename starting with
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
130 ".mix" followed by a <hex8> suffix which indicates the file number. It
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
131 contains a series of CRLF-terminated lines. By special dispensation, the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
132 filename ".mix" is used for file number 0, which was used in experimental
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
133 versions of mix as a "primary" file (this concept no longer exists).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
134
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
135 A file number is set to the current modseq when it is created. If a copy
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
136 or append causes the file to exceed the compiled-in file size limit, a new
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
137 file is started and the metadata is updated accordingly.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
138
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
139 Preceeding each message is per-message record with the following format:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
140 Key Payload
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
141 --- -------
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
142 ;; per-message record
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
143 : :<code>:<uid>:<date>:<size>:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
144
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
145 The per-message records contain the following data:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
146 <code> = "msg" ;; fixed code
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
147 <uid> = <hex8> ;; message UID
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
148 <date> = <yyyymmddhhmmss+zzzz> ;; internal date
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
149 <size> = <hex8> ;; rfc822.size
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
150 The message data begins on the next line
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
151
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
152 Subsequent fields are reserved for future assignment and must be ignored.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
153
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
154
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
155 3. New mail delivery
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
156
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
157 To deliver a new message, it is necessary to share lock the destination
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
158 metadata file, then get an exclusive lock on the destination index and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
159 status files. Once this is done, the new message data is appended to the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
160 new message file. The metadata (UIDLAST value), index, and status
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
161 files are all updated to add the new message.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
162
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
163 Then all the destination mailbox files are closed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
164
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
165
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
166 4. Mailbox pinging
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
167
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
168 The index and status files are share locked. Initially, sequences are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
169 remembered as zero, so at open time they are always "altered".
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
170
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
171 The sequence from the index file is checked; if it is altered the index
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
172 file is read and processed as follows:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
173 . If expunge is permitted, then any messages that are not in the index
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
174 are reported as having been expunged via mm_expunged().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
175 . new messages are announced via mm_exists()/mm_recent().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
176
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
177 Next, the sequence from the status file is checked. If it is altered,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
178 the status file is read and the status updated for any message which is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
179 new or has an altered modseq in the status file. Altered modseq messages
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
180 are announced via mm_flags().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
181
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
182 Then the index and status files are closed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
183
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
184
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
185 4. Flag alteration
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
186
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
187 The status file is exclusive locked.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
188
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
189 The sequence from the status file is checked. If it is altered, the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
190 status file is read and the status updated for any message which is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
191 new or has an altered modseq in the status file. Altered modseq
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
192 messages are announced via mm_flags().
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
193
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
194 The alterations are then applied for all requested messages, updating
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
195 the modseq for each requestedmessage which changes flags as a result
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
196 of the alteration (alterations which do not result in a change do not
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
197 alter the modseq). Then the status file is rewritten with a new
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
198 sequence, but only if flags of at least one message was changed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
199
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
200 Then the status file is closed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
201
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
202
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
203 5. Checkpoint and expunge
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
204
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
205 Checkpoint is identical to expunge, however it skips the step of expunging
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
206 deleted messages.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
207
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
208 The index and status files are locked exclusive. If expunging, all
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
209 deleted messages are expunged from the index and announced via
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
210 mm_expunged(). The message data is notremoved at this time.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
211
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
212 If a checkpoint was requested, or if any messages were expunged, or if
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
213 it remembered that a "burp" was needed, then:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
214 . the metadata file is locked exclusive. If this fails, remember that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
215 a burp is needed. Otherwise perform a burp:
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
216 . calculate the file byte ranges occupied by expunged messages
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
217 . for each file needing "burping", open and slide down subsequent file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
218 data on top of the expunged messages
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
219 . update the index and status files
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
220
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
221 Then the index and status files are closed.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
222
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
223 5.1 More details on expunging and "burping"
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
224
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
225 Shared expunge presents a problem due to the requirements of the IMAP
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
226 protocol. You can't "burp" away a message until you are certain that
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
227 no sharers have a pointer to any longer. Consequently, for the nonce
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
228 "burping" out expunged data be defered to an exclusive expunge as in
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
229 mbx format.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
230
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
231 If shared burping is ever implemented, then care will be needed not to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
232 burp data that a session still relies upon. It's easy enough to burp
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
233 the index files; just create new index files, deleting the old, and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
234 require that you look for a new one appearing at mailbox ping time
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
235 (when it's safe). The data files are a problem, since we
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
236 intentionally don't want to keep them open and do want to avoid quota
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
237 problems by overwriting in place. Also, when you burp you have to
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
238 change the pointers in the index file.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
239
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
240 Bottom line: shared burping is too hairy right now, so the first
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
241 version will do exclusive-only burping and not worry about it. If
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
242 shared burping is really needed, then that routine will need to be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
243 rewritten.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
244
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
245 Shared burping has been a problem for every other IMAP server. Most
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
246 get it wrong, and cause terrible confusion to clients (including
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
247 client crashes).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
248
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
249
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
250 6. Message data file file roll out strategy
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
251
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
252 The current new message file is finalized, and a new one started, when
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
253 an append or copy is done that would cause the file to grow to larger
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
254 than a preconfigured size (MIXDATAROLL). A multi-message copy or
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
255 append is written into its entirety to a single new message file. In
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
256 the case of multi-copy, the new message file is switched when the sum
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
257 of the sizes of all messages to be copied would cause the current new
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
258 message file to exceed MIXDATAROLL. In the case of multi-append, only
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
259 the first message is considered; this is due to technical limitations.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
260
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
261 7. Error detection
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
262
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
263 Mix detects bad data in the metadata, index, and status files; and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
264 declares the stream dead. It does not unilaterally reassign
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
265 UIDVALIDITY the way that the flat file formats do.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
266
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
267 When mix reads a header from the message file, it also reads the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
268 per-message record and verifies that there is a per-message record there.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
269 This is a simple test for message file corruption. It doesn't declare
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
270 the stream dead; it simply issues an error message and returns a
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
271 zero-length string for the message header. This makes it possible for
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
272 the user to fix the mailbox simply by deleting and expunging any messages
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
273 that are in this state.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
274
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
275
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
276 8. Reconstruct tool
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
277
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
278 [None of this is implemented yet.]
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
279
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
280 The layout of these files is designed to make the reconstruct tool be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
281 as simple as possible. Much of the need for the reconstruct tool is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
282 eliminated since the mix format has a much more limited scope of
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
283 writing than the flat file formats; thus there is "less collateral
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
284 damage."
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
285
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
286 If the metadata file is lost or corrupted, then all keywords are lost;
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
287 if the mailbox has any keywords used in the .mixstatus file, it'll be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
288 necessary to create some placeholder names. Otherwise, a new
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
289 UIDVALIDITY can be assigned, and a good UIDLAST value calculated by
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
290 the reconstruct tool. Since this file is very small, it's not likely
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
291 to be damaged.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
292
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
293 If the index file is lost or corrupted, it is possible to reconstruct
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
294 it with no loss by reading all the data files. However, this could
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
295 cause expunged but not yet burped messages to reappear.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
296
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
297 If the status file is lost or corrupted, then flags are lost and
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
298 will revert to a default state of no flags set. Just deleting the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
299 corrupted file is good enough.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
300
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
301 The reconstruct tool can use the per-message record in the message
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
302 file to locate messages if the recorded sizes and/or messages are
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
303 corrupt. If that happens, it will need to rebuild the index file
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
304 (with associated changes to the metadata file to change the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
305 UIDVALIDITY). That should probably be a manual operation and not be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
306 part of the default operation or auto-reconstruct.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
307
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
308
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
309 9. Locking strategy
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
310
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
311 The mix format does not use the traditional c-client /tmp file locking.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
312
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
313 The metadata file is open and locked whenever the mailbox is open.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
314 Normally this is a shared lock, but it will be upgraded to exclusive
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
315 if the mailbox is expunged. As a guard (since there is no true
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
316 lock-upgrade/downgrade on UNIX), the index exclusive lock must be
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
317 acquired first before upgrading to exclusive.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
318
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
319 The index file is shared locked when reading the index, and exclusive
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
320 locked (and read) when appending new messages to the index or when
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
321 expunging (note that expunging also requires an exclusive lock on
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
322 metadata). Normally, the index file is not open or locked.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
323
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
324 The status file is shared locked when reading status, and exclusive
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
325 locked (and read) when updating status. Normally, the status file is
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
326 not open or locked.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
327
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
328 It isn't necessary to lock any of the data files as long as we only
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
329 have exclusive burping.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
330
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
331
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
332 10. Memory usage
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
333
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
334 The mix format returns a file stringstruct, which is the modern
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
335 c-client behavior. This prevents imapd from growing to enormous sizes
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
336 due to a godzillagram (how it affects other programs depends upon what
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
337 they do with the returned stringstruct).
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
338
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
339
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
340 11. Future extensions
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
341
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
342 Cached ENVELOPE, BODYSTRUCTURE. Cyrus does, and this will eliminate
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
343 most of the reason to access the data files. Possibly cached overviews,
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
344 ala NNTP, instead?
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
345
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
346
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
347 Support for ANNOTATION.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
348
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
349
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
350 12. RENAME issues
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
351
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
352 Mix currently makes no attempt to address the IMAP RENAME problem.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
353 This occurs when a mailbox is deleted, and another mailbox is renamed
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
354 with that name in place, no attempt is made to reassign UIDVALIDITY
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
355 for this mailbox and all the inferior mailboxes. This potentially can
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
356 cause problems for a disconnected-use client that has cached status
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
357 for the old mailbox which had that name.
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
358
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
359 The RENAME problem is a well known flaw in the IMAP protocol. Few
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
360 servers correctly handle it (among other things, not only do all the
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
361 UIDVALIDITY values have to be changed but this has to be done
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
362 atomically!). It was a mistake to add RENAME into IMAP, but it's much
ada5e610ab86 imap-2007e
yuuji@gentei.org
parents:
diff changeset
363 too late to remove it now.

yatex.org