Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6884af70
Commit
6884af70
authored
May 29, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Piers Lauders' latest version, with some of my own changes reapplied.
Also replaced random()*32000 with randint(0, 31999).
parent
ed6219b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
10 deletions
+31
-10
Lib/imaplib.py
Lib/imaplib.py
+31
-10
No files found.
Lib/imaplib.py
View file @
6884af70
...
...
@@ -77,9 +77,16 @@ class IMAP4:
port
-
port
number
(
default
:
standard
IMAP4
port
).
All
IMAP4rev1
commands
are
supported
by
methods
of
the
same
name
(
in
lower
-
case
).
Each
command
returns
a
tuple
:
(
type
,
[
data
,
...])
where
'type'
is
usually
'OK'
or
'NO'
,
and
'data'
is
either
the
text
from
the
tagged
response
,
or
untagged
results
from
command
.
name
(
in
lower
-
case
).
All
arguments
to
commands
are
converted
to
strings
,
except
for
the
last
argument
to
APPEND
which
is
passed
as
an
IMAP4
literal
.
If
necessary
(
the
string
isn
't enclosed with either
parentheses or double quotes) each converted string is quoted.
Each command returns a tuple: (type, [data, ...]) where '
type
'
is usually '
OK
' or '
NO
', and '
data
' is either the text from the
tagged response, or untagged results from command.
Errors raise the exception class <instance>.error("<reason>").
IMAP4 server errors raise <instance>.abort("<reason>"),
...
...
@@ -95,6 +102,7 @@ class IMAP4:
self.port = port
self.debug = Debug
self.state = '
LOGOUT
'
self.literal = None # A literal argument to a command
self.tagged_commands = {} # Tagged commands awaiting response
self.untagged_responses = {} # {typ: [data, ...], ...}
self.continuation_response = '' # Last continuation response
...
...
@@ -109,7 +117,7 @@ class IMAP4:
# Create unique tag for this session,
# and compile tagged response matcher.
self.tagpre = Int2AP(random.rand
om()*32000
)
self.tagpre = Int2AP(random.rand
int(0, 31999)
)
self.tagre = re.compile(r'
(
?
P
<
tag
>
'
+ self.tagpre
+ r'
\
d
+
)
(
?
P
<
type
>
[
A
-
Z
]
+
)
(
?
P
<
data
>
.
*
)
')
...
...
@@ -172,7 +180,8 @@ class IMAP4:
date_time = Time2Internaldate(date_time)
else:
date_time = None
return self._simple_command(name, mailbox, flags, date_time, message)
self.literal = message
return self._simple_command(name, mailbox, flags, date_time)
def authenticate(self, func):
...
...
@@ -310,10 +319,18 @@ class IMAP4:
return self._untagged_response(typ, name)
def
recent
(self):
"""
Prompt
server
for
an
update
.
def
noop
(self):
"""
Send NOOP command
.
Flush
all
untagged
responses
.
(typ, data) = <instance>.noop()
"""
return self._simple_command('
NOOP
')
def recent(self):
"""Return most recent '
RECENT
' response if it exists,
else prompt server for an update using the '
NOOP
' command,
and flush all untagged responses.
(typ, [data]) = <instance>.recent()
...
...
@@ -468,15 +485,16 @@ class IMAP4:
print '
\
tuntagged_responses
[
%
s
]
+=
%
.
20
s
..
' % (typ, `dat`)
def _command(self, name,
dat1=None, dat2=None, dat3=None, literal=None
):
def _command(self, name,
*args
):
if self.state not in Commands[name]:
self.literal = None
raise self.error(
'
command
%
s
illegal
in
state
%
s
' % (name, self.state))
tag = self._new_tag()
data = '
%
s
%
s
' % (tag, name)
for d in
(dat1, dat2, dat3)
:
for d in
args
:
if d is None: continue
if type(d) is type(''):
l = len(string.split(d))
...
...
@@ -486,7 +504,10 @@ class IMAP4:
data = '
%
s
"%s"' % (data, d)
else:
data = '
%
s
%
s
' % (data, d)
literal = self.literal
if literal is not None:
self.literal = None
data = '
%
s
{
%
s
}
' % (data, len(literal))
try:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment