Merge branch 'ss/improve-collapsing' into next

This commit is contained in:
Nicolas Sebrecht 2011-09-06 19:59:28 +02:00
commit a21bb949af

View File

@ -191,9 +191,10 @@ def flagsmaildir2imap(maildirflaglist):
def uid_sequence(uidlist):
"""Collapse UID lists into shorter sequence sets
[1,2,3,4,5,10,12,13] will return "1:5,10,12:13". This function does
not sort the list, and only collapses if subsequent entries form a
range.
[1,2,3,4,5,10,12,13] will return "1:5,10,12:13". This function
converts items to numeric type and sorts the list to always produce
the minimal collapsed set.
:returns: The collapsed UID list as string"""
def getrange(start, end):
if start == end:
@ -203,9 +204,10 @@ def uid_sequence(uidlist):
if not len(uidlist): return '' # Empty list, return
start, end = None, None
retval = []
# Force items to be longs and sort them
sorted_uids = sorted(map(int, uidlist))
for item in iter(uidlist):
item = int(item)
for item in iter(sorted_uids):
if start == None: # First item
start, end = item, item
elif item == end + 1: # Next item in a range