workaround for imaputil.imapsplit failure on gmail folders with quotes in the name
eichin at gmail.com
Thu Dec 22 03:28:29 GMT 2011
offlineimap/repository/IMAP.py IMAPRepository.getfolders does a flags,
delim, name = imaputil.imapsplit(string) on the individual results of
a listfunction call. Turns out I have a couple of folders with quotes
(0x22) in the folder name (but not around the entire thing); imapsplit
mishandles this - the quotes are backslashed by the time it sees them,
but it doesn't deal with that, and so it returns an extra field which
should be part of the name.
An example folder name of this form is: "Make" Magazine (ORA)
I have a few others as well.
A fix that "works for me", rather than trying to handle backslashes in
the regexp (which might be provably impossible - it'll certainly be
unreadable even if you succeed :-) is to replace the backslash-quote
sequence with a ^A (0x1), perform the re.search, and then swap it
I can't claim this is particularly well tested - while I've run with
it for a dozen hours of syncing, it only applies to 3 of my gmail
folders, and none of my other IMAP folders - although without the fix,
offlineimap blows up before it even tries.
diff --git a/offlineimap/imaputil.py b/offlineimap/imaputil.py
index f583312..1851e69 100644
@@ -141,8 +141,13 @@ def imapsplit(imapstring):
workstr = workstr[rpareni:].lstrip()
elif workstr == '"':
- quotelist = quotere.search(workstr).group(1)
+ # not sure the RE can handle this, so...
+ assert '\1' not in workstr
+ safe_workstr = workstr.replace('\\"', '\1')
+ safe_quotelist = quotere.search(safe_workstr).group(1)
+ quotelist = safe_quotelist.replace('\1', '\\"')
workstr = workstr[len(quotelist):].lstrip()
+ # *maybe* strip backslashes...
splits = string.split(workstr, maxsplit = 1)
_Mark_ <eichin at thok.org> <eichin at gmail.com>
More information about the OfflineIMAP-project