/
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/imaplib.html
(58515B)
<!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>20.10. imaplib — IMAP4 protocol client — 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="20.11. nntplib — NNTP protocol client" href="nntplib.html" /> <link rel="prev" title="20.9. poplib — POP3 protocol client" href="poplib.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/2/library/imaplib.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="nntplib.html" title="20.11. nntplib — NNTP protocol client" accesskey="N">next</a> |</li> <li class="right" > <a href="poplib.html" title="20.9. poplib — POP3 protocol client" 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="internet.html" accesskey="U">20. Internet Protocols and Support</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-imaplib"> <span id="imaplib-imap4-protocol-client"></span><h1>20.10. <a class="reference internal" href="#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> — IMAP4 protocol client<a class="headerlink" href="#module-imaplib" title="Permalink to this headline">¶</a></h1> <p id="index-0"><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/2.7/Lib/imaplib.py">Lib/imaplib.py</a></p> <hr class="docutils" /> <p>This module defines three classes, <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a>, <a class="reference internal" href="#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> and <a class="reference internal" href="#imaplib.IMAP4_stream" title="imaplib.IMAP4_stream"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_stream</span></code></a>, which encapsulate a connection to an IMAP4 server and implement a large subset of the IMAP4rev1 client protocol as defined in <span class="target" id="index-1"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2060.html"><strong>RFC 2060</strong></a>. It is backward compatible with IMAP4 (<span class="target" id="index-2"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc1730.html"><strong>RFC 1730</strong></a>) servers, but note that the <code class="docutils literal notranslate"><span class="pre">STATUS</span></code> command is not supported in IMAP4.</p> <p>Three classes are provided by the <a class="reference internal" href="#module-imaplib" title="imaplib: IMAP4 protocol client (requires sockets)."><code class="xref py py-mod docutils literal notranslate"><span class="pre">imaplib</span></code></a> module, <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> is the base class:</p> <dl class="class"> <dt id="imaplib.IMAP4"> <em class="property">class </em><code class="descclassname">imaplib.</code><code class="descname">IMAP4</code><span class="sig-paren">(</span><span class="optional">[</span><em>host</em><span class="optional">[</span>, <em>port</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4" title="Permalink to this definition">¶</a></dt> <dd><p>This class implements the actual IMAP4 protocol. The connection is created and protocol version (IMAP4 or IMAP4rev1) is determined when the instance is initialized. If <em>host</em> is not specified, <code class="docutils literal notranslate"><span class="pre">''</span></code> (the local host) is used. If <em>port</em> is omitted, the standard IMAP4 port (143) is used.</p> </dd></dl> <p>Three exceptions are defined as attributes of the <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> class:</p> <dl class="exception"> <dt id="imaplib.IMAP4.error"> <em class="property">exception </em><code class="descclassname">IMAP4.</code><code class="descname">error</code><a class="headerlink" href="#imaplib.IMAP4.error" title="Permalink to this definition">¶</a></dt> <dd><p>Exception raised on any errors. The reason for the exception is passed to the constructor as a string.</p> </dd></dl> <dl class="exception"> <dt id="imaplib.IMAP4.abort"> <em class="property">exception </em><code class="descclassname">IMAP4.</code><code class="descname">abort</code><a class="headerlink" href="#imaplib.IMAP4.abort" title="Permalink to this definition">¶</a></dt> <dd><p>IMAP4 server errors cause this exception to be raised. This is a sub-class of <a class="reference internal" href="#imaplib.IMAP4.error" title="imaplib.IMAP4.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IMAP4.error</span></code></a>. Note that closing the instance and instantiating a new one will usually allow recovery from this exception.</p> </dd></dl> <dl class="exception"> <dt id="imaplib.IMAP4.readonly"> <em class="property">exception </em><code class="descclassname">IMAP4.</code><code class="descname">readonly</code><a class="headerlink" href="#imaplib.IMAP4.readonly" title="Permalink to this definition">¶</a></dt> <dd><p>This exception is raised when a writable mailbox has its status changed by the server. This is a sub-class of <a class="reference internal" href="#imaplib.IMAP4.error" title="imaplib.IMAP4.error"><code class="xref py py-exc docutils literal notranslate"><span class="pre">IMAP4.error</span></code></a>. Some other client now has write permission, and the mailbox will need to be re-opened to re-obtain write permission.</p> </dd></dl> <p>There’s also a subclass for secure connections:</p> <dl class="class"> <dt id="imaplib.IMAP4_SSL"> <em class="property">class </em><code class="descclassname">imaplib.</code><code class="descname">IMAP4_SSL</code><span class="sig-paren">(</span><span class="optional">[</span><em>host</em><span class="optional">[</span>, <em>port</em><span class="optional">[</span>, <em>keyfile</em><span class="optional">[</span>, <em>certfile</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4_SSL" title="Permalink to this definition">¶</a></dt> <dd><p>This is a subclass derived from <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> that connects over an SSL encrypted socket (to use this class you need a socket module that was compiled with SSL support). If <em>host</em> is not specified, <code class="docutils literal notranslate"><span class="pre">''</span></code> (the local host) is used. If <em>port</em> is omitted, the standard IMAP4-over-SSL port (993) is used. <em>keyfile</em> and <em>certfile</em> are also optional - they can contain a PEM formatted private key and certificate chain file for the SSL connection.</p> </dd></dl> <p>The second subclass allows for connections created by a child process:</p> <dl class="class"> <dt id="imaplib.IMAP4_stream"> <em class="property">class </em><code class="descclassname">imaplib.</code><code class="descname">IMAP4_stream</code><span class="sig-paren">(</span><em>command</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4_stream" title="Permalink to this definition">¶</a></dt> <dd><p>This is a subclass derived from <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> that connects to the <code class="docutils literal notranslate"><span class="pre">stdin/stdout</span></code> file descriptors created by passing <em>command</em> to <code class="docutils literal notranslate"><span class="pre">os.popen2()</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <p>The following utility functions are defined:</p> <dl class="function"> <dt id="imaplib.Internaldate2tuple"> <code class="descclassname">imaplib.</code><code class="descname">Internaldate2tuple</code><span class="sig-paren">(</span><em>datestr</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.Internaldate2tuple" title="Permalink to this definition">¶</a></dt> <dd><p>Parse an IMAP4 <code class="docutils literal notranslate"><span class="pre">INTERNALDATE</span></code> string and return corresponding local time. The return value is 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 or <code class="docutils literal notranslate"><span class="pre">None</span></code> if the string has wrong format.</p> </dd></dl> <dl class="function"> <dt id="imaplib.Int2AP"> <code class="descclassname">imaplib.</code><code class="descname">Int2AP</code><span class="sig-paren">(</span><em>num</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.Int2AP" title="Permalink to this definition">¶</a></dt> <dd><p>Converts an integer into a string representation using characters from the set [<code class="docutils literal notranslate"><span class="pre">A</span></code> .. <code class="docutils literal notranslate"><span class="pre">P</span></code>].</p> </dd></dl> <dl class="function"> <dt id="imaplib.ParseFlags"> <code class="descclassname">imaplib.</code><code class="descname">ParseFlags</code><span class="sig-paren">(</span><em>flagstr</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.ParseFlags" title="Permalink to this definition">¶</a></dt> <dd><p>Converts an IMAP4 <code class="docutils literal notranslate"><span class="pre">FLAGS</span></code> response to a tuple of individual flags.</p> </dd></dl> <dl class="function"> <dt id="imaplib.Time2Internaldate"> <code class="descclassname">imaplib.</code><code class="descname">Time2Internaldate</code><span class="sig-paren">(</span><em>date_time</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.Time2Internaldate" title="Permalink to this definition">¶</a></dt> <dd><p>Convert <em>date_time</em> to an IMAP4 <code class="docutils literal notranslate"><span class="pre">INTERNALDATE</span></code> representation. The return value is a string in the form: <code class="docutils literal notranslate"><span class="pre">"DD-Mmm-YYYY</span> <span class="pre">HH:MM:SS</span> <span class="pre">+HHMM"</span></code> (including double-quotes). The <em>date_time</em> argument can be a number (int or float) representing seconds since epoch (as returned by <a class="reference internal" href="time.html#time.time" title="time.time"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.time()</span></code></a>), a 9-tuple representing local time (as returned by <a class="reference internal" href="time.html#time.localtime" title="time.localtime"><code class="xref py py-func docutils literal notranslate"><span class="pre">time.localtime()</span></code></a>), or a double-quoted string. In the last case, it is assumed to already be in the correct format.</p> </dd></dl> <p>Note that IMAP4 message numbers change as the mailbox changes; in particular, after an <code class="docutils literal notranslate"><span class="pre">EXPUNGE</span></code> command performs deletions the remaining messages are renumbered. So it is highly advisable to use UIDs instead, with the UID command.</p> <p>At the end of the module, there is a test section that contains a more extensive example of usage.</p> <div class="admonition seealso"> <p class="first admonition-title">See also</p> <p class="last">Documents describing the protocol, and sources and binaries for servers implementing it, can all be found at the University of Washington’s <em>IMAP Information Center</em> (<a class="reference external" href="https://www.washington.edu/imap/">https://www.washington.edu/imap/</a>).</p> </div> <div class="section" id="imap4-objects"> <span id="id1"></span><h2>20.10.1. IMAP4 Objects<a class="headerlink" href="#imap4-objects" title="Permalink to this headline">¶</a></h2> <p>All IMAP4rev1 commands are represented by methods of the same name, either upper-case or lower-case.</p> <p>All arguments to commands are converted to strings, except for <code class="docutils literal notranslate"><span class="pre">AUTHENTICATE</span></code>, and the last argument to <code class="docutils literal notranslate"><span class="pre">APPEND</span></code> which is passed as an IMAP4 literal. If necessary (the string contains IMAP4 protocol-sensitive characters and isn’t enclosed with either parentheses or double quotes) each string is quoted. However, the <em>password</em> argument to the <code class="docutils literal notranslate"><span class="pre">LOGIN</span></code> command is always quoted. If you want to avoid having an argument string quoted (eg: the <em>flags</em> argument to <code class="docutils literal notranslate"><span class="pre">STORE</span></code>) then enclose the string in parentheses (eg: <code class="docutils literal notranslate"><span class="pre">r'(\Deleted)'</span></code>).</p> <p>Each command returns a tuple: <code class="docutils literal notranslate"><span class="pre">(type,</span> <span class="pre">[data,</span> <span class="pre">...])</span></code> where <em>type</em> is usually <code class="docutils literal notranslate"><span class="pre">'OK'</span></code> or <code class="docutils literal notranslate"><span class="pre">'NO'</span></code>, and <em>data</em> is either the text from the command response, or mandated results from the command. Each <em>data</em> is either a string, or a tuple. If a tuple, then the first part is the header of the response, and the second part contains the data (ie: ‘literal’ value).</p> <p>The <em>message_set</em> options to commands below is a string specifying one or more messages to be acted upon. It may be a simple message number (<code class="docutils literal notranslate"><span class="pre">'1'</span></code>), a range of message numbers (<code class="docutils literal notranslate"><span class="pre">'2:4'</span></code>), or a group of non-contiguous ranges separated by commas (<code class="docutils literal notranslate"><span class="pre">'1:3,6:9'</span></code>). A range can contain an asterisk to indicate an infinite upper bound (<code class="docutils literal notranslate"><span class="pre">'3:*'</span></code>).</p> <p>An <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> instance has the following methods:</p> <dl class="method"> <dt id="imaplib.IMAP4.append"> <code class="descclassname">IMAP4.</code><code class="descname">append</code><span class="sig-paren">(</span><em>mailbox</em>, <em>flags</em>, <em>date_time</em>, <em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.append" title="Permalink to this definition">¶</a></dt> <dd><p>Append <em>message</em> to named mailbox.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.authenticate"> <code class="descclassname">IMAP4.</code><code class="descname">authenticate</code><span class="sig-paren">(</span><em>mechanism</em>, <em>authobject</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.authenticate" title="Permalink to this definition">¶</a></dt> <dd><p>Authenticate command — requires response processing.</p> <p><em>mechanism</em> specifies which authentication mechanism is to be used - it should appear in the instance variable <code class="docutils literal notranslate"><span class="pre">capabilities</span></code> in the form <code class="docutils literal notranslate"><span class="pre">AUTH=mechanism</span></code>.</p> <p><em>authobject</em> must be a callable object:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">data</span> <span class="o">=</span> <span class="n">authobject</span><span class="p">(</span><span class="n">response</span><span class="p">)</span> </pre></div> </div> <p>It will be called to process server continuation responses. It should return <code class="docutils literal notranslate"><span class="pre">data</span></code> that will be encoded and sent to server. It should return <code class="docutils literal notranslate"><span class="pre">None</span></code> if the client abort response <code class="docutils literal notranslate"><span class="pre">*</span></code> should be sent instead.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.check"> <code class="descclassname">IMAP4.</code><code class="descname">check</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.check" title="Permalink to this definition">¶</a></dt> <dd><p>Checkpoint mailbox on server.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.close"> <code class="descclassname">IMAP4.</code><code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.close" title="Permalink to this definition">¶</a></dt> <dd><p>Close currently selected mailbox. Deleted messages are removed from writable mailbox. This is the recommended command before <code class="docutils literal notranslate"><span class="pre">LOGOUT</span></code>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.copy"> <code class="descclassname">IMAP4.</code><code class="descname">copy</code><span class="sig-paren">(</span><em>message_set</em>, <em>new_mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.copy" title="Permalink to this definition">¶</a></dt> <dd><p>Copy <em>message_set</em> messages onto end of <em>new_mailbox</em>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.create"> <code class="descclassname">IMAP4.</code><code class="descname">create</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.create" title="Permalink to this definition">¶</a></dt> <dd><p>Create new mailbox named <em>mailbox</em>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.delete"> <code class="descclassname">IMAP4.</code><code class="descname">delete</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.delete" title="Permalink to this definition">¶</a></dt> <dd><p>Delete old mailbox named <em>mailbox</em>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.deleteacl"> <code class="descclassname">IMAP4.</code><code class="descname">deleteacl</code><span class="sig-paren">(</span><em>mailbox</em>, <em>who</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.deleteacl" title="Permalink to this definition">¶</a></dt> <dd><p>Delete the ACLs (remove any rights) set for who on mailbox.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.4.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.expunge"> <code class="descclassname">IMAP4.</code><code class="descname">expunge</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.expunge" title="Permalink to this definition">¶</a></dt> <dd><p>Permanently remove deleted items from selected mailbox. Generates an <code class="docutils literal notranslate"><span class="pre">EXPUNGE</span></code> response for each deleted message. Returned data contains a list of <code class="docutils literal notranslate"><span class="pre">EXPUNGE</span></code> message numbers in order received.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.fetch"> <code class="descclassname">IMAP4.</code><code class="descname">fetch</code><span class="sig-paren">(</span><em>message_set</em>, <em>message_parts</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.fetch" title="Permalink to this definition">¶</a></dt> <dd><p>Fetch (parts of) messages. <em>message_parts</em> should be a string of message part names enclosed within parentheses, eg: <code class="docutils literal notranslate"><span class="pre">"(UID</span> <span class="pre">BODY[TEXT])"</span></code>. Returned data are tuples of message part envelope and data.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.getacl"> <code class="descclassname">IMAP4.</code><code class="descname">getacl</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.getacl" title="Permalink to this definition">¶</a></dt> <dd><p>Get the <code class="docutils literal notranslate"><span class="pre">ACL</span></code>s for <em>mailbox</em>. The method is non-standard, but is supported by the <code class="docutils literal notranslate"><span class="pre">Cyrus</span></code> server.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.getannotation"> <code class="descclassname">IMAP4.</code><code class="descname">getannotation</code><span class="sig-paren">(</span><em>mailbox</em>, <em>entry</em>, <em>attribute</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.getannotation" title="Permalink to this definition">¶</a></dt> <dd><p>Retrieve the specified <code class="docutils literal notranslate"><span class="pre">ANNOTATION</span></code>s for <em>mailbox</em>. The method is non-standard, but is supported by the <code class="docutils literal notranslate"><span class="pre">Cyrus</span></code> server.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.getquota"> <code class="descclassname">IMAP4.</code><code class="descname">getquota</code><span class="sig-paren">(</span><em>root</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.getquota" title="Permalink to this definition">¶</a></dt> <dd><p>Get the <code class="docutils literal notranslate"><span class="pre">quota</span></code> <em>root</em>’s resource usage and limits. This method is part of the IMAP4 QUOTA extension defined in rfc2087.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.getquotaroot"> <code class="descclassname">IMAP4.</code><code class="descname">getquotaroot</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.getquotaroot" title="Permalink to this definition">¶</a></dt> <dd><p>Get the list of <code class="docutils literal notranslate"><span class="pre">quota</span></code> <code class="docutils literal notranslate"><span class="pre">roots</span></code> for the named <em>mailbox</em>. This method is part of the IMAP4 QUOTA extension defined in rfc2087.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.list"> <code class="descclassname">IMAP4.</code><code class="descname">list</code><span class="sig-paren">(</span><span class="optional">[</span><em>directory</em><span class="optional">[</span>, <em>pattern</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.list" title="Permalink to this definition">¶</a></dt> <dd><p>List mailbox names in <em>directory</em> matching <em>pattern</em>. <em>directory</em> defaults to the top-level mail folder, and <em>pattern</em> defaults to match anything. Returned data contains a list of <code class="docutils literal notranslate"><span class="pre">LIST</span></code> responses.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.login"> <code class="descclassname">IMAP4.</code><code class="descname">login</code><span class="sig-paren">(</span><em>user</em>, <em>password</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.login" title="Permalink to this definition">¶</a></dt> <dd><p>Identify the client using a plaintext password. The <em>password</em> will be quoted.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.login_cram_md5"> <code class="descclassname">IMAP4.</code><code class="descname">login_cram_md5</code><span class="sig-paren">(</span><em>user</em>, <em>password</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.login_cram_md5" title="Permalink to this definition">¶</a></dt> <dd><p>Force use of <code class="docutils literal notranslate"><span class="pre">CRAM-MD5</span></code> authentication when identifying the client to protect the password. Will only work if the server <code class="docutils literal notranslate"><span class="pre">CAPABILITY</span></code> response includes the phrase <code class="docutils literal notranslate"><span class="pre">AUTH=CRAM-MD5</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.logout"> <code class="descclassname">IMAP4.</code><code class="descname">logout</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.logout" title="Permalink to this definition">¶</a></dt> <dd><p>Shutdown connection to server. Returns server <code class="docutils literal notranslate"><span class="pre">BYE</span></code> response.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.lsub"> <code class="descclassname">IMAP4.</code><code class="descname">lsub</code><span class="sig-paren">(</span><span class="optional">[</span><em>directory</em><span class="optional">[</span>, <em>pattern</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.lsub" title="Permalink to this definition">¶</a></dt> <dd><p>List subscribed mailbox names in directory matching pattern. <em>directory</em> defaults to the top level directory and <em>pattern</em> defaults to match any mailbox. Returned data are tuples of message part envelope and data.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.myrights"> <code class="descclassname">IMAP4.</code><code class="descname">myrights</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.myrights" title="Permalink to this definition">¶</a></dt> <dd><p>Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.4.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.namespace"> <code class="descclassname">IMAP4.</code><code class="descname">namespace</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.namespace" title="Permalink to this definition">¶</a></dt> <dd><p>Returns IMAP namespaces as defined in RFC2342.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.noop"> <code class="descclassname">IMAP4.</code><code class="descname">noop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.noop" title="Permalink to this definition">¶</a></dt> <dd><p>Send <code class="docutils literal notranslate"><span class="pre">NOOP</span></code> to server.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.open"> <code class="descclassname">IMAP4.</code><code class="descname">open</code><span class="sig-paren">(</span><em>host</em>, <em>port</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.open" title="Permalink to this definition">¶</a></dt> <dd><p>Opens socket to <em>port</em> at <em>host</em>. This method is implicitly called by the <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a> constructor. The connection objects established by this method will be used in the <a class="reference internal" href="#imaplib.IMAP4.read" title="imaplib.IMAP4.read"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.read()</span></code></a>, <a class="reference internal" href="#imaplib.IMAP4.readline" title="imaplib.IMAP4.readline"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.readline()</span></code></a>, <a class="reference internal" href="#imaplib.IMAP4.send" title="imaplib.IMAP4.send"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.send()</span></code></a>, and <a class="reference internal" href="#imaplib.IMAP4.shutdown" title="imaplib.IMAP4.shutdown"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.shutdown()</span></code></a> methods. You may override this method.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.partial"> <code class="descclassname">IMAP4.</code><code class="descname">partial</code><span class="sig-paren">(</span><em>message_num</em>, <em>message_part</em>, <em>start</em>, <em>length</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.partial" title="Permalink to this definition">¶</a></dt> <dd><p>Fetch truncated part of a message. Returned data is a tuple of message part envelope and data.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.proxyauth"> <code class="descclassname">IMAP4.</code><code class="descname">proxyauth</code><span class="sig-paren">(</span><em>user</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.proxyauth" title="Permalink to this definition">¶</a></dt> <dd><p>Assume authentication as <em>user</em>. Allows an authorised administrator to proxy into any user’s mailbox.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.read"> <code class="descclassname">IMAP4.</code><code class="descname">read</code><span class="sig-paren">(</span><em>size</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.read" title="Permalink to this definition">¶</a></dt> <dd><p>Reads <em>size</em> bytes from the remote server. You may override this method.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.readline"> <code class="descclassname">IMAP4.</code><code class="descname">readline</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.readline" title="Permalink to this definition">¶</a></dt> <dd><p>Reads one line from the remote server. You may override this method.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.recent"> <code class="descclassname">IMAP4.</code><code class="descname">recent</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.recent" title="Permalink to this definition">¶</a></dt> <dd><p>Prompt server for an update. Returned data is <code class="docutils literal notranslate"><span class="pre">None</span></code> if no new messages, else value of <code class="docutils literal notranslate"><span class="pre">RECENT</span></code> response.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.rename"> <code class="descclassname">IMAP4.</code><code class="descname">rename</code><span class="sig-paren">(</span><em>oldmailbox</em>, <em>newmailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.rename" title="Permalink to this definition">¶</a></dt> <dd><p>Rename mailbox named <em>oldmailbox</em> to <em>newmailbox</em>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.response"> <code class="descclassname">IMAP4.</code><code class="descname">response</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.response" title="Permalink to this definition">¶</a></dt> <dd><p>Return data for response <em>code</em> if received, or <code class="docutils literal notranslate"><span class="pre">None</span></code>. Returns the given code, instead of the usual type.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.search"> <code class="descclassname">IMAP4.</code><code class="descname">search</code><span class="sig-paren">(</span><em>charset</em>, <em>criterion</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.search" title="Permalink to this definition">¶</a></dt> <dd><p>Search mailbox for matching messages. <em>charset</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code>, in which case no <code class="docutils literal notranslate"><span class="pre">CHARSET</span></code> will be specified in the request to the server. The IMAP protocol requires that at least one criterion be specified; an exception will be raised when the server returns an error.</p> <p>Example:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># M is a connected IMAP4 instance...</span> <span class="n">typ</span><span class="p">,</span> <span class="n">msgnums</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">'FROM'</span><span class="p">,</span> <span class="s1">'"LDJ"'</span><span class="p">)</span> <span class="c1"># or:</span> <span class="n">typ</span><span class="p">,</span> <span class="n">msgnums</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">'(FROM "LDJ")'</span><span class="p">)</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.select"> <code class="descclassname">IMAP4.</code><code class="descname">select</code><span class="sig-paren">(</span><span class="optional">[</span><em>mailbox</em><span class="optional">[</span>, <em>readonly</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.select" title="Permalink to this definition">¶</a></dt> <dd><p>Select a mailbox. Returned data is the count of messages in <em>mailbox</em> (<code class="docutils literal notranslate"><span class="pre">EXISTS</span></code> response). The default <em>mailbox</em> is <code class="docutils literal notranslate"><span class="pre">'INBOX'</span></code>. If the <em>readonly</em> flag is set, modifications to the mailbox are not allowed.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.send"> <code class="descclassname">IMAP4.</code><code class="descname">send</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.send" title="Permalink to this definition">¶</a></dt> <dd><p>Sends <code class="docutils literal notranslate"><span class="pre">data</span></code> to the remote server. You may override this method.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.setacl"> <code class="descclassname">IMAP4.</code><code class="descname">setacl</code><span class="sig-paren">(</span><em>mailbox</em>, <em>who</em>, <em>what</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.setacl" title="Permalink to this definition">¶</a></dt> <dd><p>Set an <code class="docutils literal notranslate"><span class="pre">ACL</span></code> for <em>mailbox</em>. The method is non-standard, but is supported by the <code class="docutils literal notranslate"><span class="pre">Cyrus</span></code> server.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.setannotation"> <code class="descclassname">IMAP4.</code><code class="descname">setannotation</code><span class="sig-paren">(</span><em>mailbox</em>, <em>entry</em>, <em>attribute</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.setannotation" title="Permalink to this definition">¶</a></dt> <dd><p>Set <code class="docutils literal notranslate"><span class="pre">ANNOTATION</span></code>s for <em>mailbox</em>. The method is non-standard, but is supported by the <code class="docutils literal notranslate"><span class="pre">Cyrus</span></code> server.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.5.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.setquota"> <code class="descclassname">IMAP4.</code><code class="descname">setquota</code><span class="sig-paren">(</span><em>root</em>, <em>limits</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.setquota" title="Permalink to this definition">¶</a></dt> <dd><p>Set the <code class="docutils literal notranslate"><span class="pre">quota</span></code> <em>root</em>’s resource <em>limits</em>. This method is part of the IMAP4 QUOTA extension defined in rfc2087.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.3.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.shutdown"> <code class="descclassname">IMAP4.</code><code class="descname">shutdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.shutdown" title="Permalink to this definition">¶</a></dt> <dd><p>Close connection established in <code class="docutils literal notranslate"><span class="pre">open</span></code>. This method is implicitly called by <a class="reference internal" href="#imaplib.IMAP4.logout" title="imaplib.IMAP4.logout"><code class="xref py py-meth docutils literal notranslate"><span class="pre">IMAP4.logout()</span></code></a>. You may override this method.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.socket"> <code class="descclassname">IMAP4.</code><code class="descname">socket</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.socket" title="Permalink to this definition">¶</a></dt> <dd><p>Returns socket instance used to connect to server.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.sort"> <code class="descclassname">IMAP4.</code><code class="descname">sort</code><span class="sig-paren">(</span><em>sort_criteria</em>, <em>charset</em>, <em>search_criterion</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.sort" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">sort</span></code> command is a variant of <code class="docutils literal notranslate"><span class="pre">search</span></code> with sorting semantics for the results. Returned data contains a space separated list of matching message numbers.</p> <p>Sort has two arguments before the <em>search_criterion</em> argument(s); a parenthesized list of <em>sort_criteria</em>, and the searching <em>charset</em>. Note that unlike <code class="docutils literal notranslate"><span class="pre">search</span></code>, the searching <em>charset</em> argument is mandatory. There is also a <code class="docutils literal notranslate"><span class="pre">uid</span> <span class="pre">sort</span></code> command which corresponds to <code class="docutils literal notranslate"><span class="pre">sort</span></code> the way that <code class="docutils literal notranslate"><span class="pre">uid</span> <span class="pre">search</span></code> corresponds to <code class="docutils literal notranslate"><span class="pre">search</span></code>. The <code class="docutils literal notranslate"><span class="pre">sort</span></code> command first searches the mailbox for messages that match the given searching criteria using the charset argument for the interpretation of strings in the searching criteria. It then returns the numbers of matching messages.</p> <p>This is an <code class="docutils literal notranslate"><span class="pre">IMAP4rev1</span></code> extension command.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.status"> <code class="descclassname">IMAP4.</code><code class="descname">status</code><span class="sig-paren">(</span><em>mailbox</em>, <em>names</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.status" title="Permalink to this definition">¶</a></dt> <dd><p>Request named status conditions for <em>mailbox</em>.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.store"> <code class="descclassname">IMAP4.</code><code class="descname">store</code><span class="sig-paren">(</span><em>message_set</em>, <em>command</em>, <em>flag_list</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.store" title="Permalink to this definition">¶</a></dt> <dd><p>Alters flag dispositions for messages in mailbox. <em>command</em> is specified by section 6.4.6 of <span class="target" id="index-3"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc2060.html"><strong>RFC 2060</strong></a> as being one of “FLAGS”, “+FLAGS”, or “-FLAGS”, optionally with a suffix of “.SILENT”.</p> <p>For example, to set the delete flag on all messages:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">typ</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">'ALL'</span><span class="p">)</span> <span class="k">for</span> <span class="n">num</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">():</span> <span class="n">M</span><span class="o">.</span><span class="n">store</span><span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="s1">'+FLAGS'</span><span class="p">,</span> <span class="s1">'</span><span class="se">\\</span><span class="s1">Deleted'</span><span class="p">)</span> <span class="n">M</span><span class="o">.</span><span class="n">expunge</span><span class="p">()</span> </pre></div> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.subscribe"> <code class="descclassname">IMAP4.</code><code class="descname">subscribe</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.subscribe" title="Permalink to this definition">¶</a></dt> <dd><p>Subscribe to new mailbox.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.thread"> <code class="descclassname">IMAP4.</code><code class="descname">thread</code><span class="sig-paren">(</span><em>threading_algorithm</em>, <em>charset</em>, <em>search_criterion</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.thread" title="Permalink to this definition">¶</a></dt> <dd><p>The <code class="docutils literal notranslate"><span class="pre">thread</span></code> command is a variant of <code class="docutils literal notranslate"><span class="pre">search</span></code> with threading semantics for the results. Returned data contains a space separated list of thread members.</p> <p>Thread members consist of zero or more messages numbers, delimited by spaces, indicating successive parent and child.</p> <p>Thread has two arguments before the <em>search_criterion</em> argument(s); a <em>threading_algorithm</em>, and the searching <em>charset</em>. Note that unlike <code class="docutils literal notranslate"><span class="pre">search</span></code>, the searching <em>charset</em> argument is mandatory. There is also a <code class="docutils literal notranslate"><span class="pre">uid</span> <span class="pre">thread</span></code> command which corresponds to <code class="docutils literal notranslate"><span class="pre">thread</span></code> the way that <code class="docutils literal notranslate"><span class="pre">uid</span> <span class="pre">search</span></code> corresponds to <code class="docutils literal notranslate"><span class="pre">search</span></code>. The <code class="docutils literal notranslate"><span class="pre">thread</span></code> command first searches the mailbox for messages that match the given searching criteria using the charset argument for the interpretation of strings in the searching criteria. It then returns the matching messages threaded according to the specified threading algorithm.</p> <p>This is an <code class="docutils literal notranslate"><span class="pre">IMAP4rev1</span></code> extension command.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 2.4.</span></p> </div> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.uid"> <code class="descclassname">IMAP4.</code><code class="descname">uid</code><span class="sig-paren">(</span><em>command</em>, <em>arg</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.uid" title="Permalink to this definition">¶</a></dt> <dd><p>Execute command args with messages identified by UID, rather than message number. Returns response appropriate to command. At least one argument must be supplied; if none are provided, the server will return an error and an exception will be raised.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.unsubscribe"> <code class="descclassname">IMAP4.</code><code class="descname">unsubscribe</code><span class="sig-paren">(</span><em>mailbox</em><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.unsubscribe" title="Permalink to this definition">¶</a></dt> <dd><p>Unsubscribe from old mailbox.</p> </dd></dl> <dl class="method"> <dt id="imaplib.IMAP4.xatom"> <code class="descclassname">IMAP4.</code><code class="descname">xatom</code><span class="sig-paren">(</span><em>name</em><span class="optional">[</span>, <em>arg</em><span class="optional">[</span>, <em>...</em><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4.xatom" title="Permalink to this definition">¶</a></dt> <dd><p>Allow simple extension commands notified by server in <code class="docutils literal notranslate"><span class="pre">CAPABILITY</span></code> response.</p> </dd></dl> <p>Instances of <a class="reference internal" href="#imaplib.IMAP4_SSL" title="imaplib.IMAP4_SSL"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4_SSL</span></code></a> have just one additional method:</p> <dl class="method"> <dt id="imaplib.IMAP4_SSL.ssl"> <code class="descclassname">IMAP4_SSL.</code><code class="descname">ssl</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#imaplib.IMAP4_SSL.ssl" title="Permalink to this definition">¶</a></dt> <dd><p>Returns SSLObject instance used for the secure connection with the server.</p> </dd></dl> <p>The following attributes are defined on instances of <a class="reference internal" href="#imaplib.IMAP4" title="imaplib.IMAP4"><code class="xref py py-class docutils literal notranslate"><span class="pre">IMAP4</span></code></a>:</p> <dl class="attribute"> <dt id="imaplib.IMAP4.PROTOCOL_VERSION"> <code class="descclassname">IMAP4.</code><code class="descname">PROTOCOL_VERSION</code><a class="headerlink" href="#imaplib.IMAP4.PROTOCOL_VERSION" title="Permalink to this definition">¶</a></dt> <dd><p>The most recent supported protocol in the <code class="docutils literal notranslate"><span class="pre">CAPABILITY</span></code> response from the server.</p> </dd></dl> <dl class="attribute"> <dt id="imaplib.IMAP4.debug"> <code class="descclassname">IMAP4.</code><code class="descname">debug</code><a class="headerlink" href="#imaplib.IMAP4.debug" title="Permalink to this definition">¶</a></dt> <dd><p>Integer value to control debugging output. The initialize value is taken from the module variable <code class="docutils literal notranslate"><span class="pre">Debug</span></code>. Values greater than three trace each command.</p> </dd></dl> </div> <div class="section" id="imap4-example"> <span id="id2"></span><h2>20.10.2. IMAP4 Example<a class="headerlink" href="#imap4-example" title="Permalink to this headline">¶</a></h2> <p>Here is a minimal example (without error checking) that opens a mailbox and retrieves and prints all messages:</p> <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">getpass</span><span class="o">,</span> <span class="nn">imaplib</span> <span class="n">M</span> <span class="o">=</span> <span class="n">imaplib</span><span class="o">.</span><span class="n">IMAP4</span><span class="p">()</span> <span class="n">M</span><span class="o">.</span><span class="n">login</span><span class="p">(</span><span class="n">getpass</span><span class="o">.</span><span class="n">getuser</span><span class="p">(),</span> <span class="n">getpass</span><span class="o">.</span><span class="n">getpass</span><span class="p">())</span> <span class="n">M</span><span class="o">.</span><span class="n">select</span><span class="p">()</span> <span class="n">typ</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s1">'ALL'</span><span class="p">)</span> <span class="k">for</span> <span class="n">num</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">():</span> <span class="n">typ</span><span class="p">,</span> <span class="n">data</span> <span class="o">=</span> <span class="n">M</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="s1">'(RFC822)'</span><span class="p">)</span> <span class="nb">print</span> <span class="s1">'Message </span><span class="si">%s</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">num</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">])</span> <span class="n">M</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="n">M</span><span class="o">.</span><span class="n">logout</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="#">20.10. <code class="docutils literal notranslate"><span class="pre">imaplib</span></code> — IMAP4 protocol client</a><ul> <li><a class="reference internal" href="#imap4-objects">20.10.1. IMAP4 Objects</a></li> <li><a class="reference internal" href="#imap4-example">20.10.2. IMAP4 Example</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="poplib.html" title="previous chapter">20.9. <code class="docutils literal notranslate"><span class="pre">poplib</span></code> — POP3 protocol client</a></p> <h4>Next topic</h4> <p class="topless"><a href="nntplib.html" title="next chapter">20.11. <code class="docutils literal notranslate"><span class="pre">nntplib</span></code> — NNTP protocol client</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../_sources/library/imaplib.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="nntplib.html" title="20.11. nntplib — NNTP protocol client" >next</a> |</li> <li class="right" > <a href="poplib.html" title="20.9. poplib — POP3 protocol client" >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="internet.html" >20. Internet Protocols and Support</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