Split the IMAP folders
This patch modifies two files. First, we need split using '', not '""'. Else we don't split anything. OTOH, we need convert the bytes to string, then we can parse the folder names.
This commit is contained in:
parent
c9a4b1fefa
commit
22dfbd7a54
@ -599,7 +599,7 @@ class IMAPServer(object):
|
|||||||
imapobj.capabilities = tuple(dat[-1].upper().split())
|
imapobj.capabilities = tuple(dat[-1].upper().split())
|
||||||
|
|
||||||
if self.delim == None:
|
if self.delim == None:
|
||||||
listres = imapobj.list(self.reference, '""')[1]
|
listres = imapobj.list(self.reference, '')[1]
|
||||||
if listres == [None] or listres == None:
|
if listres == [None] or listres == None:
|
||||||
# Some buggy IMAP servers do not respond well to LIST "" ""
|
# Some buggy IMAP servers do not respond well to LIST "" ""
|
||||||
# Work around them.
|
# Work around them.
|
||||||
|
@ -104,42 +104,7 @@ def imapsplit(imapstring):
|
|||||||
['(\\HasNoChildren)', '"."', '"INBOX.Sent"']"""
|
['(\\HasNoChildren)', '"."', '"INBOX.Sent"']"""
|
||||||
|
|
||||||
if not isinstance(imapstring, str):
|
if not isinstance(imapstring, str):
|
||||||
__debug("imapsplit() got a non-string input; working around.")
|
imapstring = imapstring.decode('utf-8')
|
||||||
# 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.sub('\{\d+\}$', '', arg)
|
|
||||||
__debug("imapsplit() non-string [%d]: Feeding %s to recursion"%\
|
|
||||||
(i, arg))
|
|
||||||
retval.extend(imapsplit(arg))
|
|
||||||
__debug("imapsplit() non-string: returning %s" % str(retval))
|
|
||||||
return retval
|
|
||||||
|
|
||||||
workstr = imapstring.strip()
|
workstr = imapstring.strip()
|
||||||
retval = []
|
retval = []
|
||||||
|
Loading…
Reference in New Issue
Block a user