IOS Mail: Emails are listed in wrong order

emailgmailiosmail.appmobile-mail

I've recently migrated my email from Google Apps to the free version of Google – however my iPad and iPhone mail apps are ordering my emails in some completely illogical order.

enter image description here

At the top I have new unread emails, then I have emails from October 2013 which then goes backwards down to 2011. Somewhere scattered in those messages are the emails from November 2013 to today.

Other email clients (both on iOS, Windows and the web) don't have this issue, so how can I resolve this?

More details

I can temporarily resolve this if I scroll down to the very bottom of the emails (so loading them all) and then return to the top. At which point all my emails are displayed in the correct date order.

However overnight iOS (presumably) flushes the bottom emails from memory and in the morning I'm back to seeing unread emails at the top followed by the ones from 2013. The ones that I've previously read are now buried somewhere in the list.

  • Clients that don't have this issue: Gmail (web), GMail (iOS app),
    Outlook (Windows), Windows 10 mail (Windows) and Thunderbird
    (Windows).
  • Clients that do have this issue: iOS Mail for iPad, iOS Mail
    for iPhone.

I've tried importing my emails between Google accounts in multiple ways, none of which have made any difference to the iOS Mail clients:

  1. Getting the new Gmail account to pull emails via POP3 from the old email account
  2. Using Thunderbird to link both old and new accounts and then transfer the emails between the two via IMAP
  3. Same as #2, but using a local folder as an intermediary – as suggested by this answer.

Bizarrely, when I did #2 for "Sent Items", iOS Mail presents them in the correct order!

Finally, this has nothing to do with threading of emails. I've tried turning that on and off and it makes no difference.

Does anyone know how I can fix this?

Best Answer

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).