Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../usr/lib64/python3....
File: imaplib.py
"""IMAP4 client.
[0] Fix | Delete
[1] Fix | Delete
Based on RFC 2060.
[2] Fix | Delete
[3] Fix | Delete
Public class: IMAP4
[4] Fix | Delete
Public variable: Debug
[5] Fix | Delete
Public functions: Internaldate2tuple
[6] Fix | Delete
Int2AP
[7] Fix | Delete
ParseFlags
[8] Fix | Delete
Time2Internaldate
[9] Fix | Delete
"""
[10] Fix | Delete
[11] Fix | Delete
# Author: Piers Lauder <piers@cs.su.oz.au> December 1997.
[12] Fix | Delete
#
[13] Fix | Delete
# Authentication code contributed by Donn Cave <donn@u.washington.edu> June 1998.
[14] Fix | Delete
# String method conversion by ESR, February 2001.
[15] Fix | Delete
# GET/SETACL contributed by Anthony Baxter <anthony@interlink.com.au> April 2001.
[16] Fix | Delete
# IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002.
[17] Fix | Delete
# GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002.
[18] Fix | Delete
# PROXYAUTH contributed by Rick Holbert <holbert.13@osu.edu> November 2002.
[19] Fix | Delete
# GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
[20] Fix | Delete
[21] Fix | Delete
__version__ = "2.58"
[22] Fix | Delete
[23] Fix | Delete
import binascii, errno, random, re, socket, subprocess, sys, time, calendar
[24] Fix | Delete
from datetime import datetime, timezone, timedelta
[25] Fix | Delete
from io import DEFAULT_BUFFER_SIZE
[26] Fix | Delete
[27] Fix | Delete
try:
[28] Fix | Delete
import ssl
[29] Fix | Delete
HAVE_SSL = True
[30] Fix | Delete
except ImportError:
[31] Fix | Delete
HAVE_SSL = False
[32] Fix | Delete
[33] Fix | Delete
__all__ = ["IMAP4", "IMAP4_stream", "Internaldate2tuple",
[34] Fix | Delete
"Int2AP", "ParseFlags", "Time2Internaldate"]
[35] Fix | Delete
[36] Fix | Delete
# Globals
[37] Fix | Delete
[38] Fix | Delete
CRLF = b'\r\n'
[39] Fix | Delete
Debug = 0
[40] Fix | Delete
IMAP4_PORT = 143
[41] Fix | Delete
IMAP4_SSL_PORT = 993
[42] Fix | Delete
AllowedVersions = ('IMAP4REV1', 'IMAP4') # Most recent first
[43] Fix | Delete
[44] Fix | Delete
# Maximal line length when calling readline(). This is to prevent
[45] Fix | Delete
# reading arbitrary length lines. RFC 3501 and 2060 (IMAP 4rev1)
[46] Fix | Delete
# don't specify a line length. RFC 2683 suggests limiting client
[47] Fix | Delete
# command lines to 1000 octets and that servers should be prepared
[48] Fix | Delete
# to accept command lines up to 8000 octets, so we used to use 10K here.
[49] Fix | Delete
# In the modern world (eg: gmail) the response to, for example, a
[50] Fix | Delete
# search command can be quite large, so we now use 1M.
[51] Fix | Delete
_MAXLINE = 1000000
[52] Fix | Delete
[53] Fix | Delete
[54] Fix | Delete
# Commands
[55] Fix | Delete
[56] Fix | Delete
Commands = {
[57] Fix | Delete
# name valid states
[58] Fix | Delete
'APPEND': ('AUTH', 'SELECTED'),
[59] Fix | Delete
'AUTHENTICATE': ('NONAUTH',),
[60] Fix | Delete
'CAPABILITY': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
[61] Fix | Delete
'CHECK': ('SELECTED',),
[62] Fix | Delete
'CLOSE': ('SELECTED',),
[63] Fix | Delete
'COPY': ('SELECTED',),
[64] Fix | Delete
'CREATE': ('AUTH', 'SELECTED'),
[65] Fix | Delete
'DELETE': ('AUTH', 'SELECTED'),
[66] Fix | Delete
'DELETEACL': ('AUTH', 'SELECTED'),
[67] Fix | Delete
'ENABLE': ('AUTH', ),
[68] Fix | Delete
'EXAMINE': ('AUTH', 'SELECTED'),
[69] Fix | Delete
'EXPUNGE': ('SELECTED',),
[70] Fix | Delete
'FETCH': ('SELECTED',),
[71] Fix | Delete
'GETACL': ('AUTH', 'SELECTED'),
[72] Fix | Delete
'GETANNOTATION':('AUTH', 'SELECTED'),
[73] Fix | Delete
'GETQUOTA': ('AUTH', 'SELECTED'),
[74] Fix | Delete
'GETQUOTAROOT': ('AUTH', 'SELECTED'),
[75] Fix | Delete
'MYRIGHTS': ('AUTH', 'SELECTED'),
[76] Fix | Delete
'LIST': ('AUTH', 'SELECTED'),
[77] Fix | Delete
'LOGIN': ('NONAUTH',),
[78] Fix | Delete
'LOGOUT': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
[79] Fix | Delete
'LSUB': ('AUTH', 'SELECTED'),
[80] Fix | Delete
'MOVE': ('SELECTED',),
[81] Fix | Delete
'NAMESPACE': ('AUTH', 'SELECTED'),
[82] Fix | Delete
'NOOP': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
[83] Fix | Delete
'PARTIAL': ('SELECTED',), # NB: obsolete
[84] Fix | Delete
'PROXYAUTH': ('AUTH',),
[85] Fix | Delete
'RENAME': ('AUTH', 'SELECTED'),
[86] Fix | Delete
'SEARCH': ('SELECTED',),
[87] Fix | Delete
'SELECT': ('AUTH', 'SELECTED'),
[88] Fix | Delete
'SETACL': ('AUTH', 'SELECTED'),
[89] Fix | Delete
'SETANNOTATION':('AUTH', 'SELECTED'),
[90] Fix | Delete
'SETQUOTA': ('AUTH', 'SELECTED'),
[91] Fix | Delete
'SORT': ('SELECTED',),
[92] Fix | Delete
'STARTTLS': ('NONAUTH',),
[93] Fix | Delete
'STATUS': ('AUTH', 'SELECTED'),
[94] Fix | Delete
'STORE': ('SELECTED',),
[95] Fix | Delete
'SUBSCRIBE': ('AUTH', 'SELECTED'),
[96] Fix | Delete
'THREAD': ('SELECTED',),
[97] Fix | Delete
'UID': ('SELECTED',),
[98] Fix | Delete
'UNSUBSCRIBE': ('AUTH', 'SELECTED'),
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
# Patterns to match server responses
[102] Fix | Delete
[103] Fix | Delete
Continuation = re.compile(br'\+( (?P<data>.*))?')
[104] Fix | Delete
Flags = re.compile(br'.*FLAGS \((?P<flags>[^\)]*)\)')
[105] Fix | Delete
InternalDate = re.compile(br'.*INTERNALDATE "'
[106] Fix | Delete
br'(?P<day>[ 0123][0-9])-(?P<mon>[A-Z][a-z][a-z])-(?P<year>[0-9][0-9][0-9][0-9])'
[107] Fix | Delete
br' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
[108] Fix | Delete
br' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
[109] Fix | Delete
br'"')
[110] Fix | Delete
# Literal is no longer used; kept for backward compatibility.
[111] Fix | Delete
Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII)
[112] Fix | Delete
MapCRLF = re.compile(br'\r\n|\r|\n')
[113] Fix | Delete
# We no longer exclude the ']' character from the data portion of the response
[114] Fix | Delete
# code, even though it violates the RFC. Popular IMAP servers such as Gmail
[115] Fix | Delete
# allow flags with ']', and there are programs (including imaplib!) that can
[116] Fix | Delete
# produce them. The problem with this is if the 'text' portion of the response
[117] Fix | Delete
# includes a ']' we'll parse the response wrong (which is the point of the RFC
[118] Fix | Delete
# restriction). However, that seems less likely to be a problem in practice
[119] Fix | Delete
# than being unable to correctly parse flags that include ']' chars, which
[120] Fix | Delete
# was reported as a real-world problem in issue #21815.
[121] Fix | Delete
Response_code = re.compile(br'\[(?P<type>[A-Z-]+)( (?P<data>.*))?\]')
[122] Fix | Delete
Untagged_response = re.compile(br'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
[123] Fix | Delete
# Untagged_status is no longer used; kept for backward compatibility
[124] Fix | Delete
Untagged_status = re.compile(
[125] Fix | Delete
br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?', re.ASCII)
[126] Fix | Delete
# We compile these in _mode_xxx.
[127] Fix | Delete
_Literal = br'.*{(?P<size>\d+)}$'
[128] Fix | Delete
_Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?'
[129] Fix | Delete
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
class IMAP4:
[133] Fix | Delete
[134] Fix | Delete
r"""IMAP4 client class.
[135] Fix | Delete
[136] Fix | Delete
Instantiate with: IMAP4([host[, port]])
[137] Fix | Delete
[138] Fix | Delete
host - host's name (default: localhost);
[139] Fix | Delete
port - port number (default: standard IMAP4 port).
[140] Fix | Delete
[141] Fix | Delete
All IMAP4rev1 commands are supported by methods of the same
[142] Fix | Delete
name (in lower-case).
[143] Fix | Delete
[144] Fix | Delete
All arguments to commands are converted to strings, except for
[145] Fix | Delete
AUTHENTICATE, and the last argument to APPEND which is passed as
[146] Fix | Delete
an IMAP4 literal. If necessary (the string contains any
[147] Fix | Delete
non-printing characters or white-space and isn't enclosed with
[148] Fix | Delete
either parentheses or double quotes) each string is quoted.
[149] Fix | Delete
However, the 'password' argument to the LOGIN command is always
[150] Fix | Delete
quoted. If you want to avoid having an argument string quoted
[151] Fix | Delete
(eg: the 'flags' argument to STORE) then enclose the string in
[152] Fix | Delete
parentheses (eg: "(\Deleted)").
[153] Fix | Delete
[154] Fix | Delete
Each command returns a tuple: (type, [data, ...]) where 'type'
[155] Fix | Delete
is usually 'OK' or 'NO', and 'data' is either the text from the
[156] Fix | Delete
tagged response, or untagged results from command. Each 'data'
[157] Fix | Delete
is either a string, or a tuple. If a tuple, then the first part
[158] Fix | Delete
is the header of the response, and the second part contains
[159] Fix | Delete
the data (ie: 'literal' value).
[160] Fix | Delete
[161] Fix | Delete
Errors raise the exception class <instance>.error("<reason>").
[162] Fix | Delete
IMAP4 server errors raise <instance>.abort("<reason>"),
[163] Fix | Delete
which is a sub-class of 'error'. Mailbox status changes
[164] Fix | Delete
from READ-WRITE to READ-ONLY raise the exception class
[165] Fix | Delete
<instance>.readonly("<reason>"), which is a sub-class of 'abort'.
[166] Fix | Delete
[167] Fix | Delete
"error" exceptions imply a program error.
[168] Fix | Delete
"abort" exceptions imply the connection should be reset, and
[169] Fix | Delete
the command re-tried.
[170] Fix | Delete
"readonly" exceptions imply the command should be re-tried.
[171] Fix | Delete
[172] Fix | Delete
Note: to use this module, you must read the RFCs pertaining to the
[173] Fix | Delete
IMAP4 protocol, as the semantics of the arguments to each IMAP4
[174] Fix | Delete
command are left to the invoker, not to mention the results. Also,
[175] Fix | Delete
most IMAP servers implement a sub-set of the commands available here.
[176] Fix | Delete
"""
[177] Fix | Delete
[178] Fix | Delete
class error(Exception): pass # Logical errors - debug required
[179] Fix | Delete
class abort(error): pass # Service errors - close and retry
[180] Fix | Delete
class readonly(abort): pass # Mailbox status changed to READ-ONLY
[181] Fix | Delete
[182] Fix | Delete
def __init__(self, host='', port=IMAP4_PORT):
[183] Fix | Delete
self.debug = Debug
[184] Fix | Delete
self.state = 'LOGOUT'
[185] Fix | Delete
self.literal = None # A literal argument to a command
[186] Fix | Delete
self.tagged_commands = {} # Tagged commands awaiting response
[187] Fix | Delete
self.untagged_responses = {} # {typ: [data, ...], ...}
[188] Fix | Delete
self.continuation_response = '' # Last continuation response
[189] Fix | Delete
self.is_readonly = False # READ-ONLY desired state
[190] Fix | Delete
self.tagnum = 0
[191] Fix | Delete
self._tls_established = False
[192] Fix | Delete
self._mode_ascii()
[193] Fix | Delete
[194] Fix | Delete
# Open socket to server.
[195] Fix | Delete
[196] Fix | Delete
self.open(host, port)
[197] Fix | Delete
[198] Fix | Delete
try:
[199] Fix | Delete
self._connect()
[200] Fix | Delete
except Exception:
[201] Fix | Delete
try:
[202] Fix | Delete
self.shutdown()
[203] Fix | Delete
except OSError:
[204] Fix | Delete
pass
[205] Fix | Delete
raise
[206] Fix | Delete
[207] Fix | Delete
def _mode_ascii(self):
[208] Fix | Delete
self.utf8_enabled = False
[209] Fix | Delete
self._encoding = 'ascii'
[210] Fix | Delete
self.Literal = re.compile(_Literal, re.ASCII)
[211] Fix | Delete
self.Untagged_status = re.compile(_Untagged_status, re.ASCII)
[212] Fix | Delete
[213] Fix | Delete
[214] Fix | Delete
def _mode_utf8(self):
[215] Fix | Delete
self.utf8_enabled = True
[216] Fix | Delete
self._encoding = 'utf-8'
[217] Fix | Delete
self.Literal = re.compile(_Literal)
[218] Fix | Delete
self.Untagged_status = re.compile(_Untagged_status)
[219] Fix | Delete
[220] Fix | Delete
[221] Fix | Delete
def _connect(self):
[222] Fix | Delete
# Create unique tag for this session,
[223] Fix | Delete
# and compile tagged response matcher.
[224] Fix | Delete
[225] Fix | Delete
self.tagpre = Int2AP(random.randint(4096, 65535))
[226] Fix | Delete
self.tagre = re.compile(br'(?P<tag>'
[227] Fix | Delete
+ self.tagpre
[228] Fix | Delete
+ br'\d+) (?P<type>[A-Z]+) (?P<data>.*)', re.ASCII)
[229] Fix | Delete
[230] Fix | Delete
# Get server welcome message,
[231] Fix | Delete
# request and store CAPABILITY response.
[232] Fix | Delete
[233] Fix | Delete
if __debug__:
[234] Fix | Delete
self._cmd_log_len = 10
[235] Fix | Delete
self._cmd_log_idx = 0
[236] Fix | Delete
self._cmd_log = {} # Last `_cmd_log_len' interactions
[237] Fix | Delete
if self.debug >= 1:
[238] Fix | Delete
self._mesg('imaplib version %s' % __version__)
[239] Fix | Delete
self._mesg('new IMAP4 connection, tag=%s' % self.tagpre)
[240] Fix | Delete
[241] Fix | Delete
self.welcome = self._get_response()
[242] Fix | Delete
if 'PREAUTH' in self.untagged_responses:
[243] Fix | Delete
self.state = 'AUTH'
[244] Fix | Delete
elif 'OK' in self.untagged_responses:
[245] Fix | Delete
self.state = 'NONAUTH'
[246] Fix | Delete
else:
[247] Fix | Delete
raise self.error(self.welcome)
[248] Fix | Delete
[249] Fix | Delete
self._get_capabilities()
[250] Fix | Delete
if __debug__:
[251] Fix | Delete
if self.debug >= 3:
[252] Fix | Delete
self._mesg('CAPABILITIES: %r' % (self.capabilities,))
[253] Fix | Delete
[254] Fix | Delete
for version in AllowedVersions:
[255] Fix | Delete
if not version in self.capabilities:
[256] Fix | Delete
continue
[257] Fix | Delete
self.PROTOCOL_VERSION = version
[258] Fix | Delete
return
[259] Fix | Delete
[260] Fix | Delete
raise self.error('server not IMAP4 compliant')
[261] Fix | Delete
[262] Fix | Delete
[263] Fix | Delete
def __getattr__(self, attr):
[264] Fix | Delete
# Allow UPPERCASE variants of IMAP4 command methods.
[265] Fix | Delete
if attr in Commands:
[266] Fix | Delete
return getattr(self, attr.lower())
[267] Fix | Delete
raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
[268] Fix | Delete
[269] Fix | Delete
def __enter__(self):
[270] Fix | Delete
return self
[271] Fix | Delete
[272] Fix | Delete
def __exit__(self, *args):
[273] Fix | Delete
try:
[274] Fix | Delete
self.logout()
[275] Fix | Delete
except OSError:
[276] Fix | Delete
pass
[277] Fix | Delete
[278] Fix | Delete
[279] Fix | Delete
# Overridable methods
[280] Fix | Delete
[281] Fix | Delete
[282] Fix | Delete
def _create_socket(self):
[283] Fix | Delete
# Default value of IMAP4.host is '', but socket.getaddrinfo()
[284] Fix | Delete
# (which is used by socket.create_connection()) expects None
[285] Fix | Delete
# as a default value for host.
[286] Fix | Delete
host = None if not self.host else self.host
[287] Fix | Delete
return socket.create_connection((host, self.port))
[288] Fix | Delete
[289] Fix | Delete
def open(self, host = '', port = IMAP4_PORT):
[290] Fix | Delete
"""Setup connection to remote server on "host:port"
[291] Fix | Delete
(default: localhost:standard IMAP4 port).
[292] Fix | Delete
This connection will be used by the routines:
[293] Fix | Delete
read, readline, send, shutdown.
[294] Fix | Delete
"""
[295] Fix | Delete
self.host = host
[296] Fix | Delete
self.port = port
[297] Fix | Delete
self.sock = self._create_socket()
[298] Fix | Delete
self.file = self.sock.makefile('rb')
[299] Fix | Delete
[300] Fix | Delete
[301] Fix | Delete
def read(self, size):
[302] Fix | Delete
"""Read 'size' bytes from remote."""
[303] Fix | Delete
return self.file.read(size)
[304] Fix | Delete
[305] Fix | Delete
[306] Fix | Delete
def readline(self):
[307] Fix | Delete
"""Read line from remote."""
[308] Fix | Delete
line = self.file.readline(_MAXLINE + 1)
[309] Fix | Delete
if len(line) > _MAXLINE:
[310] Fix | Delete
raise self.error("got more than %d bytes" % _MAXLINE)
[311] Fix | Delete
return line
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
def send(self, data):
[315] Fix | Delete
"""Send data to remote."""
[316] Fix | Delete
self.sock.sendall(data)
[317] Fix | Delete
[318] Fix | Delete
[319] Fix | Delete
def shutdown(self):
[320] Fix | Delete
"""Close I/O established in "open"."""
[321] Fix | Delete
self.file.close()
[322] Fix | Delete
try:
[323] Fix | Delete
self.sock.shutdown(socket.SHUT_RDWR)
[324] Fix | Delete
except OSError as exc:
[325] Fix | Delete
# The server might already have closed the connection.
[326] Fix | Delete
# On Windows, this may result in WSAEINVAL (error 10022):
[327] Fix | Delete
# An invalid operation was attempted.
[328] Fix | Delete
if (exc.errno != errno.ENOTCONN
[329] Fix | Delete
and getattr(exc, 'winerror', 0) != 10022):
[330] Fix | Delete
raise
[331] Fix | Delete
finally:
[332] Fix | Delete
self.sock.close()
[333] Fix | Delete
[334] Fix | Delete
[335] Fix | Delete
def socket(self):
[336] Fix | Delete
"""Return socket instance used to connect to IMAP4 server.
[337] Fix | Delete
[338] Fix | Delete
socket = <instance>.socket()
[339] Fix | Delete
"""
[340] Fix | Delete
return self.sock
[341] Fix | Delete
[342] Fix | Delete
[343] Fix | Delete
[344] Fix | Delete
# Utility methods
[345] Fix | Delete
[346] Fix | Delete
[347] Fix | Delete
def recent(self):
[348] Fix | Delete
"""Return most recent 'RECENT' responses if any exist,
[349] Fix | Delete
else prompt server for an update using the 'NOOP' command.
[350] Fix | Delete
[351] Fix | Delete
(typ, [data]) = <instance>.recent()
[352] Fix | Delete
[353] Fix | Delete
'data' is None if no new messages,
[354] Fix | Delete
else list of RECENT responses, most recent last.
[355] Fix | Delete
"""
[356] Fix | Delete
name = 'RECENT'
[357] Fix | Delete
typ, dat = self._untagged_response('OK', [None], name)
[358] Fix | Delete
if dat[-1]:
[359] Fix | Delete
return typ, dat
[360] Fix | Delete
typ, dat = self.noop() # Prod server for response
[361] Fix | Delete
return self._untagged_response(typ, dat, name)
[362] Fix | Delete
[363] Fix | Delete
[364] Fix | Delete
def response(self, code):
[365] Fix | Delete
"""Return data for response 'code' if received, or None.
[366] Fix | Delete
[367] Fix | Delete
Old value for response 'code' is cleared.
[368] Fix | Delete
[369] Fix | Delete
(code, [data]) = <instance>.response(code)
[370] Fix | Delete
"""
[371] Fix | Delete
return self._untagged_response(code, [None], code.upper())
[372] Fix | Delete
[373] Fix | Delete
[374] Fix | Delete
[375] Fix | Delete
# IMAP4 commands
[376] Fix | Delete
[377] Fix | Delete
[378] Fix | Delete
def append(self, mailbox, flags, date_time, message):
[379] Fix | Delete
"""Append message to named mailbox.
[380] Fix | Delete
[381] Fix | Delete
(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)
[382] Fix | Delete
[383] Fix | Delete
All args except `message' can be None.
[384] Fix | Delete
"""
[385] Fix | Delete
name = 'APPEND'
[386] Fix | Delete
if not mailbox:
[387] Fix | Delete
mailbox = 'INBOX'
[388] Fix | Delete
if flags:
[389] Fix | Delete
if (flags[0],flags[-1]) != ('(',')'):
[390] Fix | Delete
flags = '(%s)' % flags
[391] Fix | Delete
else:
[392] Fix | Delete
flags = None
[393] Fix | Delete
if date_time:
[394] Fix | Delete
date_time = Time2Internaldate(date_time)
[395] Fix | Delete
else:
[396] Fix | Delete
date_time = None
[397] Fix | Delete
literal = MapCRLF.sub(CRLF, message)
[398] Fix | Delete
if self.utf8_enabled:
[399] Fix | Delete
literal = b'UTF8 (' + literal + b')'
[400] Fix | Delete
self.literal = literal
[401] Fix | Delete
return self._simple_command(name, mailbox, flags, date_time)
[402] Fix | Delete
[403] Fix | Delete
[404] Fix | Delete
def authenticate(self, mechanism, authobject):
[405] Fix | Delete
"""Authenticate command - requires response processing.
[406] Fix | Delete
[407] Fix | Delete
'mechanism' specifies which authentication mechanism is to
[408] Fix | Delete
be used - it must appear in <instance>.capabilities in the
[409] Fix | Delete
form AUTH=<mechanism>.
[410] Fix | Delete
[411] Fix | Delete
'authobject' must be a callable object:
[412] Fix | Delete
[413] Fix | Delete
data = authobject(response)
[414] Fix | Delete
[415] Fix | Delete
It will be called to process server continuation responses; the
[416] Fix | Delete
response argument it is passed will be a bytes. It should return bytes
[417] Fix | Delete
data that will be base64 encoded and sent to the server. It should
[418] Fix | Delete
return None if the client abort response '*' should be sent instead.
[419] Fix | Delete
"""
[420] Fix | Delete
mech = mechanism.upper()
[421] Fix | Delete
# XXX: shouldn't this code be removed, not commented out?
[422] Fix | Delete
#cap = 'AUTH=%s' % mech
[423] Fix | Delete
#if not cap in self.capabilities: # Let the server decide!
[424] Fix | Delete
# raise self.error("Server doesn't allow %s authentication." % mech)
[425] Fix | Delete
self.literal = _Authenticator(authobject).process
[426] Fix | Delete
typ, dat = self._simple_command('AUTHENTICATE', mech)
[427] Fix | Delete
if typ != 'OK':
[428] Fix | Delete
raise self.error(dat[-1].decode('utf-8', 'replace'))
[429] Fix | Delete
self.state = 'AUTH'
[430] Fix | Delete
return typ, dat
[431] Fix | Delete
[432] Fix | Delete
[433] Fix | Delete
def capability(self):
[434] Fix | Delete
"""(typ, [data]) = <instance>.capability()
[435] Fix | Delete
Fetch capabilities list from server."""
[436] Fix | Delete
[437] Fix | Delete
name = 'CAPABILITY'
[438] Fix | Delete
typ, dat = self._simple_command(name)
[439] Fix | Delete
return self._untagged_response(typ, dat, name)
[440] Fix | Delete
[441] Fix | Delete
[442] Fix | Delete
def check(self):
[443] Fix | Delete
"""Checkpoint mailbox on server.
[444] Fix | Delete
[445] Fix | Delete
(typ, [data]) = <instance>.check()
[446] Fix | Delete
"""
[447] Fix | Delete
return self._simple_command('CHECK')
[448] Fix | Delete
[449] Fix | Delete
[450] Fix | Delete
def close(self):
[451] Fix | Delete
"""Close currently selected mailbox.
[452] Fix | Delete
[453] Fix | Delete
Deleted messages are removed from writable mailbox.
[454] Fix | Delete
This is the recommended command before 'LOGOUT'.
[455] Fix | Delete
[456] Fix | Delete
(typ, [data]) = <instance>.close()
[457] Fix | Delete
"""
[458] Fix | Delete
try:
[459] Fix | Delete
typ, dat = self._simple_command('CLOSE')
[460] Fix | Delete
finally:
[461] Fix | Delete
self.state = 'AUTH'
[462] Fix | Delete
return typ, dat
[463] Fix | Delete
[464] Fix | Delete
[465] Fix | Delete
def copy(self, message_set, new_mailbox):
[466] Fix | Delete
"""Copy 'message_set' messages onto end of 'new_mailbox'.
[467] Fix | Delete
[468] Fix | Delete
(typ, [data]) = <instance>.copy(message_set, new_mailbox)
[469] Fix | Delete
"""
[470] Fix | Delete
return self._simple_command('COPY', message_set, new_mailbox)
[471] Fix | Delete
[472] Fix | Delete
[473] Fix | Delete
def create(self, mailbox):
[474] Fix | Delete
"""Create new mailbox.
[475] Fix | Delete
[476] Fix | Delete
(typ, [data]) = <instance>.create(mailbox)
[477] Fix | Delete
"""
[478] Fix | Delete
return self._simple_command('CREATE', mailbox)
[479] Fix | Delete
[480] Fix | Delete
[481] Fix | Delete
def delete(self, mailbox):
[482] Fix | Delete
"""Delete old mailbox.
[483] Fix | Delete
[484] Fix | Delete
(typ, [data]) = <instance>.delete(mailbox)
[485] Fix | Delete
"""
[486] Fix | Delete
return self._simple_command('DELETE', mailbox)
[487] Fix | Delete
[488] Fix | Delete
def deleteacl(self, mailbox, who):
[489] Fix | Delete
"""Delete the ACLs (remove any rights) set for who on mailbox.
[490] Fix | Delete
[491] Fix | Delete
(typ, [data]) = <instance>.deleteacl(mailbox, who)
[492] Fix | Delete
"""
[493] Fix | Delete
return self._simple_command('DELETEACL', mailbox, who)
[494] Fix | Delete
[495] Fix | Delete
def enable(self, capability):
[496] Fix | Delete
"""Send an RFC5161 enable string to the server.
[497] Fix | Delete
[498] Fix | Delete
(typ, [data]) = <intance>.enable(capability)
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function