iOS Mail: Emails are listed in wrong order
Not sure if anyone will still read this but this question was still pretty high in rank on Google search.
I'm moving a large amount of mails from Gmail to self hosted solution, and also noticed this issue. I believe this is not caused by &quot;Apple isn't looking at the same date for sorting that webmail or Outlook uses&quot;, rather it's because how the app interacts with IMAP servers.
In IMAP servers, all messages in a specific folder has a unique identifier (UID, see RFC 3501 for more technical details). It's a monotonic increasing number, and the UID is assigned to each mail in the order of it's addition to the mailbox in most cases.
The issue is when migrating emails, sometimes it's not guaranteed that the old mails are inserted in chronological order, so they may be partially &quot;out of order&quot; in terms of UID (in my case, the new mailbox is already receiving new mails when old mails are still being imported by imapsync).
My best guess is iOS mail app is only fetching tailing UID range of a folder, and in a normal mailbox it's just fetching the latest mails. However, in the above situation, it may gets mails that could be very old, but for all mails it's already fetched they will be in right chronological order. The time gap is simply because the app didn't actually have those mails downloaded. When you load more mails, the &quot;missing&quot; mails will be eventually downloaded and shown in right order. (I should have verified this by sniffing but didn't, but this should be the most possible explanation.)
The reason Outlook was fine in @Rick Rothwell's case may be that Outlook actually stores all mail headers locally (IIRC) so it can just reorder the mails locally to show them in chronological order. I've checked Roundcube's source code and it uses IMAP SORT command when fetching mails. However that command supposedly is not supported by some servers, and that could be why iOS mail app was not using it.
To fix the issue, I think the most direct approach is to just move the mails to another temp folder then move them back, while making sure that the moving operation is applied in chronological order (older ones first). As the UID of the mails are tracked per-folder, moving them across folders would give them new UIDs, and by making sure that they are assigned UID in right order there would be no issues in iOS mail app (or any other client that has this issue).