Apple - How to sort new folders alphabetically in OS X Mail?

I am running Mac OS Sierra on a late 2009 iMac 27". My Mac iCloud account mailboxes were NOT in alphabetical order and I have too many to manually sort. Disabling and enabling IMAP Mail for my Mac iCloud account did not work for me. This did the trick perfectly.

  1. Stop Mac application
  2. Run these commands at a command line prompt in bash or ksh. (Substitute your user name where you see "steve" below. Substitute whatever you like for "Nov-12-2016". That is just arbitrary stuff to rename the files and to be able to find them if needed later):
cd /Users/steve/library/Mail/V4

for file in $(find . -name .mboxCache.plist)
do
    print mv $file ${file}.Nov-12-2016
    mv $file ${file}.Nov-12-2016
done

I really wish Apple would just fix this bug once and for all. But until they do, when I see my Mailboxes are out of order I will run my script.

I cannot figure out how to get this simple ksh code to format correctly here, even though I read the help and tried the code and block quote buttons. So the code as shown has too many empty lines and spaces. Sorry for that.

Steve Price


Steve Price's answer pointed me in the right direction. I'm running El Capitan, and found the .mboxCache.plist files under /Users/my login/Library/Mail/V3. The file is a text file, and can be edited with a text editor (after closing the mail program).

For folders appearing in the wrong place, the problematic entries are as follows:

                    <key>MailboxDisplayIndex</key>
                    <integer>0</integer>

The value "0" puts the folder at the beginning, higher values go later in the list.

If you simply remove the two above lines for any folder appearing in the wrong place, and restart Mail, those folders will go back to being sorted alphabetically.

Sometimes the following two lines also appear in combination with the above:

                    <key>MailboxIsManuallySorted</key>
                    <true/>

In those cases, I changed "true" to "false".

Now my folders are back where I want them, yay!