Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/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
'UNSELECT': ('SELECTED',),
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
# Patterns to match server responses
[103] Fix | Delete
[104] Fix | Delete
Continuation = re.compile(br'\+( (?P<data>.*))?')
[105] Fix | Delete
Flags = re.compile(br'.*FLAGS \((?P<flags>[^\)]*)\)')
[106] Fix | Delete
InternalDate = re.compile(br'.*INTERNALDATE "'
[107] 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])'
[108] Fix | Delete
br' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
[109] Fix | Delete
br' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
[110] Fix | Delete
br'"')
[111] Fix | Delete
# Literal is no longer used; kept for backward compatibility.
[112] Fix | Delete
Literal = re.compile(br'.*{(?P<size>\d+)}$', re.ASCII)
[113] Fix | Delete
MapCRLF = re.compile(br'\r\n|\r|\n')
[114] Fix | Delete
# We no longer exclude the ']' character from the data portion of the response
[115] Fix | Delete
# code, even though it violates the RFC. Popular IMAP servers such as Gmail
[116] Fix | Delete
# allow flags with ']', and there are programs (including imaplib!) that can
[117] Fix | Delete
# produce them. The problem with this is if the 'text' portion of the response
[118] Fix | Delete
# includes a ']' we'll parse the response wrong (which is the point of the RFC
[119] Fix | Delete
# restriction). However, that seems less likely to be a problem in practice
[120] Fix | Delete
# than being unable to correctly parse flags that include ']' chars, which
[121] Fix | Delete
# was reported as a real-world problem in issue #21815.
[122] Fix | Delete
Response_code = re.compile(br'\[(?P<type>[A-Z-]+)( (?P<data>.*))?\]')
[123] Fix | Delete
Untagged_response = re.compile(br'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
[124] Fix | Delete
# Untagged_status is no longer used; kept for backward compatibility
[125] Fix | Delete
Untagged_status = re.compile(
[126] Fix | Delete
br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?', re.ASCII)
[127] Fix | Delete
# We compile these in _mode_xxx.
[128] Fix | Delete
_Literal = br'.*{(?P<size>\d+)}$'
[129] Fix | Delete
_Untagged_status = br'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?'
[130] Fix | Delete
[131] Fix | Delete
[132] Fix | Delete
[133] Fix | Delete
class IMAP4:
[134] Fix | Delete
[135] Fix | Delete
r"""IMAP4 client class.
[136] Fix | Delete
[137] Fix | Delete
Instantiate with: IMAP4([host[, port[, timeout=None]]])
[138] Fix | Delete
[139] Fix | Delete
host - host's name (default: localhost);
[140] Fix | Delete
port - port number (default: standard IMAP4 port).
[141] Fix | Delete
timeout - socket timeout (default: None)
[142] Fix | Delete
If timeout is not given or is None,
[143] Fix | Delete
the global default socket timeout is used
[144] Fix | Delete
[145] Fix | Delete
All IMAP4rev1 commands are supported by methods of the same
[146] Fix | Delete
name (in lower-case).
[147] Fix | Delete
[148] Fix | Delete
All arguments to commands are converted to strings, except for
[149] Fix | Delete
AUTHENTICATE, and the last argument to APPEND which is passed as
[150] Fix | Delete
an IMAP4 literal. If necessary (the string contains any
[151] Fix | Delete
non-printing characters or white-space and isn't enclosed with
[152] Fix | Delete
either parentheses or double quotes) each string is quoted.
[153] Fix | Delete
However, the 'password' argument to the LOGIN command is always
[154] Fix | Delete
quoted. If you want to avoid having an argument string quoted
[155] Fix | Delete
(eg: the 'flags' argument to STORE) then enclose the string in
[156] Fix | Delete
parentheses (eg: "(\Deleted)").
[157] Fix | Delete
[158] Fix | Delete
Each command returns a tuple: (type, [data, ...]) where 'type'
[159] Fix | Delete
is usually 'OK' or 'NO', and 'data' is either the text from the
[160] Fix | Delete
tagged response, or untagged results from command. Each 'data'
[161] Fix | Delete
is either a string, or a tuple. If a tuple, then the first part
[162] Fix | Delete
is the header of the response, and the second part contains
[163] Fix | Delete
the data (ie: 'literal' value).
[164] Fix | Delete
[165] Fix | Delete
Errors raise the exception class <instance>.error("<reason>").
[166] Fix | Delete
IMAP4 server errors raise <instance>.abort("<reason>"),
[167] Fix | Delete
which is a sub-class of 'error'. Mailbox status changes
[168] Fix | Delete
from READ-WRITE to READ-ONLY raise the exception class
[169] Fix | Delete
<instance>.readonly("<reason>"), which is a sub-class of 'abort'.
[170] Fix | Delete
[171] Fix | Delete
"error" exceptions imply a program error.
[172] Fix | Delete
"abort" exceptions imply the connection should be reset, and
[173] Fix | Delete
the command re-tried.
[174] Fix | Delete
"readonly" exceptions imply the command should be re-tried.
[175] Fix | Delete
[176] Fix | Delete
Note: to use this module, you must read the RFCs pertaining to the
[177] Fix | Delete
IMAP4 protocol, as the semantics of the arguments to each IMAP4
[178] Fix | Delete
command are left to the invoker, not to mention the results. Also,
[179] Fix | Delete
most IMAP servers implement a sub-set of the commands available here.
[180] Fix | Delete
"""
[181] Fix | Delete
[182] Fix | Delete
class error(Exception): pass # Logical errors - debug required
[183] Fix | Delete
class abort(error): pass # Service errors - close and retry
[184] Fix | Delete
class readonly(abort): pass # Mailbox status changed to READ-ONLY
[185] Fix | Delete
[186] Fix | Delete
def __init__(self, host='', port=IMAP4_PORT, timeout=None):
[187] Fix | Delete
self.debug = Debug
[188] Fix | Delete
self.state = 'LOGOUT'
[189] Fix | Delete
self.literal = None # A literal argument to a command
[190] Fix | Delete
self.tagged_commands = {} # Tagged commands awaiting response
[191] Fix | Delete
self.untagged_responses = {} # {typ: [data, ...], ...}
[192] Fix | Delete
self.continuation_response = '' # Last continuation response
[193] Fix | Delete
self.is_readonly = False # READ-ONLY desired state
[194] Fix | Delete
self.tagnum = 0
[195] Fix | Delete
self._tls_established = False
[196] Fix | Delete
self._mode_ascii()
[197] Fix | Delete
[198] Fix | Delete
# Open socket to server.
[199] Fix | Delete
[200] Fix | Delete
self.open(host, port, timeout)
[201] Fix | Delete
[202] Fix | Delete
try:
[203] Fix | Delete
self._connect()
[204] Fix | Delete
except Exception:
[205] Fix | Delete
try:
[206] Fix | Delete
self.shutdown()
[207] Fix | Delete
except OSError:
[208] Fix | Delete
pass
[209] Fix | Delete
raise
[210] Fix | Delete
[211] Fix | Delete
def _mode_ascii(self):
[212] Fix | Delete
self.utf8_enabled = False
[213] Fix | Delete
self._encoding = 'ascii'
[214] Fix | Delete
self.Literal = re.compile(_Literal, re.ASCII)
[215] Fix | Delete
self.Untagged_status = re.compile(_Untagged_status, re.ASCII)
[216] Fix | Delete
[217] Fix | Delete
[218] Fix | Delete
def _mode_utf8(self):
[219] Fix | Delete
self.utf8_enabled = True
[220] Fix | Delete
self._encoding = 'utf-8'
[221] Fix | Delete
self.Literal = re.compile(_Literal)
[222] Fix | Delete
self.Untagged_status = re.compile(_Untagged_status)
[223] Fix | Delete
[224] Fix | Delete
[225] Fix | Delete
def _connect(self):
[226] Fix | Delete
# Create unique tag for this session,
[227] Fix | Delete
# and compile tagged response matcher.
[228] Fix | Delete
[229] Fix | Delete
self.tagpre = Int2AP(random.randint(4096, 65535))
[230] Fix | Delete
self.tagre = re.compile(br'(?P<tag>'
[231] Fix | Delete
+ self.tagpre
[232] Fix | Delete
+ br'\d+) (?P<type>[A-Z]+) (?P<data>.*)', re.ASCII)
[233] Fix | Delete
[234] Fix | Delete
# Get server welcome message,
[235] Fix | Delete
# request and store CAPABILITY response.
[236] Fix | Delete
[237] Fix | Delete
if __debug__:
[238] Fix | Delete
self._cmd_log_len = 10
[239] Fix | Delete
self._cmd_log_idx = 0
[240] Fix | Delete
self._cmd_log = {} # Last `_cmd_log_len' interactions
[241] Fix | Delete
if self.debug >= 1:
[242] Fix | Delete
self._mesg('imaplib version %s' % __version__)
[243] Fix | Delete
self._mesg('new IMAP4 connection, tag=%s' % self.tagpre)
[244] Fix | Delete
[245] Fix | Delete
self.welcome = self._get_response()
[246] Fix | Delete
if 'PREAUTH' in self.untagged_responses:
[247] Fix | Delete
self.state = 'AUTH'
[248] Fix | Delete
elif 'OK' in self.untagged_responses:
[249] Fix | Delete
self.state = 'NONAUTH'
[250] Fix | Delete
else:
[251] Fix | Delete
raise self.error(self.welcome)
[252] Fix | Delete
[253] Fix | Delete
self._get_capabilities()
[254] Fix | Delete
if __debug__:
[255] Fix | Delete
if self.debug >= 3:
[256] Fix | Delete
self._mesg('CAPABILITIES: %r' % (self.capabilities,))
[257] Fix | Delete
[258] Fix | Delete
for version in AllowedVersions:
[259] Fix | Delete
if not version in self.capabilities:
[260] Fix | Delete
continue
[261] Fix | Delete
self.PROTOCOL_VERSION = version
[262] Fix | Delete
return
[263] Fix | Delete
[264] Fix | Delete
raise self.error('server not IMAP4 compliant')
[265] Fix | Delete
[266] Fix | Delete
[267] Fix | Delete
def __getattr__(self, attr):
[268] Fix | Delete
# Allow UPPERCASE variants of IMAP4 command methods.
[269] Fix | Delete
if attr in Commands:
[270] Fix | Delete
return getattr(self, attr.lower())
[271] Fix | Delete
raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
[272] Fix | Delete
[273] Fix | Delete
def __enter__(self):
[274] Fix | Delete
return self
[275] Fix | Delete
[276] Fix | Delete
def __exit__(self, *args):
[277] Fix | Delete
if self.state == "LOGOUT":
[278] Fix | Delete
return
[279] Fix | Delete
[280] Fix | Delete
try:
[281] Fix | Delete
self.logout()
[282] Fix | Delete
except OSError:
[283] Fix | Delete
pass
[284] Fix | Delete
[285] Fix | Delete
[286] Fix | Delete
# Overridable methods
[287] Fix | Delete
[288] Fix | Delete
[289] Fix | Delete
def _create_socket(self, timeout):
[290] Fix | Delete
# Default value of IMAP4.host is '', but socket.getaddrinfo()
[291] Fix | Delete
# (which is used by socket.create_connection()) expects None
[292] Fix | Delete
# as a default value for host.
[293] Fix | Delete
if timeout is not None and not timeout:
[294] Fix | Delete
raise ValueError('Non-blocking socket (timeout=0) is not supported')
[295] Fix | Delete
host = None if not self.host else self.host
[296] Fix | Delete
sys.audit("imaplib.open", self, self.host, self.port)
[297] Fix | Delete
address = (host, self.port)
[298] Fix | Delete
if timeout is not None:
[299] Fix | Delete
return socket.create_connection(address, timeout)
[300] Fix | Delete
return socket.create_connection(address)
[301] Fix | Delete
[302] Fix | Delete
def open(self, host='', port=IMAP4_PORT, timeout=None):
[303] Fix | Delete
"""Setup connection to remote server on "host:port"
[304] Fix | Delete
(default: localhost:standard IMAP4 port).
[305] Fix | Delete
This connection will be used by the routines:
[306] Fix | Delete
read, readline, send, shutdown.
[307] Fix | Delete
"""
[308] Fix | Delete
self.host = host
[309] Fix | Delete
self.port = port
[310] Fix | Delete
self.sock = self._create_socket(timeout)
[311] Fix | Delete
self.file = self.sock.makefile('rb')
[312] Fix | Delete
[313] Fix | Delete
[314] Fix | Delete
def read(self, size):
[315] Fix | Delete
"""Read 'size' bytes from remote."""
[316] Fix | Delete
return self.file.read(size)
[317] Fix | Delete
[318] Fix | Delete
[319] Fix | Delete
def readline(self):
[320] Fix | Delete
"""Read line from remote."""
[321] Fix | Delete
line = self.file.readline(_MAXLINE + 1)
[322] Fix | Delete
if len(line) > _MAXLINE:
[323] Fix | Delete
raise self.error("got more than %d bytes" % _MAXLINE)
[324] Fix | Delete
return line
[325] Fix | Delete
[326] Fix | Delete
[327] Fix | Delete
def send(self, data):
[328] Fix | Delete
"""Send data to remote."""
[329] Fix | Delete
sys.audit("imaplib.send", self, data)
[330] Fix | Delete
self.sock.sendall(data)
[331] Fix | Delete
[332] Fix | Delete
[333] Fix | Delete
def shutdown(self):
[334] Fix | Delete
"""Close I/O established in "open"."""
[335] Fix | Delete
self.file.close()
[336] Fix | Delete
try:
[337] Fix | Delete
self.sock.shutdown(socket.SHUT_RDWR)
[338] Fix | Delete
except OSError as exc:
[339] Fix | Delete
# The server might already have closed the connection.
[340] Fix | Delete
# On Windows, this may result in WSAEINVAL (error 10022):
[341] Fix | Delete
# An invalid operation was attempted.
[342] Fix | Delete
if (exc.errno != errno.ENOTCONN
[343] Fix | Delete
and getattr(exc, 'winerror', 0) != 10022):
[344] Fix | Delete
raise
[345] Fix | Delete
finally:
[346] Fix | Delete
self.sock.close()
[347] Fix | Delete
[348] Fix | Delete
[349] Fix | Delete
def socket(self):
[350] Fix | Delete
"""Return socket instance used to connect to IMAP4 server.
[351] Fix | Delete
[352] Fix | Delete
socket = <instance>.socket()
[353] Fix | Delete
"""
[354] Fix | Delete
return self.sock
[355] Fix | Delete
[356] Fix | Delete
[357] Fix | Delete
[358] Fix | Delete
# Utility methods
[359] Fix | Delete
[360] Fix | Delete
[361] Fix | Delete
def recent(self):
[362] Fix | Delete
"""Return most recent 'RECENT' responses if any exist,
[363] Fix | Delete
else prompt server for an update using the 'NOOP' command.
[364] Fix | Delete
[365] Fix | Delete
(typ, [data]) = <instance>.recent()
[366] Fix | Delete
[367] Fix | Delete
'data' is None if no new messages,
[368] Fix | Delete
else list of RECENT responses, most recent last.
[369] Fix | Delete
"""
[370] Fix | Delete
name = 'RECENT'
[371] Fix | Delete
typ, dat = self._untagged_response('OK', [None], name)
[372] Fix | Delete
if dat[-1]:
[373] Fix | Delete
return typ, dat
[374] Fix | Delete
typ, dat = self.noop() # Prod server for response
[375] Fix | Delete
return self._untagged_response(typ, dat, name)
[376] Fix | Delete
[377] Fix | Delete
[378] Fix | Delete
def response(self, code):
[379] Fix | Delete
"""Return data for response 'code' if received, or None.
[380] Fix | Delete
[381] Fix | Delete
Old value for response 'code' is cleared.
[382] Fix | Delete
[383] Fix | Delete
(code, [data]) = <instance>.response(code)
[384] Fix | Delete
"""
[385] Fix | Delete
return self._untagged_response(code, [None], code.upper())
[386] Fix | Delete
[387] Fix | Delete
[388] Fix | Delete
[389] Fix | Delete
# IMAP4 commands
[390] Fix | Delete
[391] Fix | Delete
[392] Fix | Delete
def append(self, mailbox, flags, date_time, message):
[393] Fix | Delete
"""Append message to named mailbox.
[394] Fix | Delete
[395] Fix | Delete
(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)
[396] Fix | Delete
[397] Fix | Delete
All args except `message' can be None.
[398] Fix | Delete
"""
[399] Fix | Delete
name = 'APPEND'
[400] Fix | Delete
if not mailbox:
[401] Fix | Delete
mailbox = 'INBOX'
[402] Fix | Delete
if flags:
[403] Fix | Delete
if (flags[0],flags[-1]) != ('(',')'):
[404] Fix | Delete
flags = '(%s)' % flags
[405] Fix | Delete
else:
[406] Fix | Delete
flags = None
[407] Fix | Delete
if date_time:
[408] Fix | Delete
date_time = Time2Internaldate(date_time)
[409] Fix | Delete
else:
[410] Fix | Delete
date_time = None
[411] Fix | Delete
literal = MapCRLF.sub(CRLF, message)
[412] Fix | Delete
if self.utf8_enabled:
[413] Fix | Delete
literal = b'UTF8 (' + literal + b')'
[414] Fix | Delete
self.literal = literal
[415] Fix | Delete
return self._simple_command(name, mailbox, flags, date_time)
[416] Fix | Delete
[417] Fix | Delete
[418] Fix | Delete
def authenticate(self, mechanism, authobject):
[419] Fix | Delete
"""Authenticate command - requires response processing.
[420] Fix | Delete
[421] Fix | Delete
'mechanism' specifies which authentication mechanism is to
[422] Fix | Delete
be used - it must appear in <instance>.capabilities in the
[423] Fix | Delete
form AUTH=<mechanism>.
[424] Fix | Delete
[425] Fix | Delete
'authobject' must be a callable object:
[426] Fix | Delete
[427] Fix | Delete
data = authobject(response)
[428] Fix | Delete
[429] Fix | Delete
It will be called to process server continuation responses; the
[430] Fix | Delete
response argument it is passed will be a bytes. It should return bytes
[431] Fix | Delete
data that will be base64 encoded and sent to the server. It should
[432] Fix | Delete
return None if the client abort response '*' should be sent instead.
[433] Fix | Delete
"""
[434] Fix | Delete
mech = mechanism.upper()
[435] Fix | Delete
# XXX: shouldn't this code be removed, not commented out?
[436] Fix | Delete
#cap = 'AUTH=%s' % mech
[437] Fix | Delete
#if not cap in self.capabilities: # Let the server decide!
[438] Fix | Delete
# raise self.error("Server doesn't allow %s authentication." % mech)
[439] Fix | Delete
self.literal = _Authenticator(authobject).process
[440] Fix | Delete
typ, dat = self._simple_command('AUTHENTICATE', mech)
[441] Fix | Delete
if typ != 'OK':
[442] Fix | Delete
raise self.error(dat[-1].decode('utf-8', 'replace'))
[443] Fix | Delete
self.state = 'AUTH'
[444] Fix | Delete
return typ, dat
[445] Fix | Delete
[446] Fix | Delete
[447] Fix | Delete
def capability(self):
[448] Fix | Delete
"""(typ, [data]) = <instance>.capability()
[449] Fix | Delete
Fetch capabilities list from server."""
[450] Fix | Delete
[451] Fix | Delete
name = 'CAPABILITY'
[452] Fix | Delete
typ, dat = self._simple_command(name)
[453] Fix | Delete
return self._untagged_response(typ, dat, name)
[454] Fix | Delete
[455] Fix | Delete
[456] Fix | Delete
def check(self):
[457] Fix | Delete
"""Checkpoint mailbox on server.
[458] Fix | Delete
[459] Fix | Delete
(typ, [data]) = <instance>.check()
[460] Fix | Delete
"""
[461] Fix | Delete
return self._simple_command('CHECK')
[462] Fix | Delete
[463] Fix | Delete
[464] Fix | Delete
def close(self):
[465] Fix | Delete
"""Close currently selected mailbox.
[466] Fix | Delete
[467] Fix | Delete
Deleted messages are removed from writable mailbox.
[468] Fix | Delete
This is the recommended command before 'LOGOUT'.
[469] Fix | Delete
[470] Fix | Delete
(typ, [data]) = <instance>.close()
[471] Fix | Delete
"""
[472] Fix | Delete
try:
[473] Fix | Delete
typ, dat = self._simple_command('CLOSE')
[474] Fix | Delete
finally:
[475] Fix | Delete
self.state = 'AUTH'
[476] Fix | Delete
return typ, dat
[477] Fix | Delete
[478] Fix | Delete
[479] Fix | Delete
def copy(self, message_set, new_mailbox):
[480] Fix | Delete
"""Copy 'message_set' messages onto end of 'new_mailbox'.
[481] Fix | Delete
[482] Fix | Delete
(typ, [data]) = <instance>.copy(message_set, new_mailbox)
[483] Fix | Delete
"""
[484] Fix | Delete
return self._simple_command('COPY', message_set, new_mailbox)
[485] Fix | Delete
[486] Fix | Delete
[487] Fix | Delete
def create(self, mailbox):
[488] Fix | Delete
"""Create new mailbox.
[489] Fix | Delete
[490] Fix | Delete
(typ, [data]) = <instance>.create(mailbox)
[491] Fix | Delete
"""
[492] Fix | Delete
return self._simple_command('CREATE', mailbox)
[493] Fix | Delete
[494] Fix | Delete
[495] Fix | Delete
def delete(self, mailbox):
[496] Fix | Delete
"""Delete old mailbox.
[497] Fix | Delete
[498] Fix | Delete
(typ, [data]) = <instance>.delete(mailbox)
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function