Skip to content

Commit

Permalink
fix(mail): properly sort partial fetch results (modseq)
Browse files Browse the repository at this point in the history
Fixes #5385
  • Loading branch information
cgx committed Sep 8, 2021
1 parent 2a8d64d commit 534bea6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions SoObjects/Mailer/SOGoMailFolder.m
Expand Up @@ -100,6 +100,22 @@
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;
Expand Down Expand Up @@ -2344,6 +2360,11 @@ - (NSArray *) syncTokenFieldsWithProperties: (NSDictionary *) theProperties
fetchResults = [fetchResults sortedArrayUsingFunction: _compareFetchResultsByMODSEQ
context: NULL];
}
else
{
fetchResults = [fetchResults sortedArrayUsingFunction: (int(*)(id, id, void*))_compareFetchResultsByUID
context: uids];
}

for (i = 0; i < [fetchResults count]; i++)
{
Expand Down

0 comments on commit 534bea6

Please sign in to comment.