/
usr
/
share
/
doc
/
python2-docs
/
html
/
library
/
/usr/share/doc/python2-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
59507
0644
edit
dl
rm
abc.html
25826
0644
edit
dl
rm
aepack.html
14164
0644
edit
dl
rm
aetools.html
16389
0644
edit
dl
rm
aetypes.html
21021
0644
edit
dl
rm
aifc.html
25064
0644
edit
dl
rm
al.html
18672
0644
edit
dl
rm
allos.html
35297
0644
edit
dl
rm
anydbm.html
18124
0644
edit
dl
rm
archiving.html
10078
0644
edit
dl
rm
argparse.html
263616
0644
edit
dl
rm
array.html
31855
0644
edit
dl
rm
ast.html
38167
0644
edit
dl
rm
asynchat.html
33930
0644
edit
dl
rm
asyncore.html
40631
0644
edit
dl
rm
atexit.html
18455
0644
edit
dl
rm
audioop.html
34252
0644
edit
dl
rm
autogil.html
8733
0644
edit
dl
rm
base64.html
21862
0644
edit
dl
rm
basehttpserver.html
37441
0644
edit
dl
rm
bastion.html
11798
0644
edit
dl
rm
bdb.html
41395
0644
edit
dl
rm
binascii.html
22997
0644
edit
dl
rm
binhex.html
11309
0644
edit
dl
rm
bisect.html
24666
0644
edit
dl
rm
bsddb.html
28589
0644
edit
dl
rm
bz2.html
29048
0644
edit
dl
rm
calendar.html
41762
0644
edit
dl
rm
carbon.html
51998
0644
edit
dl
rm
cd.html
30033
0644
edit
dl
rm
cgi.html
55922
0644
edit
dl
rm
cgihttpserver.html
14026
0644
edit
dl
rm
cgitb.html
12263
0644
edit
dl
rm
chunk.html
15899
0644
edit
dl
rm
cmath.html
28365
0644
edit
dl
rm
cmd.html
29042
0644
edit
dl
rm
code.html
26959
0644
edit
dl
rm
codecs.html
118258
0644
edit
dl
rm
codeop.html
15898
0644
edit
dl
rm
collections.html
147647
0644
edit
dl
rm
colorpicker.html
8035
0644
edit
dl
rm
colorsys.html
11919
0644
edit
dl
rm
commands.html
15516
0644
edit
dl
rm
compileall.html
18621
0644
edit
dl
rm
compiler.html
75897
0644
edit
dl
rm
configparser.html
67751
0644
edit
dl
rm
constants.html
13979
0644
edit
dl
rm
contextlib.html
22777
0644
edit
dl
rm
cookie.html
41854
0644
edit
dl
rm
cookielib.html
91032
0644
edit
dl
rm
copy.html
13004
0644
edit
dl
rm
copy_reg.html
14691
0644
edit
dl
rm
crypt.html
10647
0644
edit
dl
rm
crypto.html
7761
0644
edit
dl
rm
csv.html
76456
0644
edit
dl
rm
ctypes.html
264575
0644
edit
dl
rm
curses.ascii.html
24873
0644
edit
dl
rm
curses.html
167501
0644
edit
dl
rm
curses.panel.html
15824
0644
edit
dl
rm
custominterp.html
8026
0644
edit
dl
rm
datatypes.html
18015
0644
edit
dl
rm
datetime.html
253438
0644
edit
dl
rm
dbhash.html
16825
0644
edit
dl
rm
dbm.html
13507
0644
edit
dl
rm
debug.html
10703
0644
edit
dl
rm
decimal.html
222315
0644
edit
dl
rm
development.html
14828
0644
edit
dl
rm
difflib.html
91975
0644
edit
dl
rm
dircache.html
12299
0644
edit
dl
rm
dis.html
84156
0644
edit
dl
rm
distribution.html
7679
0644
edit
dl
rm
distutils.html
10152
0644
edit
dl
rm
dl.html
17668
0644
edit
dl
rm
doctest.html
185883
0644
edit
dl
rm
docxmlrpcserver.html
17573
0644
edit
dl
rm
dumbdbm.html
15549
0644
edit
dl
rm
dummy_thread.html
10065
0644
edit
dl
rm
dummy_threading.html
8934
0644
edit
dl
rm
easydialogs.html
33124
0644
edit
dl
rm
email-examples.html
47424
0644
edit
dl
rm
email.charset.html
29424
0644
edit
dl
rm
email.encoders.html
12847
0644
edit
dl
rm
email.errors.html
17952
0644
edit
dl
rm
email.generator.html
23141
0644
edit
dl
rm
email.header.html
29108
0644
edit
dl
rm
email.html
55722
0644
edit
dl
rm
email.iterators.html
12623
0644
edit
dl
rm
email.message.html
70189
0644
edit
dl
rm
email.mime.html
31655
0644
edit
dl
rm
email.parser.html
35142
0644
edit
dl
rm
email.utils.html
27076
0644
edit
dl
rm
ensurepip.html
18327
0644
edit
dl
rm
errno.html
40246
0644
edit
dl
rm
exceptions.html
63693
0644
edit
dl
rm
fcntl.html
26245
0644
edit
dl
rm
filecmp.html
23997
0644
edit
dl
rm
fileformats.html
9653
0644
edit
dl
rm
fileinput.html
27071
0644
edit
dl
rm
filesys.html
10866
0644
edit
dl
rm
fl.html
56525
0644
edit
dl
rm
fm.html
13009
0644
edit
dl
rm
fnmatch.html
16258
0644
edit
dl
rm
formatter.html
37371
0644
edit
dl
rm
fpectl.html
16879
0644
edit
dl
rm
fpformat.html
11455
0644
edit
dl
rm
fractions.html
24888
0644
edit
dl
rm
framework.html
36934
0644
edit
dl
rm
frameworks.html
7551
0644
edit
dl
rm
ftplib.html
49577
0644
edit
dl
rm
functions.html
205640
0644
edit
dl
rm
functools.html
29645
0644
edit
dl
rm
future_builtins.html
14477
0644
edit
dl
rm
gc.html
28423
0644
edit
dl
rm
gdbm.html
17805
0644
edit
dl
rm
gensuitemodule.html
12574
0644
edit
dl
rm
getopt.html
25280
0644
edit
dl
rm
getpass.html
11426
0644
edit
dl
rm
gettext.html
84971
0644
edit
dl
rm
gl.html
24342
0644
edit
dl
rm
glob.html
14430
0644
edit
dl
rm
grp.html
11316
0644
edit
dl
rm
gzip.html
20576
0644
edit
dl
rm
hashlib.html
25467
0644
edit
dl
rm
heapq.html
34890
0644
edit
dl
rm
hmac.html
14374
0644
edit
dl
rm
hotshot.html
20147
0644
edit
dl
rm
htmllib.html
27682
0644
edit
dl
rm
htmlparser.html
42433
0644
edit
dl
rm
httplib.html
70932
0644
edit
dl
rm
i18n.html
10047
0644
edit
dl
rm
ic.html
18654
0644
edit
dl
rm
idle.html
42148
0644
edit
dl
rm
imageop.html
16099
0644
edit
dl
rm
imaplib.html
58515
0644
edit
dl
rm
imgfile.html
12732
0644
edit
dl
rm
imghdr.html
12238
0644
edit
dl
rm
imp.html
37603
0644
edit
dl
rm
importlib.html
8926
0644
edit
dl
rm
imputil.html
33563
0644
edit
dl
rm
index.html
79088
0644
edit
dl
rm
inspect.html
56823
0644
edit
dl
rm
internet.html
26138
0644
edit
dl
rm
intro.html
9353
0644
edit
dl
rm
io.html
113701
0644
edit
dl
rm
ipc.html
16598
0644
edit
dl
rm
itertools.html
125397
0644
edit
dl
rm
jpeg.html
13757
0644
edit
dl
rm
json.html
73678
0644
edit
dl
rm
keyword.html
8210
0644
edit
dl
rm
language.html
11687
0644
edit
dl
rm
linecache.html
11416
0644
edit
dl
rm
locale.html
61576
0644
edit
dl
rm
logging.config.html
80045
0644
edit
dl
rm
logging.handlers.html
80194
0644
edit
dl
rm
logging.html
110254
0644
edit
dl
rm
mac.html
23376
0644
edit
dl
rm
macos.html
16129
0644
edit
dl
rm
macosa.html
14080
0644
edit
dl
rm
macostools.html
16898
0644
edit
dl
rm
macpath.html
8386
0644
edit
dl
rm
mailbox.html
171121
0644
edit
dl
rm
mailcap.html
14132
0644
edit
dl
rm
markup.html
19862
0644
edit
dl
rm
marshal.html
19456
0644
edit
dl
rm
math.html
44015
0644
edit
dl
rm
md5.html
15123
0644
edit
dl
rm
mhlib.html
24123
0644
edit
dl
rm
mimetools.html
21206
0644
edit
dl
rm
mimetypes.html
30634
0644
edit
dl
rm
mimewriter.html
16078
0644
edit
dl
rm
mimify.html
15279
0644
edit
dl
rm
miniaeframe.html
13109
0644
edit
dl
rm
misc.html
7236
0644
edit
dl
rm
mm.html
9570
0644
edit
dl
rm
mmap.html
30832
0644
edit
dl
rm
modulefinder.html
18096
0644
edit
dl
rm
modules.html
9017
0644
edit
dl
rm
msilib.html
57853
0644
edit
dl
rm
msvcrt.html
21232
0644
edit
dl
rm
multifile.html
26256
0644
edit
dl
rm
multiprocessing.html
414535
0644
edit
dl
rm
mutex.html
12147
0644
edit
dl
rm
netdata.html
18379
0644
edit
dl
rm
netrc.html
14021
0644
edit
dl
rm
new.html
13177
0644
edit
dl
rm
nis.html
11502
0644
edit
dl
rm
nntplib.html
45689
0644
edit
dl
rm
numbers.html
40636
0644
edit
dl
rm
numeric.html
14292
0644
edit
dl
rm
operator.html
93622
0644
edit
dl
rm
optparse.html
250109
0644
edit
dl
rm
os.html
240195
0644
edit
dl
rm
os.path.html
43402
0644
edit
dl
rm
ossaudiodev.html
45594
0644
edit
dl
rm
othergui.html
9403
0644
edit
dl
rm
parser.html
42558
0644
edit
dl
rm
pdb.html
38603
0644
edit
dl
rm
persistence.html
15676
0644
edit
dl
rm
pickle.html
109684
0644
edit
dl
rm
pickletools.html
11475
0644
edit
dl
rm
pipes.html
19685
0644
edit
dl
rm
pkgutil.html
27367
0644
edit
dl
rm
platform.html
31599
0644
edit
dl
rm
plistlib.html
18344
0644
edit
dl
rm
popen2.html
27601
0644
edit
dl
rm
poplib.html
24320
0644
edit
dl
rm
posix.html
16626
0644
edit
dl
rm
posixfile.html
21387
0644
edit
dl
rm
pprint.html
32207
0644
edit
dl
rm
profile.html
72788
0644
edit
dl
rm
pty.html
10195
0644
edit
dl
rm
pwd.html
12388
0644
edit
dl
rm
pyclbr.html
15812
0644
edit
dl
rm
pydoc.html
13650
0644
edit
dl
rm
pyexpat.html
80886
0644
edit
dl
rm
python.html
12854
0644
edit
dl
rm
py_compile.html
11932
0644
edit
dl
rm
queue.html
26856
0644
edit
dl
rm
quopri.html
12739
0644
edit
dl
rm
random.html
42722
0644
edit
dl
rm
re.html
155985
0644
edit
dl
rm
readline.html
37383
0644
edit
dl
rm
repr.html
21778
0644
edit
dl
rm
resource.html
28286
0644
edit
dl
rm
restricted.html
12366
0644
edit
dl
rm
rexec.html
40566
0644
edit
dl
rm
rfc822.html
46408
0644
edit
dl
rm
rlcompleter.html
14460
0644
edit
dl
rm
robotparser.html
13403
0644
edit
dl
rm
runpy.html
21925
0644
edit
dl
rm
sched.html
19878
0644
edit
dl
rm
scrolledtext.html
9728
0644
edit
dl
rm
select.html
44090
0644
edit
dl
rm
sets.html
40151
0644
edit
dl
rm
sgi.html
10371
0644
edit
dl
rm
sgmllib.html
34464
0644
edit
dl
rm
sha.html
13062
0644
edit
dl
rm
shelve.html
29955
0644
edit
dl
rm
shlex.html
35033
0644
edit
dl
rm
shutil.html
45454
0644
edit
dl
rm
signal.html
34023
0644
edit
dl
rm
simplehttpserver.html
20351
0644
edit
dl
rm
simplexmlrpcserver.html
37794
0644
edit
dl
rm
site.html
26887
0644
edit
dl
rm
smtpd.html
13587
0644
edit
dl
rm
smtplib.html
47054
0644
edit
dl
rm
sndhdr.html
10993
0644
edit
dl
rm
socket.html
116414
0644
edit
dl
rm
socketserver.html
76430
0644
edit
dl
rm
someos.html
16472
0644
edit
dl
rm
spwd.html
11163
0644
edit
dl
rm
sqlite3.html
150014
0644
edit
dl
rm
ssl.html
202453
0644
edit
dl
rm
stat.html
34597
0644
edit
dl
rm
statvfs.html
11326
0644
edit
dl
rm
stdtypes.html
298144
0644
edit
dl
rm
string.html
120219
0644
edit
dl
rm
stringio.html
20061
0644
edit
dl
rm
stringprep.html
17729
0644
edit
dl
rm
strings.html
15905
0644
edit
dl
rm
struct.html
44896
0644
edit
dl
rm
subprocess.html
110447
0644
edit
dl
rm
sun.html
7253
0644
edit
dl
rm
sunau.html
30011
0644
edit
dl
rm
sunaudio.html
19236
0644
edit
dl
rm
symbol.html
8140
0644
edit
dl
rm
symtable.html
25871
0644
edit
dl
rm
sys.html
110996
0644
edit
dl
rm
sysconfig.html
26299
0644
edit
dl
rm
syslog.html
19737
0644
edit
dl
rm
tabnanny.html
11393
0644
edit
dl
rm
tarfile.html
88728
0644
edit
dl
rm
telnetlib.html
27782
0644
edit
dl
rm
tempfile.html
31903
0644
edit
dl
rm
termios.html
17309
0644
edit
dl
rm
test.html
57030
0644
edit
dl
rm
textwrap.html
30135
0644
edit
dl
rm
thread.html
21486
0644
edit
dl
rm
threading.html
86655
0644
edit
dl
rm
time.html
63798
0644
edit
dl
rm
timeit.html
40529
0644
edit
dl
rm
tix.html
50582
0644
edit
dl
rm
tk.html
26568
0644
edit
dl
rm
tkinter.html
84316
0644
edit
dl
rm
token.html
20999
0644
edit
dl
rm
tokenize.html
20607
0644
edit
dl
rm
trace.html
28668
0644
edit
dl
rm
traceback.html
40900
0644
edit
dl
rm
ttk.html
108515
0644
edit
dl
rm
tty.html
9753
0644
edit
dl
rm
turtle.html
230483
0644
edit
dl
rm
types.html
29833
0644
edit
dl
rm
undoc.html
24680
0644
edit
dl
rm
unicodedata.html
20186
0644
edit
dl
rm
unittest.html
225021
0644
edit
dl
rm
unix.html
11223
0644
edit
dl
rm
urllib.html
68266
0644
edit
dl
rm
urllib2.html
113380
0644
edit
dl
rm
urlparse.html
43474
0644
edit
dl
rm
user.html
12707
0644
edit
dl
rm
userdict.html
32069
0644
edit
dl
rm
uu.html
11810
0644
edit
dl
rm
uuid.html
30137
0644
edit
dl
rm
warnings.html
50950
0644
edit
dl
rm
wave.html
24894
0644
edit
dl
rm
weakref.html
38808
0644
edit
dl
rm
webbrowser.html
26565
0644
edit
dl
rm
whichdb.html
9499
0644
edit
dl
rm
windows.html
9817
0644
edit
dl
rm
winsound.html
20466
0644
edit
dl
rm
wsgiref.html
88384
0644
edit
dl
rm
xdrlib.html
33018
0644
edit
dl
rm
xml.dom.html
97877
0644
edit
dl
rm
xml.dom.minidom.html
43230
0644
edit
dl
rm
xml.dom.pulldom.html
13835
0644
edit
dl
rm
xml.etree.elementtree.html
111804
0644
edit
dl
rm
xml.html
18007
0644
edit
dl
rm
xml.sax.handler.html
41877
0644
edit
dl
rm
xml.sax.html
23458
0644
edit
dl
rm
xml.sax.reader.html
44802
0644
edit
dl
rm
xml.sax.utils.html
16087
0644
edit
dl
rm
xmlrpclib.html
69191
0644
edit
dl
rm
zipfile.html
62227
0644
edit
dl
rm
zipimport.html
22769
0644
edit
dl
rm
zlib.html
31230
0644
edit
dl
rm
_winreg.html
64631
0644
edit
dl
rm
__builtin__.html
11069
0644
edit
dl
rm
__future__.html
14688
0644
edit
dl
rm
__main__.html
7512
0644
edit
dl
rm
Edit:
/usr/share/doc/python2-docs/html/library/mailbox.html
(171121B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>18.4. mailbox — Manipulate mailboxes in various formats — Python 2.7.16 documentation</title> <link rel="stylesheet" href="../_static/classic.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.16 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="18.5. mhlib — Access to MH mailboxes" href="mhlib.html" /> <link rel="prev" title="18.3. mailcap — Mailcap file handling" href="mailcap.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/2/library/mailbox.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="mhlib.html" title="18.5. mhlib — Access to MH mailboxes" accesskey="N">next</a> |</li> <li class="right" > <a href="mailcap.html" title="18.3. mailcap — Mailcap file handling" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.16 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="netdata.html" accesskey="U">18. Internet Data Handling</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-mailbox"> <span id="mailbox-manipulate-mailboxes-in-various-formats"></span><h1>18.4. <a class="reference internal" href="#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a> — Manipulate mailboxes in various formats<a class="headerlink" href="#module-mailbox" title="Permalink to this headline">¶</a></h1> <p>This module defines two classes, <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> and <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a>, for accessing and manipulating on-disk mailboxes and the messages they contain. <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> offers a dictionary-like mapping from keys to messages. <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> extends the <a class="reference internal" href="email.message.html#module-email.message" title="email.message: The base class representing email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.message</span></code></a> module’s <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> class with format-specific state and behavior. Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt>Module <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a></dt> <dd>Represent and manipulate messages.</dd> </dl> </div> <div class="section" id="mailbox-objects"> <span id="id1"></span><h2>18.4.1. <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> objects<a class="headerlink" href="#mailbox-objects" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="mailbox.Mailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">Mailbox</code><a class="headerlink" href="#mailbox.Mailbox" title="Permalink to this definition">¶</a></dt> <dd><p>A mailbox, which may be inspected and modified.</p> <p>The <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> class defines an interface and is not intended to be instantiated. Instead, format-specific subclasses should inherit from <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> and your code should instantiate a particular subclass.</p> <p>The <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> interface is dictionary-like, with small keys corresponding to messages. Keys are issued by the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance with which they will be used and are only meaningful to that <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance. A key continues to identify a message even if the corresponding message is modified, such as by replacing it with another message.</p> <p>Messages may be added to a <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance using the set-like method <a class="reference internal" href="#mailbox.Mailbox.add" title="mailbox.Mailbox.add"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add()</span></code></a> and removed using a <code class="docutils literal notranslate"><span class="pre">del</span></code> statement or the set-like methods <a class="reference internal" href="#mailbox.Mailbox.remove" title="mailbox.Mailbox.remove"><code class="xref py py-meth docutils literal notranslate"><span class="pre">remove()</span></code></a> and <a class="reference internal" href="#mailbox.Mailbox.discard" title="mailbox.Mailbox.discard"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discard()</span></code></a>.</p> <p><a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> interface semantics differ from dictionary semantics in some noteworthy ways. Each time a message is requested, a new representation (typically a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance) is generated based upon the current state of the mailbox. Similarly, when a message is added to a <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance, the provided message representation’s contents are copied. In neither case is a reference to the message representation kept by the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance.</p> <p>The default <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> iterator iterates over message representations, not keys as the default dictionary iterator does. Moreover, modification of a mailbox during iteration is safe and well-defined. Messages added to the mailbox after an iterator is created will not be seen by the iterator. Messages removed from the mailbox before the iterator yields them will be silently skipped, though using a key from an iterator may result in a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception if the corresponding message is subsequently removed.</p> <div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">Be very cautious when modifying mailboxes that might be simultaneously changed by some other process. The safest mailbox format to use for such tasks is Maildir; try to avoid using single-file formats such as mbox for concurrent writing. If you’re modifying a mailbox, you <em>must</em> lock it by calling the <a class="reference internal" href="#mailbox.Mailbox.lock" title="mailbox.Mailbox.lock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">lock()</span></code></a> and <a class="reference internal" href="#mailbox.Mailbox.unlock" title="mailbox.Mailbox.unlock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unlock()</span></code></a> methods <em>before</em> reading any messages in the file or making any changes by adding or deleting a message. Failing to lock the mailbox runs the risk of losing messages or corrupting the entire mailbox.</p> </div> <p><a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instances have the following methods:</p> <dl class="method"> <dt id="mailbox.Mailbox.add"> <code class="descname">add</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.add" title="Permalink to this definition">¶</a></dt> <dd><p>Add <em>message</em> to the mailbox and return the key that has been assigned to it.</p> <p>Parameter <em>message</em> may be a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance, an <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a> instance, a string, or a file-like object (which should be open in text mode). If <em>message</em> is an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass (e.g., if it’s an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance and this is an <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a> instance), its format-specific information is used. Otherwise, reasonable defaults for format-specific information are used.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.remove"> <code class="descname">remove</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.remove" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.__delitem__"> <code class="descname">__delitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__delitem__" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.discard"> <code class="descname">discard</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.discard" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the message corresponding to <em>key</em> from the mailbox.</p> <p>If no such message exists, a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception is raised if the method was called as <a class="reference internal" href="#mailbox.Mailbox.remove" title="mailbox.Mailbox.remove"><code class="xref py py-meth docutils literal notranslate"><span class="pre">remove()</span></code></a> or <a class="reference internal" href="#mailbox.Mailbox.__delitem__" title="mailbox.Mailbox.__delitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__delitem__()</span></code></a> but no exception is raised if the method was called as <a class="reference internal" href="#mailbox.Mailbox.discard" title="mailbox.Mailbox.discard"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discard()</span></code></a>. The behavior of <a class="reference internal" href="#mailbox.Mailbox.discard" title="mailbox.Mailbox.discard"><code class="xref py py-meth docutils literal notranslate"><span class="pre">discard()</span></code></a> may be preferred if the underlying mailbox format supports concurrent modification by other processes.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.__setitem__"> <code class="descname">__setitem__</code><span class="sig-paren">(</span><em>key</em>, <em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__setitem__" title="Permalink to this definition">¶</a></dt> <dd><p>Replace the message corresponding to <em>key</em> with <em>message</em>. Raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception if no message already corresponds to <em>key</em>.</p> <p>As with <a class="reference internal" href="#mailbox.Mailbox.add" title="mailbox.Mailbox.add"><code class="xref py py-meth docutils literal notranslate"><span class="pre">add()</span></code></a>, parameter <em>message</em> may be a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance, an <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a> instance, a string, or a file-like object (which should be open in text mode). If <em>message</em> is an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass (e.g., if it’s an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance and this is an <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a> instance), its format-specific information is used. Otherwise, the format-specific information of the message that currently corresponds to <em>key</em> is left unchanged.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.iterkeys"> <code class="descname">iterkeys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.iterkeys" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.keys"> <code class="descname">keys</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.keys" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over all keys if called as <a class="reference internal" href="#mailbox.Mailbox.iterkeys" title="mailbox.Mailbox.iterkeys"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iterkeys()</span></code></a> or return a list of keys if called as <a class="reference internal" href="#mailbox.Mailbox.keys" title="mailbox.Mailbox.keys"><code class="xref py py-meth docutils literal notranslate"><span class="pre">keys()</span></code></a>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.itervalues"> <code class="descname">itervalues</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.itervalues" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.__iter__"> <code class="descname">__iter__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__iter__" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.values"> <code class="descname">values</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.values" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over representations of all messages if called as <a class="reference internal" href="#mailbox.Mailbox.itervalues" title="mailbox.Mailbox.itervalues"><code class="xref py py-meth docutils literal notranslate"><span class="pre">itervalues()</span></code></a> or <a class="reference internal" href="#mailbox.Mailbox.__iter__" title="mailbox.Mailbox.__iter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__iter__()</span></code></a> or return a list of such representations if called as <a class="reference internal" href="#mailbox.Mailbox.values" title="mailbox.Mailbox.values"><code class="xref py py-meth docutils literal notranslate"><span class="pre">values()</span></code></a>. The messages are represented as instances of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass unless a custom message factory was specified when the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance was initialized.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The behavior of <a class="reference internal" href="#mailbox.Mailbox.__iter__" title="mailbox.Mailbox.__iter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__iter__()</span></code></a> is unlike that of dictionaries, which iterate over keys.</p> </div> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.iteritems"> <code class="descname">iteritems</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.iteritems" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.items"> <code class="descname">items</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.items" title="Permalink to this definition">¶</a></dt> <dd><p>Return an iterator over (<em>key</em>, <em>message</em>) pairs, where <em>key</em> is a key and <em>message</em> is a message representation, if called as <a class="reference internal" href="#mailbox.Mailbox.iteritems" title="mailbox.Mailbox.iteritems"><code class="xref py py-meth docutils literal notranslate"><span class="pre">iteritems()</span></code></a> or return a list of such pairs if called as <a class="reference internal" href="#mailbox.Mailbox.items" title="mailbox.Mailbox.items"><code class="xref py py-meth docutils literal notranslate"><span class="pre">items()</span></code></a>. The messages are represented as instances of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass unless a custom message factory was specified when the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance was initialized.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.get"> <code class="descname">get</code><span class="sig-paren">(</span><em>key</em>, <em>default=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.get" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.__getitem__"> <code class="descname">__getitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__getitem__" title="Permalink to this definition">¶</a></dt> <dd><p>Return a representation of the message corresponding to <em>key</em>. If no such message exists, <em>default</em> is returned if the method was called as <a class="reference internal" href="#mailbox.Mailbox.get" title="mailbox.Mailbox.get"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get()</span></code></a> and a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception is raised if the method was called as <a class="reference internal" href="#mailbox.Mailbox.__getitem__" title="mailbox.Mailbox.__getitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__getitem__()</span></code></a>. The message is represented as an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass unless a custom message factory was specified when the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance was initialized.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.get_message"> <code class="descname">get_message</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.get_message" title="Permalink to this definition">¶</a></dt> <dd><p>Return a representation of the message corresponding to <em>key</em> as an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass, or raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception if no such message exists.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.get_string"> <code class="descname">get_string</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.get_string" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representation of the message corresponding to <em>key</em>, or raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception if no such message exists.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>Return a file-like representation of the message corresponding to <em>key</em>, or raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception if no such message exists. The file-like object behaves as if open in binary mode. This file should be closed once it is no longer needed.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Unlike other representations of messages, file-like representations are not necessarily independent of the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance that created them or of the underlying mailbox. More specific documentation is provided by each subclass.</p> </div> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.has_key"> <code class="descname">has_key</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.has_key" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Mailbox.__contains__"> <code class="descname">__contains__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__contains__" title="Permalink to this definition">¶</a></dt> <dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if <em>key</em> corresponds to a message, <code class="docutils literal notranslate"><span class="pre">False</span></code> otherwise.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.__len__"> <code class="descname">__len__</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.__len__" title="Permalink to this definition">¶</a></dt> <dd><p>Return a count of messages in the mailbox.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.clear"> <code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.clear" title="Permalink to this definition">¶</a></dt> <dd><p>Delete all messages from the mailbox.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.pop"> <code class="descname">pop</code><span class="sig-paren">(</span><em>key</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.pop" title="Permalink to this definition">¶</a></dt> <dd><p>Return a representation of the message corresponding to <em>key</em> and delete the message. If no such message exists, return <em>default</em> if it was supplied or else raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception. The message is represented as an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass unless a custom message factory was specified when the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance was initialized.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.popitem"> <code class="descname">popitem</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.popitem" title="Permalink to this definition">¶</a></dt> <dd><p>Return an arbitrary (<em>key</em>, <em>message</em>) pair, where <em>key</em> is a key and <em>message</em> is a message representation, and delete the corresponding message. If the mailbox is empty, raise a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception. The message is represented as an instance of the appropriate format-specific <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> subclass unless a custom message factory was specified when the <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance was initialized.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.update"> <code class="descname">update</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.update" title="Permalink to this definition">¶</a></dt> <dd><p>Parameter <em>arg</em> should be a <em>key</em>-to-<em>message</em> mapping or an iterable of (<em>key</em>, <em>message</em>) pairs. Updates the mailbox so that, for each given <em>key</em> and <em>message</em>, the message corresponding to <em>key</em> is set to <em>message</em> as if by using <a class="reference internal" href="#mailbox.Mailbox.__setitem__" title="mailbox.Mailbox.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a>. As with <a class="reference internal" href="#mailbox.Mailbox.__setitem__" title="mailbox.Mailbox.__setitem__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__setitem__()</span></code></a>, each <em>key</em> must already correspond to a message in the mailbox or else a <a class="reference internal" href="exceptions.html#exceptions.KeyError" title="exceptions.KeyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">KeyError</span></code></a> exception will be raised, so in general it is incorrect for <em>arg</em> to be a <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Unlike with dictionaries, keyword arguments are not supported.</p> </div> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.flush"> <code class="descname">flush</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.flush" title="Permalink to this definition">¶</a></dt> <dd><p>Write any pending changes to the filesystem. For some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> subclasses, changes are always written immediately and <a class="reference internal" href="#mailbox.Mailbox.flush" title="mailbox.Mailbox.flush"><code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code></a> does nothing, but you should still make a habit of calling this method.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.lock" title="Permalink to this definition">¶</a></dt> <dd><p>Acquire an exclusive advisory lock on the mailbox so that other processes know not to modify it. An <a class="reference internal" href="#mailbox.ExternalClashError" title="mailbox.ExternalClashError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ExternalClashError</span></code></a> is raised if the lock is not available. The particular locking mechanisms used depend upon the mailbox format. You should <em>always</em> lock the mailbox before making any modifications to its contents.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Release the lock on the mailbox, if any.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Mailbox.close"> <code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Mailbox.close" title="Permalink to this definition">¶</a></dt> <dd><p>Flush the mailbox, unlock it if necessary, and close any open files. For some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> subclasses, this method does nothing.</p> </dd></dl> </dd></dl> <div class="section" id="maildir"> <span id="mailbox-maildir"></span><h3>18.4.1.1. <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a><a class="headerlink" href="#maildir" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.Maildir"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">Maildir</code><span class="sig-paren">(</span><em>dirname</em>, <em>factory=rfc822.Message</em>, <em>create=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> for mailboxes in Maildir format. Parameter <em>factory</em> is a callable object that accepts a file-like message representation (which behaves as if opened in binary mode) and returns a custom representation. If <em>factory</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> is used as the default message representation. If <em>create</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the mailbox is created if it does not exist.</p> <p>It is for historical reasons that <em>factory</em> defaults to <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">rfc822.Message</span></code></a> and that <em>dirname</em> is named as such rather than <em>path</em>. For a <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> instance that behaves like instances of other <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> subclasses, set <em>factory</em> to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> <p>Maildir is a directory-based mailbox format invented for the qmail mail transfer agent and now widely supported by other programs. Messages in a Maildir mailbox are stored in separate files within a common directory structure. This design allows Maildir mailboxes to be accessed and modified by multiple unrelated programs without data corruption, so file locking is unnecessary.</p> <p>Maildir mailboxes contain three subdirectories, namely: <code class="file docutils literal notranslate"><span class="pre">tmp</span></code>, <code class="file docutils literal notranslate"><span class="pre">new</span></code>, and <code class="file docutils literal notranslate"><span class="pre">cur</span></code>. Messages are created momentarily in the <code class="file docutils literal notranslate"><span class="pre">tmp</span></code> subdirectory and then moved to the <code class="file docutils literal notranslate"><span class="pre">new</span></code> subdirectory to finalize delivery. A mail user agent may subsequently move the message to the <code class="file docutils literal notranslate"><span class="pre">cur</span></code> subdirectory and store information about the state of the message in a special “info” section appended to its file name.</p> <p>Folders of the style introduced by the Courier mail transfer agent are also supported. Any subdirectory of the main mailbox is considered a folder if <code class="docutils literal notranslate"><span class="pre">'.'</span></code> is the first character in its name. Folder names are represented by <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> without the leading <code class="docutils literal notranslate"><span class="pre">'.'</span></code>. Each folder is itself a Maildir mailbox but should not contain other folders. Instead, a logical nesting is indicated using <code class="docutils literal notranslate"><span class="pre">'.'</span></code> to delimit levels, e.g., “Archived.2005.07”.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p>The Maildir specification requires the use of a colon (<code class="docutils literal notranslate"><span class="pre">':'</span></code>) in certain message file names. However, some operating systems do not permit this character in file names, If you wish to use a Maildir-like format on such an operating system, you should specify another character to use instead. The exclamation point (<code class="docutils literal notranslate"><span class="pre">'!'</span></code>) is a popular choice. For example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">mailbox</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">Maildir</span><span class="o">.</span><span class="n">colon</span> <span class="o">=</span> <span class="s1">'!'</span> </pre></div> </div> <p class="last">The <code class="xref py py-attr docutils literal notranslate"><span class="pre">colon</span></code> attribute may also be set on a per-instance basis.</p> </div> <p><a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> instances have all of the methods of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> in addition to the following:</p> <dl class="method"> <dt id="mailbox.Maildir.list_folders"> <code class="descname">list_folders</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.list_folders" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the names of all folders.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.get_folder"> <code class="descname">get_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.get_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Return a <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> instance representing the folder whose name is <em>folder</em>. A <a class="reference internal" href="#mailbox.NoSuchMailboxError" title="mailbox.NoSuchMailboxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoSuchMailboxError</span></code></a> exception is raised if the folder does not exist.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.add_folder"> <code class="descname">add_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.add_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Create a folder whose name is <em>folder</em> and return a <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> instance representing it.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.remove_folder"> <code class="descname">remove_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.remove_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the folder whose name is <em>folder</em>. If the folder contains any messages, a <a class="reference internal" href="#mailbox.NotEmptyError" title="mailbox.NotEmptyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotEmptyError</span></code></a> exception will be raised and the folder will not be deleted.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.clean"> <code class="descname">clean</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.clean" title="Permalink to this definition">¶</a></dt> <dd><p>Delete temporary files from the mailbox that have not been accessed in the last 36 hours. The Maildir specification says that mail-reading programs should do this occasionally.</p> </dd></dl> <p>Some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> methods implemented by <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> deserve special remarks:</p> <dl class="method"> <dt id="mailbox.Maildir.add"> <code class="descname">add</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.add" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Maildir.__setitem__"> <code class="descname">__setitem__</code><span class="sig-paren">(</span><em>key</em>, <em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.__setitem__" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Maildir.update"> <code class="descname">update</code><span class="sig-paren">(</span><em>arg</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.update" title="Permalink to this definition">¶</a></dt> <dd><div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">These methods generate unique file names based upon the current process ID. When using multiple threads, undetected name clashes may occur and cause corruption of the mailbox unless threads are coordinated to avoid using these methods to manipulate the same mailbox simultaneously.</p> </div> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.flush"> <code class="descname">flush</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.flush" title="Permalink to this definition">¶</a></dt> <dd><p>All changes to Maildir mailboxes are immediately applied, so this method does nothing.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.lock" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Maildir.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Maildir mailboxes do not support (or require) locking, so these methods do nothing.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.close"> <code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.close" title="Permalink to this definition">¶</a></dt> <dd><p><a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> instances do not keep any open files and the underlying mailboxes do not support locking, so this method does nothing.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Maildir.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Maildir.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>Depending upon the host platform, it may not be possible to modify or remove the underlying message while the returned file remains open.</p> </dd></dl> </dd></dl> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://www.qmail.org/man/man5/maildir.html">maildir man page from qmail</a></dt> <dd>The original specification of the format.</dd> <dt><a class="reference external" href="https://cr.yp.to/proto/maildir.html">Using maildir format</a></dt> <dd>Notes on Maildir by its inventor. Includes an updated name-creation scheme and details on “info” semantics.</dd> <dt><a class="reference external" href="http://www.courier-mta.org/maildir.html">maildir man page from Courier</a></dt> <dd>Another specification of the format. Describes a common extension for supporting folders.</dd> </dl> </div> </div> <div class="section" id="mbox"> <span id="mailbox-mbox"></span><h3>18.4.1.2. <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a><a class="headerlink" href="#mbox" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.mbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">mbox</code><span class="sig-paren">(</span><em>path</em>, <em>factory=None</em>, <em>create=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mbox" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> for mailboxes in mbox format. Parameter <em>factory</em> is a callable object that accepts a file-like message representation (which behaves as if opened in binary mode) and returns a custom representation. If <em>factory</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> is used as the default message representation. If <em>create</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the mailbox is created if it does not exist.</p> <p>The mbox format is the classic format for storing mail on Unix systems. All messages in an mbox mailbox are stored in a single file with the beginning of each message indicated by a line whose first five characters are “From “.</p> <p>Several variations of the mbox format exist to address perceived shortcomings in the original. In the interest of compatibility, <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a> implements the original format, which is sometimes referred to as <em class="dfn">mboxo</em>. This means that the <em class="mailheader">Content-Length</em> header, if present, is ignored and that any occurrences of “From ” at the beginning of a line in a message body are transformed to “>From ” when storing the message, although occurrences of “>From ” are not transformed to “From ” when reading the message.</p> <p>Some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> methods implemented by <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a> deserve special remarks:</p> <dl class="method"> <dt id="mailbox.mbox.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mbox.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>Using the file after calling <code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> on the <a class="reference internal" href="#mailbox.mbox" title="mailbox.mbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">mbox</span></code></a> instance may yield unpredictable results or raise an exception.</p> </dd></dl> <dl class="method"> <dt id="mailbox.mbox.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mbox.lock" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.mbox.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mbox.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Three locking mechanisms are used—dot locking and, if available, the <code class="xref c c-func docutils literal notranslate"><span class="pre">flock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">lockf()</span></code> system calls.</p> </dd></dl> </dd></dl> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://www.qmail.org/man/man5/mbox.html">mbox man page from qmail</a></dt> <dd>A specification of the format and its variations.</dd> <dt><a class="reference external" href="http://www.tin.org/bin/man.cgi?section=5&topic=mbox">mbox man page from tin</a></dt> <dd>Another specification of the format, with details on locking.</dd> <dt><a class="reference external" href="https://www.jwz.org/doc/content-length.html">Configuring Netscape Mail on Unix: Why The Content-Length Format is Bad</a></dt> <dd>An argument for using the original mbox format rather than a variation.</dd> <dt><a class="reference external" href="https://www.loc.gov/preservation/digital/formats/fdd/fdd000383.shtml">“mbox” is a family of several mutually incompatible mailbox formats</a></dt> <dd>A history of mbox variations.</dd> </dl> </div> </div> <div class="section" id="mh"> <span id="mailbox-mh"></span><h3>18.4.1.3. <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a><a class="headerlink" href="#mh" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.MH"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MH</code><span class="sig-paren">(</span><em>path</em>, <em>factory=None</em>, <em>create=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> for mailboxes in MH format. Parameter <em>factory</em> is a callable object that accepts a file-like message representation (which behaves as if opened in binary mode) and returns a custom representation. If <em>factory</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> is used as the default message representation. If <em>create</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the mailbox is created if it does not exist.</p> <p>MH is a directory-based mailbox format invented for the MH Message Handling System, a mail user agent. Each message in an MH mailbox resides in its own file. An MH mailbox may contain other MH mailboxes (called <em class="dfn">folders</em>) in addition to messages. Folders may be nested indefinitely. MH mailboxes also support <em class="dfn">sequences</em>, which are named lists used to logically group messages without moving them to sub-folders. Sequences are defined in a file called <code class="file docutils literal notranslate"><span class="pre">.mh_sequences</span></code> in each folder.</p> <p>The <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> class manipulates MH mailboxes, but it does not attempt to emulate all of <strong class="program">mh</strong>’s behaviors. In particular, it does not modify and is not affected by the <code class="file docutils literal notranslate"><span class="pre">context</span></code> or <code class="file docutils literal notranslate"><span class="pre">.mh_profile</span></code> files that are used by <strong class="program">mh</strong> to store its state and configuration.</p> <p><a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> instances have all of the methods of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> in addition to the following:</p> <dl class="method"> <dt id="mailbox.MH.list_folders"> <code class="descname">list_folders</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.list_folders" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the names of all folders.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.get_folder"> <code class="descname">get_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.get_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Return an <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> instance representing the folder whose name is <em>folder</em>. A <a class="reference internal" href="#mailbox.NoSuchMailboxError" title="mailbox.NoSuchMailboxError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NoSuchMailboxError</span></code></a> exception is raised if the folder does not exist.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.add_folder"> <code class="descname">add_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.add_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Create a folder whose name is <em>folder</em> and return an <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> instance representing it.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.remove_folder"> <code class="descname">remove_folder</code><span class="sig-paren">(</span><em>folder</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.remove_folder" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the folder whose name is <em>folder</em>. If the folder contains any messages, a <a class="reference internal" href="#mailbox.NotEmptyError" title="mailbox.NotEmptyError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotEmptyError</span></code></a> exception will be raised and the folder will not be deleted.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.get_sequences"> <code class="descname">get_sequences</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.get_sequences" title="Permalink to this definition">¶</a></dt> <dd><p>Return a dictionary of sequence names mapped to key lists. If there are no sequences, the empty dictionary is returned.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.set_sequences"> <code class="descname">set_sequences</code><span class="sig-paren">(</span><em>sequences</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.set_sequences" title="Permalink to this definition">¶</a></dt> <dd><p>Re-define the sequences that exist in the mailbox based upon <em>sequences</em>, a dictionary of names mapped to key lists, like returned by <a class="reference internal" href="#mailbox.MH.get_sequences" title="mailbox.MH.get_sequences"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_sequences()</span></code></a>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.pack"> <code class="descname">pack</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.pack" title="Permalink to this definition">¶</a></dt> <dd><p>Rename messages in the mailbox as necessary to eliminate gaps in numbering. Entries in the sequences list are updated correspondingly.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Already-issued keys are invalidated by this operation and should not be subsequently used.</p> </div> </dd></dl> <p>Some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> methods implemented by <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> deserve special remarks:</p> <dl class="method"> <dt id="mailbox.MH.remove"> <code class="descname">remove</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.remove" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.MH.__delitem__"> <code class="descname">__delitem__</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.__delitem__" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.MH.discard"> <code class="descname">discard</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.discard" title="Permalink to this definition">¶</a></dt> <dd><p>These methods immediately delete the message. The MH convention of marking a message for deletion by prepending a comma to its name is not used.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.lock" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.MH.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Three locking mechanisms are used—dot locking and, if available, the <code class="xref c c-func docutils literal notranslate"><span class="pre">flock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">lockf()</span></code> system calls. For MH mailboxes, locking the mailbox means locking the <code class="file docutils literal notranslate"><span class="pre">.mh_sequences</span></code> file and, only for the duration of any operations that affect them, locking individual message files.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>Depending upon the host platform, it may not be possible to remove the underlying message while the returned file remains open.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.flush"> <code class="descname">flush</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.flush" title="Permalink to this definition">¶</a></dt> <dd><p>All changes to MH mailboxes are immediately applied, so this method does nothing.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MH.close"> <code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MH.close" title="Permalink to this definition">¶</a></dt> <dd><p><a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> instances do not keep any open files, so this method is equivalent to <a class="reference internal" href="#mailbox.MH.unlock" title="mailbox.MH.unlock"><code class="xref py py-meth docutils literal notranslate"><span class="pre">unlock()</span></code></a>.</p> </dd></dl> </dd></dl> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://www.nongnu.org/nmh/">nmh - Message Handling System</a></dt> <dd>Home page of <strong class="program">nmh</strong>, an updated version of the original <strong class="program">mh</strong>.</dd> <dt><a class="reference external" href="http://rand-mh.sourceforge.net/book/">MH & nmh: Email for Users & Programmers</a></dt> <dd>A GPL-licensed book on <strong class="program">mh</strong> and <strong class="program">nmh</strong>, with some information on the mailbox format.</dd> </dl> </div> </div> <div class="section" id="babyl"> <span id="mailbox-babyl"></span><h3>18.4.1.4. <a class="reference internal" href="#mailbox.Babyl" title="mailbox.Babyl"><code class="xref py py-class docutils literal notranslate"><span class="pre">Babyl</span></code></a><a class="headerlink" href="#babyl" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.Babyl"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">Babyl</code><span class="sig-paren">(</span><em>path</em>, <em>factory=None</em>, <em>create=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Babyl" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> for mailboxes in Babyl format. Parameter <em>factory</em> is a callable object that accepts a file-like message representation (which behaves as if opened in binary mode) and returns a custom representation. If <em>factory</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> is used as the default message representation. If <em>create</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the mailbox is created if it does not exist.</p> <p>Babyl is a single-file mailbox format used by the Rmail mail user agent included with Emacs. The beginning of a message is indicated by a line containing the two characters Control-Underscore (<code class="docutils literal notranslate"><span class="pre">'\037'</span></code>) and Control-L (<code class="docutils literal notranslate"><span class="pre">'\014'</span></code>). The end of a message is indicated by the start of the next message or, in the case of the last message, a line containing a Control-Underscore (<code class="docutils literal notranslate"><span class="pre">'\037'</span></code>) character.</p> <p>Messages in a Babyl mailbox have two sets of headers, original headers and so-called visible headers. Visible headers are typically a subset of the original headers that have been reformatted or abridged to be more attractive. Each message in a Babyl mailbox also has an accompanying list of <em class="dfn">labels</em>, or short strings that record extra information about the message, and a list of all user-defined labels found in the mailbox is kept in the Babyl options section.</p> <p><a class="reference internal" href="#mailbox.Babyl" title="mailbox.Babyl"><code class="xref py py-class docutils literal notranslate"><span class="pre">Babyl</span></code></a> instances have all of the methods of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> in addition to the following:</p> <dl class="method"> <dt id="mailbox.Babyl.get_labels"> <code class="descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Babyl.get_labels" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the names of all user-defined labels used in the mailbox.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The actual messages are inspected to determine which labels exist in the mailbox rather than consulting the list of labels in the Babyl options section, but the Babyl section is updated whenever the mailbox is modified.</p> </div> </dd></dl> <p>Some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> methods implemented by <a class="reference internal" href="#mailbox.Babyl" title="mailbox.Babyl"><code class="xref py py-class docutils literal notranslate"><span class="pre">Babyl</span></code></a> deserve special remarks:</p> <dl class="method"> <dt id="mailbox.Babyl.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Babyl.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>In Babyl mailboxes, the headers of a message are not stored contiguously with the body of the message. To generate a file-like representation, the headers and body are copied together into a <a class="reference internal" href="stringio.html#StringIO.StringIO" title="StringIO.StringIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">StringIO</span></code></a> instance (from the <a class="reference internal" href="stringio.html#module-StringIO" title="StringIO: Read and write strings as if they were files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">StringIO</span></code></a> module), which has an API identical to that of a file. As a result, the file-like object is truly independent of the underlying mailbox but does not save memory compared to a string representation.</p> </dd></dl> <dl class="method"> <dt id="mailbox.Babyl.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Babyl.lock" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.Babyl.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Babyl.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Three locking mechanisms are used—dot locking and, if available, the <code class="xref c c-func docutils literal notranslate"><span class="pre">flock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">lockf()</span></code> system calls.</p> </dd></dl> </dd></dl> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="https://quimby.gnus.org/notes/BABYL">Format of Version 5 Babyl Files</a></dt> <dd>A specification of the Babyl format.</dd> <dt><a class="reference external" href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Rmail.html">Reading Mail with Rmail</a></dt> <dd>The Rmail manual, with some information on Babyl semantics.</dd> </dl> </div> </div> <div class="section" id="mmdf"> <span id="mailbox-mmdf"></span><h3>18.4.1.5. <a class="reference internal" href="#mailbox.MMDF" title="mailbox.MMDF"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDF</span></code></a><a class="headerlink" href="#mmdf" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.MMDF"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MMDF</code><span class="sig-paren">(</span><em>path</em>, <em>factory=None</em>, <em>create=True</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDF" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> for mailboxes in MMDF format. Parameter <em>factory</em> is a callable object that accepts a file-like message representation (which behaves as if opened in binary mode) and returns a custom representation. If <em>factory</em> is <code class="docutils literal notranslate"><span class="pre">None</span></code>, <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> is used as the default message representation. If <em>create</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the mailbox is created if it does not exist.</p> <p>MMDF is a single-file mailbox format invented for the Multichannel Memorandum Distribution Facility, a mail transfer agent. Each message is in the same form as an mbox message but is bracketed before and after by lines containing four Control-A (<code class="docutils literal notranslate"><span class="pre">'\001'</span></code>) characters. As with the mbox format, the beginning of each message is indicated by a line whose first five characters are “From “, but additional occurrences of “From ” are not transformed to “>From ” when storing messages because the extra message separator lines prevent mistaking such occurrences for the starts of subsequent messages.</p> <p>Some <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> methods implemented by <a class="reference internal" href="#mailbox.MMDF" title="mailbox.MMDF"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDF</span></code></a> deserve special remarks:</p> <dl class="method"> <dt id="mailbox.MMDF.get_file"> <code class="descname">get_file</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDF.get_file" title="Permalink to this definition">¶</a></dt> <dd><p>Using the file after calling <code class="xref py py-meth docutils literal notranslate"><span class="pre">flush()</span></code> or <code class="xref py py-meth docutils literal notranslate"><span class="pre">close()</span></code> on the <a class="reference internal" href="#mailbox.MMDF" title="mailbox.MMDF"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDF</span></code></a> instance may yield unpredictable results or raise an exception.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDF.lock"> <code class="descname">lock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDF.lock" title="Permalink to this definition">¶</a></dt> <dt id="mailbox.MMDF.unlock"> <code class="descname">unlock</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDF.unlock" title="Permalink to this definition">¶</a></dt> <dd><p>Three locking mechanisms are used—dot locking and, if available, the <code class="xref c c-func docutils literal notranslate"><span class="pre">flock()</span></code> and <code class="xref c c-func docutils literal notranslate"><span class="pre">lockf()</span></code> system calls.</p> </dd></dl> </dd></dl> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://www.tin.org/bin/man.cgi?section=5&topic=mmdf">mmdf man page from tin</a></dt> <dd>A specification of MMDF format from the documentation of tin, a newsreader.</dd> <dt><a class="reference external" href="https://en.wikipedia.org/wiki/MMDF">MMDF</a></dt> <dd>A Wikipedia article describing the Multichannel Memorandum Distribution Facility.</dd> </dl> </div> </div> </div> <div class="section" id="message-objects"> <span id="mailbox-message-objects"></span><h2>18.4.2. <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> objects<a class="headerlink" href="#message-objects" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="mailbox.Message"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">Message</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.Message" title="Permalink to this definition">¶</a></dt> <dd><p>A subclass of the <a class="reference internal" href="email.message.html#module-email.message" title="email.message: The base class representing email messages."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email.message</span></code></a> module’s <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a>. Subclasses of <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">mailbox.Message</span></code></a> add mailbox-format-specific state and behavior.</p> <p>If <em>message</em> is omitted, the new instance is created in a default, empty state. If <em>message</em> is an <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a> instance, its contents are copied; furthermore, any format-specific information is converted insofar as possible if <em>message</em> is a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance. If <em>message</em> is a string or a file, it should contain an <span class="target" id="index-0"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a>-compliant message, which is read and parsed.</p> <p>The format-specific state and behaviors offered by subclasses vary, but in general it is only the properties that are not specific to a particular mailbox that are supported (although presumably the properties are specific to a particular mailbox format). For example, file offsets for single-file mailbox formats and file names for directory-based mailbox formats are not retained, because they are only applicable to the original mailbox. But state such as whether a message has been read by the user or marked as important is retained, because it applies to the message itself.</p> <p>There is no requirement that <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instances be used to represent messages retrieved using <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instances. In some situations, the time and memory required to generate <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> representations might not be acceptable. For such situations, <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instances also offer string and file-like representations, and a custom message factory may be specified when a <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> instance is initialized.</p> </dd></dl> <div class="section" id="maildirmessage"> <span id="mailbox-maildirmessage"></span><h3>18.4.2.1. <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a><a class="headerlink" href="#maildirmessage" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.MaildirMessage"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MaildirMessage</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage" title="Permalink to this definition">¶</a></dt> <dd><p>A message with Maildir-specific behaviors. Parameter <em>message</em> has the same meaning as with the <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> constructor.</p> <p>Typically, a mail user agent application moves all of the messages in the <code class="file docutils literal notranslate"><span class="pre">new</span></code> subdirectory to the <code class="file docutils literal notranslate"><span class="pre">cur</span></code> subdirectory after the first time the user opens and closes the mailbox, recording that the messages are old whether or not they’ve actually been read. Each message in <code class="file docutils literal notranslate"><span class="pre">cur</span></code> has an “info” section added to its file name to store information about its state. (Some mail readers may also add an “info” section to messages in <code class="file docutils literal notranslate"><span class="pre">new</span></code>.) The “info” section may take one of two forms: it may contain “2,” followed by a list of standardized flags (e.g., “2,FR”) or it may contain “1,” followed by so-called experimental information. Standard flags for Maildir messages are as follows:</p> <table border="1" class="docutils"> <colgroup> <col width="13%" /> <col width="19%" /> <col width="68%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Flag</th> <th class="head">Meaning</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>D</td> <td>Draft</td> <td>Under composition</td> </tr> <tr class="row-odd"><td>F</td> <td>Flagged</td> <td>Marked as important</td> </tr> <tr class="row-even"><td>P</td> <td>Passed</td> <td>Forwarded, resent, or bounced</td> </tr> <tr class="row-odd"><td>R</td> <td>Replied</td> <td>Replied to</td> </tr> <tr class="row-even"><td>S</td> <td>Seen</td> <td>Read</td> </tr> <tr class="row-odd"><td>T</td> <td>Trashed</td> <td>Marked for subsequent deletion</td> </tr> </tbody> </table> <p><a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instances offer the following methods:</p> <dl class="method"> <dt id="mailbox.MaildirMessage.get_subdir"> <code class="descname">get_subdir</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.get_subdir" title="Permalink to this definition">¶</a></dt> <dd><p>Return either “new” (if the message should be stored in the <code class="file docutils literal notranslate"><span class="pre">new</span></code> subdirectory) or “cur” (if the message should be stored in the <code class="file docutils literal notranslate"><span class="pre">cur</span></code> subdirectory).</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">A message is typically moved from <code class="file docutils literal notranslate"><span class="pre">new</span></code> to <code class="file docutils literal notranslate"><span class="pre">cur</span></code> after its mailbox has been accessed, whether or not the message is has been read. A message <code class="docutils literal notranslate"><span class="pre">msg</span></code> has been read if <code class="docutils literal notranslate"><span class="pre">"S"</span> <span class="pre">in</span> <span class="pre">msg.get_flags()</span></code> is <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p> </div> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.set_subdir"> <code class="descname">set_subdir</code><span class="sig-paren">(</span><em>subdir</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.set_subdir" title="Permalink to this definition">¶</a></dt> <dd><p>Set the subdirectory the message should be stored in. Parameter <em>subdir</em> must be either “new” or “cur”.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.get_flags"> <code class="descname">get_flags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.get_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string specifying the flags that are currently set. If the message complies with the standard Maildir format, the result is the concatenation in alphabetical order of zero or one occurrence of each of <code class="docutils literal notranslate"><span class="pre">'D'</span></code>, <code class="docutils literal notranslate"><span class="pre">'F'</span></code>, <code class="docutils literal notranslate"><span class="pre">'P'</span></code>, <code class="docutils literal notranslate"><span class="pre">'R'</span></code>, <code class="docutils literal notranslate"><span class="pre">'S'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'T'</span></code>. The empty string is returned if no flags are set or if “info” contains experimental semantics.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.set_flags"> <code class="descname">set_flags</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.set_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flags specified by <em>flags</em> and unset all others.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.add_flag"> <code class="descname">add_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.add_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flag(s) specified by <em>flag</em> without changing other flags. To add more than one flag at a time, <em>flag</em> may be a string of more than one character. The current “info” is overwritten whether or not it contains experimental information rather than flags.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.remove_flag"> <code class="descname">remove_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.remove_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Unset the flag(s) specified by <em>flag</em> without changing other flags. To remove more than one flag at a time, <em>flag</em> maybe a string of more than one character. If “info” contains experimental information rather than flags, the current “info” is not modified.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.get_date"> <code class="descname">get_date</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.get_date" title="Permalink to this definition">¶</a></dt> <dd><p>Return the delivery date of the message as a floating-point number representing seconds since the epoch.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.set_date"> <code class="descname">set_date</code><span class="sig-paren">(</span><em>date</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.set_date" title="Permalink to this definition">¶</a></dt> <dd><p>Set the delivery date of the message to <em>date</em>, a floating-point number representing seconds since the epoch.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.get_info"> <code class="descname">get_info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.get_info" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string containing the “info” for a message. This is useful for accessing and modifying “info” that is experimental (i.e., not a list of flags).</p> </dd></dl> <dl class="method"> <dt id="mailbox.MaildirMessage.set_info"> <code class="descname">set_info</code><span class="sig-paren">(</span><em>info</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MaildirMessage.set_info" title="Permalink to this definition">¶</a></dt> <dd><p>Set “info” to <em>info</em>, which should be a string.</p> </dd></dl> </dd></dl> <p>When a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance, the <em class="mailheader">Status</em> and <em class="mailheader">X-Status</em> headers are omitted and the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="30%" /> <col width="70%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“cur” subdirectory</td> <td>O flag</td> </tr> <tr class="row-odd"><td>F flag</td> <td>F flag</td> </tr> <tr class="row-even"><td>R flag</td> <td>A flag</td> </tr> <tr class="row-odd"><td>S flag</td> <td>R flag</td> </tr> <tr class="row-even"><td>T flag</td> <td>D flag</td> </tr> </tbody> </table> <p>When a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="54%" /> <col width="46%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“cur” subdirectory</td> <td>“unseen” sequence</td> </tr> <tr class="row-odd"><td>“cur” subdirectory and S flag</td> <td>no “unseen” sequence</td> </tr> <tr class="row-even"><td>F flag</td> <td>“flagged” sequence</td> </tr> <tr class="row-odd"><td>R flag</td> <td>“replied” sequence</td> </tr> </tbody> </table> <p>When a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="50%" /> <col width="50%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“cur” subdirectory</td> <td>“unseen” label</td> </tr> <tr class="row-odd"><td>“cur” subdirectory and S flag</td> <td>no “unseen” label</td> </tr> <tr class="row-even"><td>P flag</td> <td>“forwarded” or “resent” label</td> </tr> <tr class="row-odd"><td>R flag</td> <td>“answered” label</td> </tr> <tr class="row-even"><td>T flag</td> <td>“deleted” label</td> </tr> </tbody> </table> </div> <div class="section" id="mboxmessage"> <span id="mailbox-mboxmessage"></span><h3>18.4.2.2. <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a><a class="headerlink" href="#mboxmessage" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.mboxMessage"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">mboxMessage</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage" title="Permalink to this definition">¶</a></dt> <dd><p>A message with mbox-specific behaviors. Parameter <em>message</em> has the same meaning as with the <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> constructor.</p> <p>Messages in an mbox mailbox are stored together in a single file. The sender’s envelope address and the time of delivery are typically stored in a line beginning with “From ” that is used to indicate the start of a message, though there is considerable variation in the exact format of this data among mbox implementations. Flags that indicate the state of the message, such as whether it has been read or marked as important, are typically stored in <em class="mailheader">Status</em> and <em class="mailheader">X-Status</em> headers.</p> <p>Conventional flags for mbox messages are as follows:</p> <table border="1" class="docutils"> <colgroup> <col width="13%" /> <col width="21%" /> <col width="67%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Flag</th> <th class="head">Meaning</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R</td> <td>Read</td> <td>Read</td> </tr> <tr class="row-odd"><td>O</td> <td>Old</td> <td>Previously detected by MUA</td> </tr> <tr class="row-even"><td>D</td> <td>Deleted</td> <td>Marked for subsequent deletion</td> </tr> <tr class="row-odd"><td>F</td> <td>Flagged</td> <td>Marked as important</td> </tr> <tr class="row-even"><td>A</td> <td>Answered</td> <td>Replied to</td> </tr> </tbody> </table> <p>The “R” and “O” flags are stored in the <em class="mailheader">Status</em> header, and the “D”, “F”, and “A” flags are stored in the <em class="mailheader">X-Status</em> header. The flags and headers typically appear in the order mentioned.</p> <p><a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instances offer the following methods:</p> <dl class="method"> <dt id="mailbox.mboxMessage.get_from"> <code class="descname">get_from</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.get_from" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representing the “From ” line that marks the start of the message in an mbox mailbox. The leading “From ” and the trailing newline are excluded.</p> </dd></dl> <dl class="method"> <dt id="mailbox.mboxMessage.set_from"> <code class="descname">set_from</code><span class="sig-paren">(</span><em>from_</em>, <em>time_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.set_from" title="Permalink to this definition">¶</a></dt> <dd><p>Set the “From ” line to <em>from_</em>, which should be specified without a leading “From ” or trailing newline. For convenience, <em>time_</em> may be specified and will be formatted appropriately and appended to <em>from_</em>. If <em>time_</em> is specified, it should be a <a class="reference internal" href="time.html#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">time.struct_time</span></code></a> instance, a tuple suitable for passing to <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">time.strftime()</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">True</span></code> (to use <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a>).</p> </dd></dl> <dl class="method"> <dt id="mailbox.mboxMessage.get_flags"> <code class="descname">get_flags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.get_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string specifying the flags that are currently set. If the message complies with the conventional format, the result is the concatenation in the following order of zero or one occurrence of each of <code class="docutils literal notranslate"><span class="pre">'R'</span></code>, <code class="docutils literal notranslate"><span class="pre">'O'</span></code>, <code class="docutils literal notranslate"><span class="pre">'D'</span></code>, <code class="docutils literal notranslate"><span class="pre">'F'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'A'</span></code>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.mboxMessage.set_flags"> <code class="descname">set_flags</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.set_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flags specified by <em>flags</em> and unset all others. Parameter <em>flags</em> should be the concatenation in any order of zero or more occurrences of each of <code class="docutils literal notranslate"><span class="pre">'R'</span></code>, <code class="docutils literal notranslate"><span class="pre">'O'</span></code>, <code class="docutils literal notranslate"><span class="pre">'D'</span></code>, <code class="docutils literal notranslate"><span class="pre">'F'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'A'</span></code>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.mboxMessage.add_flag"> <code class="descname">add_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.add_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flag(s) specified by <em>flag</em> without changing other flags. To add more than one flag at a time, <em>flag</em> may be a string of more than one character.</p> </dd></dl> <dl class="method"> <dt id="mailbox.mboxMessage.remove_flag"> <code class="descname">remove_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.mboxMessage.remove_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Unset the flag(s) specified by <em>flag</em> without changing other flags. To remove more than one flag at a time, <em>flag</em> maybe a string of more than one character.</p> </dd></dl> </dd></dl> <p>When an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance, a “From ” line is generated based upon the <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance’s delivery date, and the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="35%" /> <col width="65%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag</td> <td>S flag</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“cur” subdirectory</td> </tr> <tr class="row-even"><td>D flag</td> <td>T flag</td> </tr> <tr class="row-odd"><td>F flag</td> <td>F flag</td> </tr> <tr class="row-even"><td>A flag</td> <td>R flag</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="42%" /> <col width="58%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag and O flag</td> <td>no “unseen” sequence</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“unseen” sequence</td> </tr> <tr class="row-even"><td>F flag</td> <td>“flagged” sequence</td> </tr> <tr class="row-odd"><td>A flag</td> <td>“replied” sequence</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="40%" /> <col width="60%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag and O flag</td> <td>no “unseen” label</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“unseen” label</td> </tr> <tr class="row-even"><td>D flag</td> <td>“deleted” label</td> </tr> <tr class="row-odd"><td>A flag</td> <td>“answered” label</td> </tr> </tbody> </table> <p>When a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance, the “From ” line is copied and all flags directly correspond:</p> <table border="1" class="docutils"> <colgroup> <col width="38%" /> <col width="62%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag</td> <td>R flag</td> </tr> <tr class="row-odd"><td>O flag</td> <td>O flag</td> </tr> <tr class="row-even"><td>D flag</td> <td>D flag</td> </tr> <tr class="row-odd"><td>F flag</td> <td>F flag</td> </tr> <tr class="row-even"><td>A flag</td> <td>A flag</td> </tr> </tbody> </table> </div> <div class="section" id="mhmessage"> <span id="mailbox-mhmessage"></span><h3>18.4.2.3. <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a><a class="headerlink" href="#mhmessage" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.MHMessage"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MHMessage</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMessage" title="Permalink to this definition">¶</a></dt> <dd><p>A message with MH-specific behaviors. Parameter <em>message</em> has the same meaning as with the <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> constructor.</p> <p>MH messages do not support marks or flags in the traditional sense, but they do support sequences, which are logical groupings of arbitrary messages. Some mail reading programs (although not the standard <strong class="program">mh</strong> and <strong class="program">nmh</strong>) use sequences in much the same way flags are used with other formats, as follows:</p> <table border="1" class="docutils"> <colgroup> <col width="19%" /> <col width="81%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Sequence</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>unseen</td> <td>Not read, but previously detected by MUA</td> </tr> <tr class="row-odd"><td>replied</td> <td>Replied to</td> </tr> <tr class="row-even"><td>flagged</td> <td>Marked as important</td> </tr> </tbody> </table> <p><a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instances offer the following methods:</p> <dl class="method"> <dt id="mailbox.MHMessage.get_sequences"> <code class="descname">get_sequences</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMessage.get_sequences" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of the names of sequences that include this message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MHMessage.set_sequences"> <code class="descname">set_sequences</code><span class="sig-paren">(</span><em>sequences</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMessage.set_sequences" title="Permalink to this definition">¶</a></dt> <dd><p>Set the list of sequences that include this message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MHMessage.add_sequence"> <code class="descname">add_sequence</code><span class="sig-paren">(</span><em>sequence</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMessage.add_sequence" title="Permalink to this definition">¶</a></dt> <dd><p>Add <em>sequence</em> to the list of sequences that include this message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MHMessage.remove_sequence"> <code class="descname">remove_sequence</code><span class="sig-paren">(</span><em>sequence</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMessage.remove_sequence" title="Permalink to this definition">¶</a></dt> <dd><p>Remove <em>sequence</em> from the list of sequences that include this message.</p> </dd></dl> </dd></dl> <p>When an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="39%" /> <col width="61%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” sequence</td> <td>no S flag</td> </tr> <tr class="row-odd"><td>“replied” sequence</td> <td>R flag</td> </tr> <tr class="row-even"><td>“flagged” sequence</td> <td>F flag</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance, the <em class="mailheader">Status</em> and <em class="mailheader">X-Status</em> headers are omitted and the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="30%" /> <col width="70%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” sequence</td> <td>no R flag</td> </tr> <tr class="row-odd"><td>“replied” sequence</td> <td>A flag</td> </tr> <tr class="row-even"><td>“flagged” sequence</td> <td>F flag</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="41%" /> <col width="59%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” sequence</td> <td>“unseen” label</td> </tr> <tr class="row-odd"><td>“replied” sequence</td> <td>“answered” label</td> </tr> </tbody> </table> </div> <div class="section" id="babylmessage"> <span id="mailbox-babylmessage"></span><h3>18.4.2.4. <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a><a class="headerlink" href="#babylmessage" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.BabylMessage"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">BabylMessage</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage" title="Permalink to this definition">¶</a></dt> <dd><p>A message with Babyl-specific behaviors. Parameter <em>message</em> has the same meaning as with the <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> constructor.</p> <p>Certain message labels, called <em class="dfn">attributes</em>, are defined by convention to have special meanings. The attributes are as follows:</p> <table border="1" class="docutils"> <colgroup> <col width="21%" /> <col width="79%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Label</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>unseen</td> <td>Not read, but previously detected by MUA</td> </tr> <tr class="row-odd"><td>deleted</td> <td>Marked for subsequent deletion</td> </tr> <tr class="row-even"><td>filed</td> <td>Copied to another file or mailbox</td> </tr> <tr class="row-odd"><td>answered</td> <td>Replied to</td> </tr> <tr class="row-even"><td>forwarded</td> <td>Forwarded</td> </tr> <tr class="row-odd"><td>edited</td> <td>Modified by the user</td> </tr> <tr class="row-even"><td>resent</td> <td>Resent</td> </tr> </tbody> </table> <p>By default, Rmail displays only visible headers. The <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> class, though, uses the original headers because they are more complete. Visible headers may be accessed explicitly if desired.</p> <p><a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instances offer the following methods:</p> <dl class="method"> <dt id="mailbox.BabylMessage.get_labels"> <code class="descname">get_labels</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.get_labels" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list of labels on the message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.set_labels"> <code class="descname">set_labels</code><span class="sig-paren">(</span><em>labels</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.set_labels" title="Permalink to this definition">¶</a></dt> <dd><p>Set the list of labels on the message to <em>labels</em>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.add_label"> <code class="descname">add_label</code><span class="sig-paren">(</span><em>label</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.add_label" title="Permalink to this definition">¶</a></dt> <dd><p>Add <em>label</em> to the list of labels on the message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.remove_label"> <code class="descname">remove_label</code><span class="sig-paren">(</span><em>label</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.remove_label" title="Permalink to this definition">¶</a></dt> <dd><p>Remove <em>label</em> from the list of labels on the message.</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.get_visible"> <code class="descname">get_visible</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.get_visible" title="Permalink to this definition">¶</a></dt> <dd><p>Return an <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance whose headers are the message’s visible headers and whose body is empty.</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.set_visible"> <code class="descname">set_visible</code><span class="sig-paren">(</span><em>visible</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.set_visible" title="Permalink to this definition">¶</a></dt> <dd><p>Set the message’s visible headers to be the same as the headers in <em>message</em>. Parameter <em>visible</em> should be a <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> instance, an <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">email.message.Message</span></code></a> instance, a string, or a file-like object (which should be open in text mode).</p> </dd></dl> <dl class="method"> <dt id="mailbox.BabylMessage.update_visible"> <code class="descname">update_visible</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMessage.update_visible" title="Permalink to this definition">¶</a></dt> <dd><p>When a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance’s original headers are modified, the visible headers are not automatically modified to correspond. This method updates the visible headers as follows: each visible header with a corresponding original header is set to the value of the original header, each visible header without a corresponding original header is removed, and any of <em class="mailheader">Date</em>, <em class="mailheader">From</em>, <em class="mailheader">Reply-To</em>, <em class="mailheader">To</em>, <em class="mailheader">CC</em>, and <em class="mailheader">Subject</em> that are present in the original headers but not the visible headers are added to the visible headers.</p> </dd></dl> </dd></dl> <p>When a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="38%" /> <col width="62%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” label</td> <td>no S flag</td> </tr> <tr class="row-odd"><td>“deleted” label</td> <td>T flag</td> </tr> <tr class="row-even"><td>“answered” label</td> <td>R flag</td> </tr> <tr class="row-odd"><td>“forwarded” label</td> <td>P flag</td> </tr> </tbody> </table> <p>When a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance, the <em class="mailheader">Status</em> and <em class="mailheader">X-Status</em> headers are omitted and the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="28%" /> <col width="72%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> or <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” label</td> <td>no R flag</td> </tr> <tr class="row-odd"><td>“deleted” label</td> <td>D flag</td> </tr> <tr class="row-even"><td>“answered” label</td> <td>A flag</td> </tr> </tbody> </table> <p>When a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="41%" /> <col width="59%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>“unseen” label</td> <td>“unseen” sequence</td> </tr> <tr class="row-odd"><td>“answered” label</td> <td>“replied” sequence</td> </tr> </tbody> </table> </div> <div class="section" id="mmdfmessage"> <span id="mailbox-mmdfmessage"></span><h3>18.4.2.5. <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a><a class="headerlink" href="#mmdfmessage" title="Permalink to this headline">¶</a></h3> <dl class="class"> <dt id="mailbox.MMDFMessage"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MMDFMessage</code><span class="sig-paren">(</span><span class="optional">[</span><em>message</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage" title="Permalink to this definition">¶</a></dt> <dd><p>A message with MMDF-specific behaviors. Parameter <em>message</em> has the same meaning as with the <a class="reference internal" href="#mailbox.Message" title="mailbox.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">Message</span></code></a> constructor.</p> <p>As with message in an mbox mailbox, MMDF messages are stored with the sender’s address and the delivery date in an initial line beginning with “From “. Likewise, flags that indicate the state of the message are typically stored in <em class="mailheader">Status</em> and <em class="mailheader">X-Status</em> headers.</p> <p>Conventional flags for MMDF messages are identical to those of mbox message and are as follows:</p> <table border="1" class="docutils"> <colgroup> <col width="13%" /> <col width="21%" /> <col width="67%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Flag</th> <th class="head">Meaning</th> <th class="head">Explanation</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R</td> <td>Read</td> <td>Read</td> </tr> <tr class="row-odd"><td>O</td> <td>Old</td> <td>Previously detected by MUA</td> </tr> <tr class="row-even"><td>D</td> <td>Deleted</td> <td>Marked for subsequent deletion</td> </tr> <tr class="row-odd"><td>F</td> <td>Flagged</td> <td>Marked as important</td> </tr> <tr class="row-even"><td>A</td> <td>Answered</td> <td>Replied to</td> </tr> </tbody> </table> <p>The “R” and “O” flags are stored in the <em class="mailheader">Status</em> header, and the “D”, “F”, and “A” flags are stored in the <em class="mailheader">X-Status</em> header. The flags and headers typically appear in the order mentioned.</p> <p><a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instances offer the following methods, which are identical to those offered by <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a>:</p> <dl class="method"> <dt id="mailbox.MMDFMessage.get_from"> <code class="descname">get_from</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.get_from" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representing the “From ” line that marks the start of the message in an mbox mailbox. The leading “From ” and the trailing newline are excluded.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDFMessage.set_from"> <code class="descname">set_from</code><span class="sig-paren">(</span><em>from_</em>, <em>time_=None</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.set_from" title="Permalink to this definition">¶</a></dt> <dd><p>Set the “From ” line to <em>from_</em>, which should be specified without a leading “From ” or trailing newline. For convenience, <em>time_</em> may be specified and will be formatted appropriately and appended to <em>from_</em>. If <em>time_</em> is specified, it should be a <a class="reference internal" href="time.html#time.struct_time" title="time.struct_time"><code class="xref py py-class docutils literal notranslate"><span class="pre">time.struct_time</span></code></a> instance, a tuple suitable for passing to <a class="reference internal" href="time.html#time.strftime" title="time.strftime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">time.strftime()</span></code></a>, or <code class="docutils literal notranslate"><span class="pre">True</span></code> (to use <a class="reference internal" href="time.html#time.gmtime" title="time.gmtime"><code class="xref py py-meth docutils literal notranslate"><span class="pre">time.gmtime()</span></code></a>).</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDFMessage.get_flags"> <code class="descname">get_flags</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.get_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string specifying the flags that are currently set. If the message complies with the conventional format, the result is the concatenation in the following order of zero or one occurrence of each of <code class="docutils literal notranslate"><span class="pre">'R'</span></code>, <code class="docutils literal notranslate"><span class="pre">'O'</span></code>, <code class="docutils literal notranslate"><span class="pre">'D'</span></code>, <code class="docutils literal notranslate"><span class="pre">'F'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'A'</span></code>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDFMessage.set_flags"> <code class="descname">set_flags</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.set_flags" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flags specified by <em>flags</em> and unset all others. Parameter <em>flags</em> should be the concatenation in any order of zero or more occurrences of each of <code class="docutils literal notranslate"><span class="pre">'R'</span></code>, <code class="docutils literal notranslate"><span class="pre">'O'</span></code>, <code class="docutils literal notranslate"><span class="pre">'D'</span></code>, <code class="docutils literal notranslate"><span class="pre">'F'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'A'</span></code>.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDFMessage.add_flag"> <code class="descname">add_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.add_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flag(s) specified by <em>flag</em> without changing other flags. To add more than one flag at a time, <em>flag</em> may be a string of more than one character.</p> </dd></dl> <dl class="method"> <dt id="mailbox.MMDFMessage.remove_flag"> <code class="descname">remove_flag</code><span class="sig-paren">(</span><em>flag</em><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MMDFMessage.remove_flag" title="Permalink to this definition">¶</a></dt> <dd><p>Unset the flag(s) specified by <em>flag</em> without changing other flags. To remove more than one flag at a time, <em>flag</em> maybe a string of more than one character.</p> </dd></dl> </dd></dl> <p>When an <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance, a “From ” line is generated based upon the <a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> instance’s delivery date, and the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="35%" /> <col width="65%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MaildirMessage" title="mailbox.MaildirMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag</td> <td>S flag</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“cur” subdirectory</td> </tr> <tr class="row-even"><td>D flag</td> <td>T flag</td> </tr> <tr class="row-odd"><td>F flag</td> <td>F flag</td> </tr> <tr class="row-even"><td>A flag</td> <td>R flag</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="42%" /> <col width="58%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.MHMessage" title="mailbox.MHMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MHMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag and O flag</td> <td>no “unseen” sequence</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“unseen” sequence</td> </tr> <tr class="row-even"><td>F flag</td> <td>“flagged” sequence</td> </tr> <tr class="row-odd"><td>A flag</td> <td>“replied” sequence</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance is created based upon a <a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> instance, the following conversions take place:</p> <table border="1" class="docutils"> <colgroup> <col width="40%" /> <col width="60%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.BabylMessage" title="mailbox.BabylMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag and O flag</td> <td>no “unseen” label</td> </tr> <tr class="row-odd"><td>O flag</td> <td>“unseen” label</td> </tr> <tr class="row-even"><td>D flag</td> <td>“deleted” label</td> </tr> <tr class="row-odd"><td>A flag</td> <td>“answered” label</td> </tr> </tbody> </table> <p>When an <a class="reference internal" href="#mailbox.MMDFMessage" title="mailbox.MMDFMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a> instance is created based upon an <a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> instance, the “From ” line is copied and all flags directly correspond:</p> <table border="1" class="docutils"> <colgroup> <col width="38%" /> <col width="62%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Resulting state</th> <th class="head"><a class="reference internal" href="#mailbox.mboxMessage" title="mailbox.mboxMessage"><code class="xref py py-class docutils literal notranslate"><span class="pre">mboxMessage</span></code></a> state</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>R flag</td> <td>R flag</td> </tr> <tr class="row-odd"><td>O flag</td> <td>O flag</td> </tr> <tr class="row-even"><td>D flag</td> <td>D flag</td> </tr> <tr class="row-odd"><td>F flag</td> <td>F flag</td> </tr> <tr class="row-even"><td>A flag</td> <td>A flag</td> </tr> </tbody> </table> </div> </div> <div class="section" id="exceptions"> <h2>18.4.3. Exceptions<a class="headerlink" href="#exceptions" title="Permalink to this headline">¶</a></h2> <p>The following exception classes are defined in the <a class="reference internal" href="#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a> module:</p> <dl class="exception"> <dt id="mailbox.Error"> <em class="property">exception </em><code class="descclassname">mailbox.</code><code class="descname">Error</code><a class="headerlink" href="#mailbox.Error" title="Permalink to this definition">¶</a></dt> <dd><p>The based class for all other module-specific exceptions.</p> </dd></dl> <dl class="exception"> <dt id="mailbox.NoSuchMailboxError"> <em class="property">exception </em><code class="descclassname">mailbox.</code><code class="descname">NoSuchMailboxError</code><a class="headerlink" href="#mailbox.NoSuchMailboxError" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when a mailbox is expected but is not found, such as when instantiating a <a class="reference internal" href="#mailbox.Mailbox" title="mailbox.Mailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">Mailbox</span></code></a> subclass with a path that does not exist (and with the <em>create</em> parameter set to <code class="docutils literal notranslate"><span class="pre">False</span></code>), or when opening a folder that does not exist.</p> </dd></dl> <dl class="exception"> <dt id="mailbox.NotEmptyError"> <em class="property">exception </em><code class="descclassname">mailbox.</code><code class="descname">NotEmptyError</code><a class="headerlink" href="#mailbox.NotEmptyError" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when a mailbox is not empty but is expected to be, such as when deleting a folder that contains messages.</p> </dd></dl> <dl class="exception"> <dt id="mailbox.ExternalClashError"> <em class="property">exception </em><code class="descclassname">mailbox.</code><code class="descname">ExternalClashError</code><a class="headerlink" href="#mailbox.ExternalClashError" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when some mailbox-related condition beyond the control of the program causes it to be unable to proceed, such as when failing to acquire a lock that another program already holds a lock, or when a uniquely-generated file name already exists.</p> </dd></dl> <dl class="exception"> <dt id="mailbox.FormatError"> <em class="property">exception </em><code class="descclassname">mailbox.</code><code class="descname">FormatError</code><a class="headerlink" href="#mailbox.FormatError" title="Permalink to this definition">¶</a></dt> <dd><p>Raised when the data in a file cannot be parsed, such as when an <a class="reference internal" href="#mailbox.MH" title="mailbox.MH"><code class="xref py py-class docutils literal notranslate"><span class="pre">MH</span></code></a> instance attempts to read a corrupted <code class="file docutils literal notranslate"><span class="pre">.mh_sequences</span></code> file.</p> </dd></dl> </div> <div class="section" id="deprecated-classes-and-methods"> <span id="mailbox-deprecated"></span><h2>18.4.4. Deprecated classes and methods<a class="headerlink" href="#deprecated-classes-and-methods" title="Permalink to this headline">¶</a></h2> <div class="deprecated"> <p><span class="versionmodified">Deprecated since version 2.6.</span></p> </div> <p>Older versions of the <a class="reference internal" href="#module-mailbox" title="mailbox: Manipulate mailboxes in various formats"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mailbox</span></code></a> module do not support modification of mailboxes, such as adding or removing message, and do not provide classes to represent format-specific message properties. For backward compatibility, the older mailbox classes are still available, but the newer classes should be used in preference to them. The old classes have been removed in Python 3.</p> <p>Older mailbox objects support only iteration and provide a single public method:</p> <dl class="method"> <dt id="mailbox.oldmailbox.next"> <code class="descclassname">oldmailbox.</code><code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.oldmailbox.next" title="Permalink to this definition">¶</a></dt> <dd><p>Return the next message in the mailbox, created with the optional <em>factory</em> argument passed into the mailbox object’s constructor. By default this is an <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">rfc822.Message</span></code></a> object (see the <a class="reference internal" href="rfc822.html#module-rfc822" title="rfc822: Parse 2822 style mail messages. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rfc822</span></code></a> module). Depending on the mailbox implementation the <em>fp</em> attribute of this object may be a true file object or a class instance simulating a file object, taking care of things like message boundaries if multiple mail messages are contained in a single file, etc. If no more messages are available, this method returns <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p> </dd></dl> <p>Most of the older mailbox classes have names that differ from the current mailbox class names, except for <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a>. For this reason, the new <a class="reference internal" href="#mailbox.Maildir" title="mailbox.Maildir"><code class="xref py py-class docutils literal notranslate"><span class="pre">Maildir</span></code></a> class defines a <code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code> method and its constructor differs slightly from those of the other new mailbox classes.</p> <p>The older mailbox classes whose names are not the same as their newer counterparts are as follows:</p> <dl class="class"> <dt id="mailbox.UnixMailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">UnixMailbox</code><span class="sig-paren">(</span><em>fp</em><span class="optional">[</span>, <em>factory</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.UnixMailbox" title="Permalink to this definition">¶</a></dt> <dd><p>Access to a classic Unix-style mailbox, where all messages are contained in a single file and separated by <code class="docutils literal notranslate"><span class="pre">From</span></code> (a.k.a. <code class="docutils literal notranslate"><span class="pre">From_</span></code>) lines. The file object <em>fp</em> points to the mailbox file. The optional <em>factory</em> parameter is a callable that should create new message objects. <em>factory</em> is called with one argument, <em>fp</em> by the <code class="xref py py-meth docutils literal notranslate"><span class="pre">next()</span></code> method of the mailbox object. The default is the <a class="reference internal" href="rfc822.html#rfc822.Message" title="rfc822.Message"><code class="xref py py-class docutils literal notranslate"><span class="pre">rfc822.Message</span></code></a> class (see the <a class="reference internal" href="rfc822.html#module-rfc822" title="rfc822: Parse 2822 style mail messages. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rfc822</span></code></a> module – and the note below).</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">For reasons of this module’s internal implementation, you will probably want to open the <em>fp</em> object in binary mode. This is especially important on Windows.</p> </div> <p>For maximum portability, messages in a Unix-style mailbox are separated by any line that begins exactly with the string <code class="docutils literal notranslate"><span class="pre">'From</span> <span class="pre">'</span></code> (note the trailing space) if preceded by exactly two newlines. Because of the wide-range of variations in practice, nothing else on the <code class="docutils literal notranslate"><span class="pre">From_</span></code> line should be considered. However, the current implementation doesn’t check for the leading two newlines. This is usually fine for most applications.</p> <p>The <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a> class implements a more strict version of <code class="docutils literal notranslate"><span class="pre">From_</span></code> line checking, using a regular expression that usually correctly matched <code class="docutils literal notranslate"><span class="pre">From_</span></code> delimiters. It considers delimiter line to be separated by <code class="docutils literal notranslate"><span class="pre">From</span> <span class="pre">name</span> <span class="pre">time</span></code> lines. For maximum portability, use the <a class="reference internal" href="#mailbox.PortableUnixMailbox" title="mailbox.PortableUnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">PortableUnixMailbox</span></code></a> class instead. This class is identical to <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a> except that individual messages are separated by only <code class="docutils literal notranslate"><span class="pre">From</span></code> lines.</p> </dd></dl> <dl class="class"> <dt id="mailbox.PortableUnixMailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">PortableUnixMailbox</code><span class="sig-paren">(</span><em>fp</em><span class="optional">[</span>, <em>factory</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.PortableUnixMailbox" title="Permalink to this definition">¶</a></dt> <dd><p>A less-strict version of <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a>, which considers only the <code class="docutils literal notranslate"><span class="pre">From</span></code> at the beginning of the line separating messages. The “<em>name</em> <em>time</em>” portion of the From line is ignored, to protect against some variations that are observed in practice. This works since lines in the message which begin with <code class="docutils literal notranslate"><span class="pre">'From</span> <span class="pre">'</span></code> are quoted by mail handling software at delivery-time.</p> </dd></dl> <dl class="class"> <dt id="mailbox.MmdfMailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MmdfMailbox</code><span class="sig-paren">(</span><em>fp</em><span class="optional">[</span>, <em>factory</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MmdfMailbox" title="Permalink to this definition">¶</a></dt> <dd><p>Access an MMDF-style mailbox, where all messages are contained in a single file and separated by lines consisting of 4 control-A characters. The file object <em>fp</em> points to the mailbox file. Optional <em>factory</em> is as with the <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a> class.</p> </dd></dl> <dl class="class"> <dt id="mailbox.MHMailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">MHMailbox</code><span class="sig-paren">(</span><em>dirname</em><span class="optional">[</span>, <em>factory</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.MHMailbox" title="Permalink to this definition">¶</a></dt> <dd><p>Access an MH mailbox, a directory with each message in a separate file with a numeric name. The name of the mailbox directory is passed in <em>dirname</em>. <em>factory</em> is as with the <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a> class.</p> </dd></dl> <dl class="class"> <dt id="mailbox.BabylMailbox"> <em class="property">class </em><code class="descclassname">mailbox.</code><code class="descname">BabylMailbox</code><span class="sig-paren">(</span><em>fp</em><span class="optional">[</span>, <em>factory</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#mailbox.BabylMailbox" title="Permalink to this definition">¶</a></dt> <dd><p>Access a Babyl mailbox, which is similar to an MMDF mailbox. In Babyl format, each message has two sets of headers, the <em>original</em> headers and the <em>visible</em> headers. The original headers appear before a line containing only <code class="docutils literal notranslate"><span class="pre">'***</span> <span class="pre">EOOH</span> <span class="pre">***'</span></code> (End-Of-Original-Headers) and the visible headers appear after the <code class="docutils literal notranslate"><span class="pre">EOOH</span></code> line. Babyl-compliant mail readers will show you only the visible headers, and <a class="reference internal" href="#mailbox.BabylMailbox" title="mailbox.BabylMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">BabylMailbox</span></code></a> objects will return messages containing only the visible headers. You’ll have to do your own parsing of the mailbox file to get at the original headers. Mail messages start with the EOOH line and end with a line containing only <code class="docutils literal notranslate"><span class="pre">'\037\014'</span></code>. <em>factory</em> is as with the <a class="reference internal" href="#mailbox.UnixMailbox" title="mailbox.UnixMailbox"><code class="xref py py-class docutils literal notranslate"><span class="pre">UnixMailbox</span></code></a> class.</p> </dd></dl> <p>If you wish to use the older mailbox classes with the <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><code class="xref py py-mod docutils literal notranslate"><span class="pre">email</span></code></a> module rather than the deprecated <a class="reference internal" href="rfc822.html#module-rfc822" title="rfc822: Parse 2822 style mail messages. (deprecated)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">rfc822</span></code></a> module, you can do so as follows:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">email</span> <span class="kn">import</span> <span class="nn">email.Errors</span> <span class="kn">import</span> <span class="nn">mailbox</span> <span class="k">def</span> <span class="nf">msgfactory</span><span class="p">(</span><span class="n">fp</span><span class="p">):</span> <span class="k">try</span><span class="p">:</span> <span class="k">return</span> <span class="n">email</span><span class="o">.</span><span class="n">message_from_file</span><span class="p">(</span><span class="n">fp</span><span class="p">)</span> <span class="k">except</span> <span class="n">email</span><span class="o">.</span><span class="n">Errors</span><span class="o">.</span><span class="n">MessageParseError</span><span class="p">:</span> <span class="c1"># Don't return None since that will</span> <span class="c1"># stop the mailbox iterator</span> <span class="k">return</span> <span class="s1">''</span> <span class="n">mbox</span> <span class="o">=</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">UnixMailbox</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span> <span class="n">msgfactory</span><span class="p">)</span> </pre></div> </div> <p>Alternatively, if you know your mailbox contains only well-formed MIME messages, you can simplify this to:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">email</span> <span class="kn">import</span> <span class="nn">mailbox</span> <span class="n">mbox</span> <span class="o">=</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">UnixMailbox</span><span class="p">(</span><span class="n">fp</span><span class="p">,</span> <span class="n">email</span><span class="o">.</span><span class="n">message_from_file</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="examples"> <span id="mailbox-examples"></span><h2>18.4.5. Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2> <p>A simple example of printing the subjects of all messages in a mailbox that seem interesting:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">mailbox</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">mbox</span><span class="p">(</span><span class="s1">'~/mbox'</span><span class="p">):</span> <span class="n">subject</span> <span class="o">=</span> <span class="n">message</span><span class="p">[</span><span class="s1">'subject'</span><span class="p">]</span> <span class="c1"># Could possibly be None.</span> <span class="k">if</span> <span class="n">subject</span> <span class="ow">and</span> <span class="s1">'python'</span> <span class="ow">in</span> <span class="n">subject</span><span class="o">.</span><span class="n">lower</span><span class="p">():</span> <span class="nb">print</span> <span class="n">subject</span> </pre></div> </div> <p>To copy all mail from a Babyl mailbox to an MH mailbox, converting all of the format-specific information that can be converted:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">mailbox</span> <span class="n">destination</span> <span class="o">=</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">MH</span><span class="p">(</span><span class="s1">'~/Mail'</span><span class="p">)</span> <span class="n">destination</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">Babyl</span><span class="p">(</span><span class="s1">'~/RMAIL'</span><span class="p">):</span> <span class="n">destination</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mailbox</span><span class="o">.</span><span class="n">MHMessage</span><span class="p">(</span><span class="n">message</span><span class="p">))</span> <span class="n">destination</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span> <span class="n">destination</span><span class="o">.</span><span class="n">unlock</span><span class="p">()</span> </pre></div> </div> <p>This example sorts mail from several mailing lists into different mailboxes, being careful to avoid mail corruption due to concurrent modification by other programs, mail loss due to interruption of the program, or premature termination due to malformed messages in the mailbox:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">mailbox</span> <span class="kn">import</span> <span class="nn">email.errors</span> <span class="n">list_names</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'python-list'</span><span class="p">,</span> <span class="s1">'python-dev'</span><span class="p">,</span> <span class="s1">'python-bugs'</span><span class="p">)</span> <span class="n">boxes</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">((</span><span class="n">name</span><span class="p">,</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">mbox</span><span class="p">(</span><span class="s1">'~/email/</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">list_names</span><span class="p">)</span> <span class="n">inbox</span> <span class="o">=</span> <span class="n">mailbox</span><span class="o">.</span><span class="n">Maildir</span><span class="p">(</span><span class="s1">'~/Maildir'</span><span class="p">,</span> <span class="n">factory</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">inbox</span><span class="o">.</span><span class="n">iterkeys</span><span class="p">():</span> <span class="k">try</span><span class="p">:</span> <span class="n">message</span> <span class="o">=</span> <span class="n">inbox</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="k">except</span> <span class="n">email</span><span class="o">.</span><span class="n">errors</span><span class="o">.</span><span class="n">MessageParseError</span><span class="p">:</span> <span class="k">continue</span> <span class="c1"># The message is malformed. Just leave it.</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">list_names</span><span class="p">:</span> <span class="n">list_id</span> <span class="o">=</span> <span class="n">message</span><span class="p">[</span><span class="s1">'list-id'</span><span class="p">]</span> <span class="k">if</span> <span class="n">list_id</span> <span class="ow">and</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">list_id</span><span class="p">:</span> <span class="c1"># Get mailbox to use</span> <span class="n">box</span> <span class="o">=</span> <span class="n">boxes</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="c1"># Write copy to disk before removing original.</span> <span class="c1"># If there's a crash, you might duplicate a message, but</span> <span class="c1"># that's better than losing a message completely.</span> <span class="n">box</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span> <span class="n">box</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">message</span><span class="p">)</span> <span class="n">box</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span> <span class="n">box</span><span class="o">.</span><span class="n">unlock</span><span class="p">()</span> <span class="c1"># Remove original message</span> <span class="n">inbox</span><span class="o">.</span><span class="n">lock</span><span class="p">()</span> <span class="n">inbox</span><span class="o">.</span><span class="n">discard</span><span class="p">(</span><span class="n">key</span><span class="p">)</span> <span class="n">inbox</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span> <span class="n">inbox</span><span class="o">.</span><span class="n">unlock</span><span class="p">()</span> <span class="k">break</span> <span class="c1"># Found destination, so stop looking.</span> <span class="k">for</span> <span class="n">box</span> <span class="ow">in</span> <span class="n">boxes</span><span class="o">.</span><span class="n">itervalues</span><span class="p">():</span> <span class="n">box</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">18.4. <code class="docutils literal notranslate"><span class="pre">mailbox</span></code> — Manipulate mailboxes in various formats</a><ul> <li><a class="reference internal" href="#mailbox-objects">18.4.1. <code class="docutils literal notranslate"><span class="pre">Mailbox</span></code> objects</a><ul> <li><a class="reference internal" href="#maildir">18.4.1.1. <code class="docutils literal notranslate"><span class="pre">Maildir</span></code></a></li> <li><a class="reference internal" href="#mbox">18.4.1.2. <code class="docutils literal notranslate"><span class="pre">mbox</span></code></a></li> <li><a class="reference internal" href="#mh">18.4.1.3. <code class="docutils literal notranslate"><span class="pre">MH</span></code></a></li> <li><a class="reference internal" href="#babyl">18.4.1.4. <code class="docutils literal notranslate"><span class="pre">Babyl</span></code></a></li> <li><a class="reference internal" href="#mmdf">18.4.1.5. <code class="docutils literal notranslate"><span class="pre">MMDF</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#message-objects">18.4.2. <code class="docutils literal notranslate"><span class="pre">Message</span></code> objects</a><ul> <li><a class="reference internal" href="#maildirmessage">18.4.2.1. <code class="docutils literal notranslate"><span class="pre">MaildirMessage</span></code></a></li> <li><a class="reference internal" href="#mboxmessage">18.4.2.2. <code class="docutils literal notranslate"><span class="pre">mboxMessage</span></code></a></li> <li><a class="reference internal" href="#mhmessage">18.4.2.3. <code class="docutils literal notranslate"><span class="pre">MHMessage</span></code></a></li> <li><a class="reference internal" href="#babylmessage">18.4.2.4. <code class="docutils literal notranslate"><span class="pre">BabylMessage</span></code></a></li> <li><a class="reference internal" href="#mmdfmessage">18.4.2.5. <code class="docutils literal notranslate"><span class="pre">MMDFMessage</span></code></a></li> </ul> </li> <li><a class="reference internal" href="#exceptions">18.4.3. Exceptions</a></li> <li><a class="reference internal" href="#deprecated-classes-and-methods">18.4.4. Deprecated classes and methods</a></li> <li><a class="reference internal" href="#examples">18.4.5. Examples</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="mailcap.html" title="previous chapter">18.3. <code class="docutils literal notranslate"><span class="pre">mailcap</span></code> — Mailcap file handling</a></p> <h4>Next topic</h4> <p class="topless"><a href="mhlib.html" title="next chapter">18.5. <code class="docutils literal notranslate"><span class="pre">mhlib</span></code> — Access to MH mailboxes</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/library/mailbox.rst.txt" rel="nofollow">Show Source</a></li> </ul> </div> <div id="searchbox" style="display: none" role="search"> <h3>Quick search</h3> <div class="searchformwrapper"> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="mhlib.html" title="18.5. mhlib — Access to MH mailboxes" >next</a> |</li> <li class="right" > <a href="mailcap.html" title="18.3. mailcap — Mailcap file handling" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.16 documentation</a> » </li> <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li> <li class="nav-item nav-item-2"><a href="netdata.html" >18. Internet Data Handling</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Mar 27, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run