imaputil: make uid_sequence sort all items to improve collapsing
To preserve previous behavior and save a few CPU cycles, we were not sorting UID lists and only collapsed them if they were alreay sorted. Vincent pointed out that this is not always the case and unsorted lists lead to non-optimally collapsing. Force lists to numeric types and sort them before collapsing. Reported-by: Beffara <vbeffara@ens-lyon.fr> Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
f0869e5c0f
commit
54d3307499
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user