Merge branch 'ss/improve-collapsing' into next
This commit is contained in:
commit
a21bb949af
@ -191,9 +191,10 @@ def flagsmaildir2imap(maildirflaglist):
|
|||||||
def uid_sequence(uidlist):
|
def uid_sequence(uidlist):
|
||||||
"""Collapse UID lists into shorter sequence sets
|
"""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
|
[1,2,3,4,5,10,12,13] will return "1:5,10,12:13". This function
|
||||||
not sort the list, and only collapses if subsequent entries form a
|
converts items to numeric type and sorts the list to always produce
|
||||||
range.
|
the minimal collapsed set.
|
||||||
|
|
||||||
:returns: The collapsed UID list as string"""
|
:returns: The collapsed UID list as string"""
|
||||||
def getrange(start, end):
|
def getrange(start, end):
|
||||||
if start == end:
|
if start == end:
|
||||||
@ -203,9 +204,10 @@ def uid_sequence(uidlist):
|
|||||||
if not len(uidlist): return '' # Empty list, return
|
if not len(uidlist): return '' # Empty list, return
|
||||||
start, end = None, None
|
start, end = None, None
|
||||||
retval = []
|
retval = []
|
||||||
|
# Force items to be longs and sort them
|
||||||
|
sorted_uids = sorted(map(int, uidlist))
|
||||||
|
|
||||||
for item in iter(uidlist):
|
for item in iter(sorted_uids):
|
||||||
item = int(item)
|
|
||||||
if start == None: # First item
|
if start == None: # First item
|
||||||
start, end = item, item
|
start, end = item, item
|
||||||
elif item == end + 1: # Next item in a range
|
elif item == end + 1: # Next item in a range
|
||||||
|
Loading…
x
Reference in New Issue
Block a user