Make folders containing quotes work
imaputil.imapsplit did not cope with strings that contained encoded quotation marks, e.g. a folder name '"Make" Magazine' would fail and crash OfflineImap. Make it work by adapting the regex that we use to extract the first quote to also work with encoded \" quotes. (We do no sanity checks that there is an even number of such marks within a string though) This commit makes such folders work. This was reported and analyzed by Mark Eichin. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
parent
d2f8504757
commit
c7df907cf6
@ -13,6 +13,9 @@ others.
|
|||||||
New Features
|
New Features
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
* Make folders containing quotes work rather than crashing
|
||||||
|
(reported by Mark Eichin)
|
||||||
|
|
||||||
Changes
|
Changes
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
@ -25,7 +25,12 @@ try: # python 2.6 has set() built in
|
|||||||
except NameError:
|
except NameError:
|
||||||
from sets import Set as set
|
from sets import Set as set
|
||||||
|
|
||||||
quotere = re.compile('^("(?:[^"]|\\\\")*")')
|
# find the first quote in a string
|
||||||
|
quotere = re.compile(
|
||||||
|
r"""(?P<quote>"(?:\\"|[^"])*") # Quote, possibly containing encoded
|
||||||
|
# quotation mark
|
||||||
|
\s*(?P<rest>.*)$ # Whitespace & remainder of string""",
|
||||||
|
re.VERBOSE)
|
||||||
|
|
||||||
def debug(*args):
|
def debug(*args):
|
||||||
msg = []
|
msg = []
|
||||||
@ -128,6 +133,7 @@ def imapsplit(imapstring):
|
|||||||
workstr = imapstring.strip()
|
workstr = imapstring.strip()
|
||||||
retval = []
|
retval = []
|
||||||
while len(workstr):
|
while len(workstr):
|
||||||
|
# handle parenthized fragments (...()...)
|
||||||
if workstr[0] == '(':
|
if workstr[0] == '(':
|
||||||
rparenc = 1 # count of right parenthesis to match
|
rparenc = 1 # count of right parenthesis to match
|
||||||
rpareni = 1 # position to examine
|
rpareni = 1 # position to examine
|
||||||
@ -141,9 +147,10 @@ def imapsplit(imapstring):
|
|||||||
workstr = workstr[rpareni:].lstrip()
|
workstr = workstr[rpareni:].lstrip()
|
||||||
retval.append(parenlist)
|
retval.append(parenlist)
|
||||||
elif workstr[0] == '"':
|
elif workstr[0] == '"':
|
||||||
quotelist = quotere.search(workstr).group(1)
|
# quoted fragments '"...\"..."'
|
||||||
workstr = workstr[len(quotelist):].lstrip()
|
m = quotere.match(workstr)
|
||||||
retval.append(quotelist)
|
retval.append(m.group('quote'))
|
||||||
|
workstr = m.group('rest')
|
||||||
else:
|
else:
|
||||||
splits = string.split(workstr, maxsplit = 1)
|
splits = string.split(workstr, maxsplit = 1)
|
||||||
splitslen = len(splits)
|
splitslen = len(splits)
|
||||||
@ -161,6 +168,7 @@ def imapsplit(imapstring):
|
|||||||
elif splitslen == 0:
|
elif splitslen == 0:
|
||||||
# There was not even an unquoted word.
|
# There was not even an unquoted word.
|
||||||
break
|
break
|
||||||
|
getglobalui().warn("%s->%s" % (imapstring, retval))
|
||||||
return retval
|
return retval
|
||||||
|
|
||||||
flagmap = [('\\Seen', 'S'),
|
flagmap = [('\\Seen', 'S'),
|
||||||
|
Loading…
Reference in New Issue
Block a user