Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f36b182

Browse files
committed
Patches by Piers Lauder.
Reasons for patches: 1st patch (15,21): version change 2nd patch (66,72): This is a patch I found in a Zope product release (quite by accident!). It relaxes the conditions for matching a literal. I've looked over the logic, and tested it, and it seems sensible. 3rd patch (117,123): It appears the quoting matcher was too general, and that the IMAP4 protocol requires characters like ':' in commands to be unquoted. (This is the patch already sent to Guido.) 4th patch (699,705): Spelling correction in comment. 5th patch (753,761): Another patch from the Zope product. It seems that some IMAP4 servers produce unexpected responses in the middle of valid command/response sequences. This patch ignores the unexpected responses in this situation. (How I wish users would send me bug reports with examples!). last 2 patches: (1015,1028) (1038,1044): Minor improvements to test code.
1 parent 99aabe3 commit f36b182

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

Lib/imaplib.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
Time2Internaldate
1616
"""
1717

18-
__version__ = "2.16"
18+
__version__ = "2.30"
1919

2020
import binascii, re, socket, string, time, random, sys
2121

@@ -66,7 +66,7 @@
6666
r' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
6767
r' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
6868
r'"')
69-
Literal = re.compile(r'(?P<data>.*) {(?P<size>\d+)}$')
69+
Literal = re.compile(r'.*{(?P<size>\d+)}$')
7070
Response_code = re.compile(r'\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]')
7171
Untagged_response = re.compile(r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
7272
Untagged_status = re.compile(r'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?')
@@ -117,7 +117,7 @@ class error(Exception): pass # Logical errors - debug required
117117
class abort(error): pass # Service errors - close and retry
118118
class readonly(abort): pass # Mailbox status changed to READ-ONLY
119119

120-
mustquote = re.compile(r'\W') # Match any non-alphanumeric character
120+
mustquote = re.compile(r"[^\w!#$%&'*+,.:;<=>?^`|~-]")
121121

122122
def __init__(self, host = '', port = IMAP4_PORT):
123123
self.host = host
@@ -699,7 +699,7 @@ def _get_response(self):
699699
dat2 = self.mo.group('data2')
700700

701701
if self.mo is None:
702-
# Only other possibility is '+' (continuation) rsponse...
702+
# Only other possibility is '+' (continuation) response...
703703

704704
if self._match(Continuation, resp):
705705
self.continuation_response = self.mo.group('data')
@@ -753,7 +753,19 @@ def _get_tagged_response(self, tag):
753753
if result is not None:
754754
del self.tagged_commands[tag]
755755
return result
756-
self._get_response()
756+
757+
# Some have reported "unexpected response" exceptions.
758+
# (Isn't this non-IMAP4-compliant behaviour?
759+
# Please mail me details printed below!)
760+
# Anyway, ignore them here.
761+
762+
try:
763+
self._get_response()
764+
except self.abort, val:
765+
if __debug__:
766+
if self.debug >= 1:
767+
_mesg('abort exception ignored: %s' % val)
768+
print_log()
757769

758770

759771
def _get_line(self):
@@ -1015,14 +1027,15 @@ def print_log():
10151027
if sys.argv[1:]: host = sys.argv[1]
10161028

10171029
USER = getpass.getuser()
1018-
PASSWD = getpass.getpass("IMAP password for %s: " % (host or "localhost"))
1030+
PASSWD = getpass.getpass("IMAP password for %s on %s" % (USER, host or "localhost"))
10191031

1032+
test_mesg = 'From: %s@localhost\nSubject: IMAP4 test\n\ndata...\n' % USER
10201033
test_seq1 = (
10211034
('login', (USER, PASSWD)),
10221035
('create', ('/tmp/xxx 1',)),
10231036
('rename', ('/tmp/xxx 1', '/tmp/yyy')),
10241037
('CREATE', ('/tmp/yyz 2',)),
1025-
('append', ('/tmp/yyz 2', None, None, 'From: [email protected]\n\ndata...')),
1038+
('append', ('/tmp/yyz 2', None, None, test_mesg)),
10261039
('list', ('/tmp', 'yy*')),
10271040
('select', ('/tmp/yyz 2',)),
10281041
('search', (None, '(TO zork)')),
@@ -1038,7 +1051,7 @@ def print_log():
10381051
('response',('UIDVALIDITY',)),
10391052
('uid', ('SEARCH', 'ALL')),
10401053
('response', ('EXISTS',)),
1041-
('append', (None, None, None, 'From: [email protected]\n\ndata...')),
1054+
('append', (None, None, None, test_mesg)),
10421055
('recent', ()),
10431056
('logout', ()),
10441057
)

0 commit comments

Comments
 (0)