From 099e61499c2c6a244e8f8416c6431690c70aab6e Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Tue, 17 Feb 2009 23:45:58 +0000 Subject: [PATCH] See ChangeLog Monotone-Parent: 878b0a3e701f87665e2ba4cf8ce540e2a8249c27 Monotone-Revision: 77d1441139223ab426bd10fee87d648b0711aeff Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2009-02-17T23:45:58 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 3 +++ UI/MailerUI/UIxMailListView.m | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2dc50ace..a6bc67821 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,9 @@ 2009-02-17 Francis Lachapelle + * UI/MailerUI/UIxMailListView.m ([UIxMailListView -messages]): + forced ordering of messages based on sorted UIDs. + * UI/Contacts/UIxContactFoldersView.m ([UIxContactFoldersView -allContactSearchAction]): replaced references to "displayName" by "c_cn", following changes made on 2009-02-06. diff --git a/UI/MailerUI/UIxMailListView.m b/UI/MailerUI/UIxMailListView.m index 002f4332e..0ee6599fb 100644 --- a/UI/MailerUI/UIxMailListView.m +++ b/UI/MailerUI/UIxMailListView.m @@ -460,9 +460,11 @@ - (NSArray *) messages { NSArray *uids; - NSDictionary *msgs; + NSDictionary *msgs, *msg; + NSEnumerator *msgsList; + NSMutableArray *unsortedMsgs, *sortedMsgs; NSRange r; - unsigned len; + unsigned len, index; if (!messages) { @@ -470,12 +472,26 @@ uids = [self sortedUIDs]; len = [uids count]; if (len > r.length) - /* only need to restrict if we have a lot */ - uids = [uids subarrayWithRange: r]; - + /* only need to restrict if we have a lot */ + uids = [uids subarrayWithRange: r]; + + // Don't assume the IMAP server return the messages in the + // same order as the specified list of UIDs (specially true for + // dovecot). msgs = (NSDictionary *) [[self clientObject] fetchUIDs: uids parts: [self fetchKeys]]; - messages = [[msgs objectForKey: @"fetch"] retain]; + unsortedMsgs = [msgs objectForKey: @"fetch"]; + sortedMsgs = [NSMutableArray arrayWithCapacity: [unsortedMsgs count]]; + msgsList = [unsortedMsgs objectEnumerator]; + while ( (msg = [msgsList nextObject]) ) + { + index = [uids indexOfObject: [msg objectForKey: @"uid"]]; + if (index < [sortedMsgs count]) + [sortedMsgs insertObject: msg atIndex: index]; + else + [sortedMsgs addObject: msg]; + } + messages = [[NSArray arrayWithArray: sortedMsgs] retain]; } return messages;