[Python-bugs-list] [ python-Bugs-571334 ] imaplib fetch is broken
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 20 Jun 2002 07:01:59 -0700
Bugs item #571334, was opened at 2002-06-19 16:22
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=571334&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: John Goerzen (jgoerzen)
Assigned to: Piers Lauder (pierslauder)
Summary: imaplib fetch is broken
Initial Comment:
This bug is 100% reproducible in Python 2.2.1 and the
imaplib.py from Python's CVS tree.
They'll send the message body in this form:
{100}
Headers here, body here, (100 characters worth)
This is specified in RFC2060 secion 4.3. imaplib's fetch
chokes on
"unexpected data" in the response.
imaplib should receive this prefix-quoted string properly
and return it in a
non-quoted fashion.
As it is, it is totally impossible to read messages from
most imap servers.
----------------------------------------------------------------------
Comment By: John Goerzen (jgoerzen)
Date: 2002-06-20 09:01
Message:
Logged In: YES
user_id=491567
It turns out that it is a bug in read() in the imaplib. It does not
obey the principle that the read() call will return UP TO the
amount of bytes specified. The below diff fixes it for me. I
have not yet tried append(), but I suspect that the write calls
will have the same problem.
--- imaplib.py 18 Jun 2002 15:36:03 -0000 1.1
+++ imaplib.py 20 Jun 2002 04:02:49 -0000 1.2
@@ -222,8 +222,10 @@
def read(self, size):
"""Read 'size' bytes from remote."""
- return self.file.read(size)
-
+ retval = ''
+ while len(retval) < size:
+ retval += self.file.read(size - len(retval))
+ return retval
def readline(self):
"""Read line from remote."""
@@ -1056,7 +1059,10 @@
def read(self, size):
"""Read 'size' bytes from remote."""
- return self.sslobj.read(size)
+ retval = ''
+ while len(retval) < size:
+ retval += self.sslobj.read(size - len(retval))
+ return retval
def readline(self):
----------------------------------------------------------------------
Comment By: Piers Lauder (pierslauder)
Date: 2002-06-20 03:46
Message:
Logged In: YES
user_id=196212
I can't duplicate this.
The test code at the end of imaplib.py includes a FETCH
command which is returned as a literal by my imap server.
Perhaps you could run that test on your server and cut
and paste the response.
Run the test like this:
python2.2 imaplib.py -d5 <imap_server_host_name>
>From which I get the following:
...
43:26.15 > KDP19 UID FETCH 19570 (FLAGS INTERNALDATE
RFC822.SIZE RFC822.HEADER RFC822.TEXT)
43:26.46 < * 83 FETCH (UID 19570 FLAGS (\Seen)
INTERNALDATE "20-Jun-2002 18:36:51 +1000" RFC822.SIZE 55
RFC822.HEADER {46}
43:26.46 matched r'\* (?P<data>\d+)
(?P<type>[A-Z-]+)( (?P<data2>.*))?' => ('83', 'FETCH', '
(UID 19570 FLAGS (\Seen) INTERNALDATE "20-Jun-2002 18:36:51
+1000" RFC822.SIZE 55 RFC822.HEADER {46}', '(UID 19570 FLAGS
(\Seen) INTERNALDATE "20-Jun-2002 18:36:51 +1000"
RFC822.SIZE 55 RFC822.HEADER {46}')
43:26.46 matched r'.*{(?P<size>\d+)}$' => ('46',)
43:26.47 read literal size 46
...
and so on.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=571334&group_id=5470