mbox(5) mbox(5) NNAAMMEE mbox - file containing mail messages IINNTTRROODDUUCCTTIIOONN The most common format for storage of mail messages is _m_b_o_x format. An _m_b_o_x is a single file containing zero or more mail messages. MMEESSSSAAGGEE FFOORRMMAATT A message encoded in _m_b_o_x format begins with a FFrroomm__ line, continues with a series of non-FFrroomm__ lines, and ends with a blank line. A FFrroomm__ line means any line that begins with the characters F, r, o, m, space: From god@heaven.af.mil Sat Jan 3 01:05:34 1996 Return-Path: Delivered-To: djb@silverton.berkeley.edu Date: 3 Jan 1996 01:05:34 -0000 From: God To: djb@silverton.berkeley.edu (D. J. Bernstein) How’s that mail system project coming along? The final line is a completely blank line (no spaces or tabs). Notice that blank lines may also appear elsewhere in the message. The FFrroomm__ line always looks like FFrroomm _e_n_v_s_e_n_d_e_r _d_a_t_e _m_o_r_e_i_n_f_o. _e_n_v_s_e_n_d_e_r is one word, without spaces or tabs; it is usually the enve- lope sender of the message. _d_a_t_e is the delivery date of the message. It always contains exactly 24 characters in aassccttiimmee format. _m_o_r_e_i_n_f_o is optional; it may contain arbitrary information. Between the FFrroomm__ line and the blank line is a message in RFC 822 for- mat, as described in qqmmaaiill--hheeaaddeerr((55)), subject to >>FFrroomm qquuoottiinngg as described below. HHOOWW AA MMEESSSSAAGGEE IISS DDEELLIIVVEERREEDD Here is how a program appends a message to an _m_b_o_x file. It first creates a FFrroomm__ line given the message’s envelope sender and the current date. If the envelope sender is empty (i.e., if this is a bounce message), the program uses MMAAIILLEERR--DDAAEEMMOONN instead. If the enve- lope sender contains spaces, tabs, or newlines, the program replaces them with hyphens. The program then copies the message, applying >>FFrroomm qquuoottiinngg to each line. >>FFrroomm qquuoottiinngg ensures that the resulting lines are not FFrroomm__ lines: the program prepends a >> to any FFrroomm__ line, >>FFrroomm__ line, >>>>FFrroomm__ line, >>>>>>FFrroomm__ line, etc. Finally the program appends a blank line to the message. If the last line of the message was a partial line, it writes two newlines; other- wise it writes one. HHOOWW AA MMEESSSSAAGGEE IISS RREEAADD A reader scans through an _m_b_o_x file looking for FFrroomm__ lines. Any FFrroomm__ line marks the beginning of a message. The reader should not attempt to take advantage of the fact that every FFrroomm__ line (past the beginning of the file) is preceded by a blank line. Once the reader finds a message, it extracts a (possibly corrupted) envelope sender and delivery date out of the FFrroomm__ line. It then reads until the next FFrroomm__ line or end of file, whichever comes first. It strips off the final blank line and deletes the quoting of >>FFrroomm__ lines and >>>>FFrroomm__ lines and so on. The result is an RFC 822 message. CCOOMMMMOONN MMBBOOXX VVAARRIIAANNTTSS There are many variants of _m_b_o_x format. The variant described above is _m_b_o_x_r_d format, popularized by Rahul Dhesi in June 1995. The original _m_b_o_x_o format quotes only FFrroomm__ lines, not >>FFrroomm__ lines. As a result it is impossible to tell whether From: djb@silverton.berkeley.edu (D. J. Bernstein) To: god@heaven.af.mil >From now through August I’ll be doing beta testing. Thanks for your interest. was quoted in the original message. An _m_b_o_x_r_d reader will always strip off the quoting. _m_b_o_x_c_l format is like _m_b_o_x_o format, but includes a Content-Length field with the number of bytes in the message. _m_b_o_x_c_l_2 format is like _m_b_o_x_c_l but has no >>FFrroomm quoting. These formats are used by SVR4 mailers. _m_b_o_x_c_l_2 cannot be read safely by _m_b_o_x_r_d readers. UUNNSSPPEECCIIFFIIEEDD DDEETTAAIILLSS There are many locking mechanisms for _m_b_o_x files. qqmmaaiill--llooccaall always uses fflloocckk on systems that have it, otherwise lloocckkff. The delivery date in a FFrroomm__ line does not specify a time zone. qqmmaaiill-- llooccaall always creates the delivery date in GMT so that _m_b_o_x files can be safely transported from one time zone to another. If the mtime on a nonempty _m_b_o_x file is greater than the atime, the file has new mail. If the mtime is smaller than the atime, the new mail has been read. If the atime equals the mtime, there is no way to tell whether the file has new mail, since qqmmaaiill--llooccaall takes much less than a second to run. One solution is for a mail reader to artifi- cially set the atime to the mtime plus 1. Then the file has new mail if and only if the atime is less than or equal to the mtime. Some mail readers place SSttaattuuss fields in each message to indicate which messages have been read. SSEEEE AALLSSOO maildir(5), qmail-header(5), qmail-local(8) mbox(5)