iOS Mail: Emails are listed in wrong order

Solution 1:

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 "Apple isn't looking at the same date for sorting that webmail or Outlook uses", 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 "out of order" 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 "missing" 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).

Solution 2:

The problem is that Apple isn't looking at the same date for sorting that webmail or Outlook uses. I just had a mess cleaning up a user's mailbox that was full at 25GB. Our Rackspace webmail only lets you move 100 items at a time, so I used Outlook so I could grab huge chunks of email to move. Oops !

It did a pretty good job with over 120,000 emails in the mailbox, but eventually the number of items was off. Then I used webmail to move the rest that were orphaned. Looks fine in Outlook 2016 (Office365) and in Rackspace webmail. But on an iPhone or iPad the first week of email was right, then it went to 2016 emails - 2017 and 2018 were no longer where they should be. Messed up, not in correct chronological order.

The solution that a Rackspace tech gave me was via webmail - not Outlook or other device - to move the emails in the Inbox to another folder for 5+ minutes, let everything sync on the server, then copy them back to the Inbox. It fixed all the emails I tried it on. There's 71,000+ in her Inbox, so if having the last few weeks correct on the iPhone is all she needs, I'm done ! I was very happy that a simple move out and back fixed the issue. Hope it helps someone else. There is also the option of using the Outlook app, it may not be affected by the Apple iOS date issue.

Solution 3:

I know this is old but I just had this happen to me on iOS 13. I was trying to mark all email as read and slipped and marked everything as junk... After correcting that nightmare, I noticed my email showing on my phone was very old. I read the solution here about restoring the phone from the backup and I did not want to do that. So the solution I came up with was this and it worked for me.

  1. Log in to your Gmail account online through a browser and select all email in your inbox. Then Chose Archive. This moves all mail out of the Inbox for Gmail but leaves it in the All mail folder.
  2. Go to the All Mail Folder and select the email you want to be back in your inbox. For me I selected the last 100 emails and then chose Move to Inbox.
  3. Drag down on your iPhone to refresh the mail. All your mail that you moved back to the inbox should now be in there in order.

Enjoy....