summaryrefslogtreecommitdiff
path: root/Lib/imaplib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-02-17 17:12:39 +0000
committerGuido van Rossum <guido@python.org>2000-02-17 17:12:39 +0000
commit0ffdf7acfea183a85eff6a5a2a7b8be7143c3bf1 (patch)
tree94029739e8ab1ccf10f71960585cf4a9ef1d3568 /Lib/imaplib.py
parent5f2aca6137f271cf64ec0e72a56b38c24ddbac2a (diff)
downloadcpython-0ffdf7acfea183a85eff6a5a2a7b8be7143c3bf1.tar.gz
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.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r--Lib/imaplib.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index 0275571323..c65cc90332 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -15,7 +15,7 @@ Public functions: Internaldate2tuple
Time2Internaldate
"""
-__version__ = "2.16"
+__version__ = "2.30"
import binascii, re, socket, string, time, random, sys
@@ -66,7 +66,7 @@ InternalDate = re.compile(r'.*INTERNALDATE "'
r' (?P<hour>[0-9][0-9]):(?P<min>[0-9][0-9]):(?P<sec>[0-9][0-9])'
r' (?P<zonen>[-+])(?P<zoneh>[0-9][0-9])(?P<zonem>[0-9][0-9])'
r'"')
-Literal = re.compile(r'(?P<data>.*) {(?P<size>\d+)}$')
+Literal = re.compile(r'.*{(?P<size>\d+)}$')
Response_code = re.compile(r'\[(?P<type>[A-Z-]+)( (?P<data>[^\]]*))?\]')
Untagged_response = re.compile(r'\* (?P<type>[A-Z-]+)( (?P<data>.*))?')
Untagged_status = re.compile(r'\* (?P<data>\d+) (?P<type>[A-Z-]+)( (?P<data2>.*))?')
@@ -117,7 +117,7 @@ class IMAP4:
class abort(error): pass # Service errors - close and retry
class readonly(abort): pass # Mailbox status changed to READ-ONLY
- mustquote = re.compile(r'\W') # Match any non-alphanumeric character
+ mustquote = re.compile(r"[^\w!#$%&'*+,.:;<=>?^`|~-]")
def __init__(self, host = '', port = IMAP4_PORT):
self.host = host
@@ -699,7 +699,7 @@ class IMAP4:
dat2 = self.mo.group('data2')
if self.mo is None:
- # Only other possibility is '+' (continuation) rsponse...
+ # Only other possibility is '+' (continuation) response...
if self._match(Continuation, resp):
self.continuation_response = self.mo.group('data')
@@ -753,7 +753,19 @@ class IMAP4:
if result is not None:
del self.tagged_commands[tag]
return result
- self._get_response()
+
+ # Some have reported "unexpected response" exceptions.
+ # (Isn't this non-IMAP4-compliant behaviour?
+ # Please mail me details printed below!)
+ # Anyway, ignore them here.
+
+ try:
+ self._get_response()
+ except self.abort, val:
+ if __debug__:
+ if self.debug >= 1:
+ _mesg('abort exception ignored: %s' % val)
+ print_log()
def _get_line(self):
@@ -1015,14 +1027,15 @@ if __name__ == '__main__':
if sys.argv[1:]: host = sys.argv[1]
USER = getpass.getuser()
- PASSWD = getpass.getpass("IMAP password for %s: " % (host or "localhost"))
+ PASSWD = getpass.getpass("IMAP password for %s on %s" % (USER, host or "localhost"))
+ test_mesg = 'From: %s@localhost\nSubject: IMAP4 test\n\ndata...\n' % USER
test_seq1 = (
('login', (USER, PASSWD)),
('create', ('/tmp/xxx 1',)),
('rename', ('/tmp/xxx 1', '/tmp/yyy')),
('CREATE', ('/tmp/yyz 2',)),
- ('append', ('/tmp/yyz 2', None, None, 'From: anon@x.y.z\n\ndata...')),
+ ('append', ('/tmp/yyz 2', None, None, test_mesg)),
('list', ('/tmp', 'yy*')),
('select', ('/tmp/yyz 2',)),
('search', (None, '(TO zork)')),
@@ -1038,7 +1051,7 @@ if __name__ == '__main__':
('response',('UIDVALIDITY',)),
('uid', ('SEARCH', 'ALL')),
('response', ('EXISTS',)),
- ('append', (None, None, None, 'From: anon@x.y.z\n\ndata...')),
+ ('append', (None, None, None, test_mesg)),
('recent', ()),
('logout', ()),
)