From 534bea674bb65242fc19e4184924d4d93c5103e3 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 8 Sep 2021 16:54:42 -0400 Subject: [PATCH] fix(mail): properly sort partial fetch results (modseq) Fixes #5385 --- SoObjects/Mailer/SOGoMailFolder.m | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index eb1ee8b72..812814091 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -100,6 +100,22 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) return [modseq1 compare: modseq2]; } +static NSComparisonResult _compareFetchResultsByUID (id entry1, id entry2, NSArray *uids) +{ + NSString *uid1, *uid2; + NSUInteger pos1, pos2; + + uid1 = [entry1 objectForKey: @"uid"]; + uid2 = [entry2 objectForKey: @"uid"]; + pos1 = [uids indexOfObject: uid1]; + pos2 = [uids indexOfObject: uid2]; + + if (pos1 > pos2) + return NSOrderedDescending; + else + return NSOrderedAscending; +} + @interface NGImap4Connection (PrivateMethods) - (NSString *) imap4FolderNameForURL: (NSURL *) url; @@ -2344,6 +2360,11 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data) fetchResults = [fetchResults sortedArrayUsingFunction: _compareFetchResultsByMODSEQ context: NULL]; } + else + { + fetchResults = [fetchResults sortedArrayUsingFunction: (int(*)(id, id, void*))_compareFetchResultsByUID + context: uids]; + } for (i = 0; i < [fetchResults count]; i++) {