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;