]> code.delx.au - offlineimap/commitdiff
/offlineimap/head: changeset 258
authorjgoerzen <jgoerzen>
Mon, 7 Oct 2002 20:18:02 +0000 (21:18 +0100)
committerjgoerzen <jgoerzen>
Mon, 7 Oct 2002 20:18:02 +0000 (21:18 +0100)
Added a workaround to imaputil.py to deal with a bug in imaplib.py's
tuple when a response contains a literal in certain cases.

offlineimap/head/debian/changelog
offlineimap/head/offlineimap/imaputil.py

index afa6069a63425d6ce30e1926bebb7aa39a8a10e5..f21a93d2bdedff44db04bd87ee99652498813182 100644 (file)
@@ -3,6 +3,8 @@ offlineimap (3.2.9) unstable; urgency=low
   * imaputil.py now logs information with IMAP debugging is enabled.
   * Added folderfilter capability to mbnames recorder.  You can now omit
     specified folders from the mbnames output.
+  * Added a workaround to imaputil.py to deal with a bug in imaplib.py's
+    tuple when a response contains a literal in certain cases.
 
  -- John Goerzen <jgoerzen@complete.org>  Mon, 30 Sep 2002 12:08:08 -0500
 
index c67e56beadbedc6dcf90098db65754cd6e74bdb1..0b8eb9c9bf34afd456931576e01f76bb682d4d33 100644 (file)
@@ -16,7 +16,7 @@
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-import re, string
+import re, string, types
 quotere = re.compile('^("(?:[^"]|\\\\")*")')
 import __main__
 
@@ -69,6 +69,45 @@ def imapsplit(imapstring):
     ['(\\HasNoChildren)', '"."', '"INBOX.Sent"']"""
 
     debug("imapsplit() called with input:", imapstring)
+    if type(imapstring) != types.StringType:
+        debug("imapsplit() got a non-string input; working around.")
+        # Sometimes, imaplib will throw us a tuple if the input
+        # contains a literal.  See Python bug
+        # #619732 at https://sourceforge.net/tracker/index.php?func=detail&aid=619732&group_id=5470&atid=105470
+        # One example is:
+        # result[0] = '() "\\\\" Admin'
+        # result[1] = ('() "\\\\" {19}', 'Folder\\2')
+        #
+        # This function will effectively get result[0] or result[1], so
+        # if we get the result[1] version, we need to parse apart the tuple
+        # and figure out what to do with it.  Each even-numbered
+        # part of it should end with the {} number, and each odd-numbered
+        # part should be directly a part of the result.  We'll
+        # artificially quote it to help out.
+        retval = []
+        for i in range(len(imapstring)):
+            if i % 2:                   # Odd: quote then append.
+                arg = imapstring[i]
+                # Quote code lifted from imaplib
+                arg = arg.replace('\\', '\\\\')
+                arg = arg.replace('"', '\\"')
+                arg = '"%s"' % arg
+                debug("imapsplit() non-string [%d]: Appending %s" %\
+                      (i, arg))
+                retval.append(arg)
+            else:
+                # Even -- we have a string that ends with a literal
+                # size specifier.  We need to strip off that, then run
+                # what remains through the regular imapsplit parser.
+                # Recursion to the rescue.
+                arg = imapstring[i]
+                arg = re.replace('\{\d+\}$', '', arg)
+                debug("imapsplit() non-string [%d]: Feeding %s to recursion" %\
+                      arg)
+                retval.extend(imapsplit(imapstring[i]))
+        debug("imapsplit() non-string: returning %s" % str(retval))
+        return retval
+        
     workstr = imapstring.strip()
     retval = []
     while len(workstr):