From 9eff85dd0cc52c85fdc4dbeb5d96a113752a975a Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Thu, 20 Jun 2002 15:09:19 +0100 Subject: [PATCH] /head: changeset 20 Fixed several bugs in imaplib, particularly with regard to read() --- head/offlineimap/folder/IMAP.py | 1 + head/offlineimap/folder/Maildir.py | 6 +++--- head/offlineimap/imaplib.py | 12 +++++++++--- head/offlineimap/imapserver.py | 4 ++++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/head/offlineimap/folder/IMAP.py b/head/offlineimap/folder/IMAP.py index 30dfbfc..b00d7e4 100644 --- a/head/offlineimap/folder/IMAP.py +++ b/head/offlineimap/folder/IMAP.py @@ -54,6 +54,7 @@ class IMAPFolder(BaseFolder): return self.messagelist def getmessage(self, uid): + print "***************** GETMESSAGE %d" % uid assert(self.imapobj.select(self.getfullname())[0] == 'OK') return self.imapobj.uid('fetch', '%d' % uid, '(RFC822)')[1][0][1] diff --git a/head/offlineimap/folder/Maildir.py b/head/offlineimap/folder/Maildir.py index 2ff9203..0efe822 100644 --- a/head/offlineimap/folder/Maildir.py +++ b/head/offlineimap/folder/Maildir.py @@ -76,14 +76,14 @@ class MaildirFolder(BaseFolder): nouidcounter -= 1 else: uid = long(uidmatch.group(1)) - flagmatch = re.search(':.*2,([A-Z]+)') + flagmatch = re.search(':.*2,([A-Z]+)', messagename) flags = [] if flagmatch: - flags = [f for x in flagmatch.group(1)] + flags = [x for x in flagmatch.group(1)] flags.sort() self.messagelist[uid] = {'uid': uid, 'flags': flags, - 'filename': messagename} + 'filename': file} def getmessagelist(self): return self.messagelist diff --git a/head/offlineimap/imaplib.py b/head/offlineimap/imaplib.py index 2a7630b..25c7afc 100644 --- a/head/offlineimap/imaplib.py +++ b/head/offlineimap/imaplib.py @@ -222,8 +222,10 @@ class IMAP4: 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.""" @@ -858,6 +860,7 @@ class IMAP4: if self.debug >= 4: self._mesg('read literal size %s' % size) data = self.read(size) + print "Got data size %d" % len(data) # Store response with literal as tuple @@ -1056,7 +1059,10 @@ class IMAP4_SSL(IMAP4): 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): diff --git a/head/offlineimap/imapserver.py b/head/offlineimap/imapserver.py index 83621f5..3d8dac5 100644 --- a/head/offlineimap/imapserver.py +++ b/head/offlineimap/imapserver.py @@ -32,6 +32,7 @@ class IMAPServer: self.port = 993 else: self.port = 143 + self.imapobj = None def getdelim(self): """Returns this server's folder delimiter. Can only be called @@ -47,6 +48,8 @@ class IMAPServer: """Opens a connection to the server and returns an appropriate object.""" + if self.imapobj != None: + return self.imapobj imapobj = None if self.usessl: imapobj = imaplib.IMAP4_SSL(self.hostname, self.port) @@ -61,6 +64,7 @@ class IMAPServer: self.delim = imaputil.dequote(self.delim) self.root = imaputil.dequote(self.root) + self.imapobj = imapobj return imapobj