Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

smart mailbox unread counts wrong

After upgrading to Mavericks, my smart mailboxes' unread counts are all wrong. I've tried restarting mail and rebuilding mailboxes and recreating the smart mailboxes, but still they are wrong.

Mail-OTHER, OS X Mavericks (10.9)

Posted on Oct 22, 2013 7:40 PM

Reply
Question marked as Best reply

Posted on May 6, 2017 1:53 PM

Bruce Alderson wrote:


I fixed this for my smart mailboxes (Mail.app v7.0 1822) by following these steps:


1. Open a terminal

2. Re-index Spotlight


sudo mdutil -E /


I suspect this is related to Mavericks improvements in Spotlight, as it now indexes Mail.app messages much better than in previous releases.

This solution still works! It just solve a wrong unread counts on a smart mailbox, on macOS Sierra.

Thanks!

114 replies

Oct 23, 2013 7:51 AM in response to jdstil

I need to add to my previous message, I´m afraid. It now looks to me like the whole Apply Rules menu item has stopped working. If I pick it from the drop down menu on some message in the inbox, it does not work; the same message when incoming gets correctly processed and moved to the destination folder though.

Oct 23, 2013 3:34 PM in response to jmfinn9

Similar problem, but a little more bizarre. I have three Macs all of which I updated, but only one exhibited the problem (two MacBook Airs and a Macbook Pro "17). I have done the "fix" twice, as in deleted the envelope files. On the first try, I had three "unread" e-mails and only had one after, but still one of those unread ones that didn't exist.


Thinking perhaps that the anomaly may have been caused due to updating three similarly-configured Macs, I left the other two to do their updates then shut them down and tried the "fix" the second time then let Mail do its thing, having deleted the Unread Smart Mailbox.


Once all of the synching with various accounts was complete, I did the usual Repair Disc Permissions, re-booted, shut down and reset PRAM to be extra careful. When I restarted Mail, I let it check the inboxes the re-created the Unread Smart Mailbox.


The end result? I still have one magically ethereal and un-findable unread e-mail. My other two machines, which are a bit older, are just fine.


Argh.

Oct 23, 2013 4:03 PM in response to RioMacUser

Same here. Got 1500+ unread messages in a smartbox before the Maverick install. After Maverick new messages coming in do appear in this smartbox, but the ones from before are not shown. But they do appear in the count for that smartbox!


I just moved Envelope Index, Envelope Index-shm, and Envelope Index-wal to the desktop from ~/Library/MailV2/Maildata. Envelope Index was 467Mb in my case. Restared Mail. Now staring at a window saying Message Import, Imported 136113 from 788062 messages. Time remaining: 1 hour, 6 minutes.


Good night, let's see tomorrow.

Oct 23, 2013 7:23 PM in response to RioMacUser

This is a good tip, but it unfortunately didn't solve my problem.


Investigating further, my problem seems to be related to Junk mail handling. First, in Mavericks, I had to add 'Not in Junk Folder' to my smart mailboxes, otherwise the mails marked as Junk would be included. After fixing that, the view in the smart mailbox (e.g. 'Today') was correct, but the new message count was still incorrect. But, if I delete messages in the Junk folder, the new count for 'Today' is correct. So it appears that smart mailboxes in maverick can include Junk mail (which it did not in Mountain Lion) and that even if Junk Mail is excluded by rule in the smart mailbox, the 'new mail count' still reflects the unread mail in the Junk folder.


Hope that makes sense, it's hard to describe.

Oct 24, 2013 12:38 AM in response to jmfinn9

Like jmfinn9 my smart mailboxes which were problematic also had the rule 'Not in Junk Folder'. As suggested early in this thread I removed Envelope Index from ~/Library/Mail/ which resulted in 1000+ messages in the Junk box as unread (and the lost that Junk color).


I removed the 'Not in Junk Folder' condition from my smart mailbox. Actually, it changed by itself. It said 'no mailbox selected'. Now slowly slowly the smart mailbox is showing more and more messages as unread. A message from March this year which I had marked as read to start with.


Another smart mailbox has the unread count on 4. But when I choose 'Sort by Unread' they do not appear. And to scroll through the 11227 messages does not help either.


In short, it is a mess and I don't know how to proceed.

Oct 24, 2013 6:24 AM in response to Doc411

I have made some progress, which (fingers crossed) llooks like it might be working. I thought I would report it as it might help someone else in the mean time.


Initially, I made a call to Apple Tech Support who first had me log in as new user, which didn't sort the problem. Then a reinstall of Mavericks, which didn't solve the problem either. Rebuilding mailboxes and repairing permissions had no effect.


Then I noticed that not only were flagged emails not being correctly gathered, but search was not working either; no results were shown. I created a Smart Mailbox by saving the search--still nothing. Looking through some other threads, I found a suggestion to reindex the Mail folder in Spotlight per this article http://support.apple.com/kb/ht2409. This didn't work because I got a "Privacy List error" whenever I tried to add a folder to the privacy tab.


Researching this error message lead me to this thread, https://discussions.apple.com/thread/3587838?answerId=22754118022#22754118022, in essence, the action was to issue the following Terminal commands, which would suspend the Spotlight server.


sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist

sudo mdutil -E /


After this I added and removed my Macintosh HD to the Spotlight privacy tab, which kicked off reindexing.


Back in Mail, I clicked on each flagged message. This created the appropriate color flag, if it didn't exist, and added each message to the colour category. I did this by sorting my Inbox by flags and selected the first email and cursored down the list. Adding and removing flags to new messages now works correctly as well.


The aforementioned Smart Mailbox is now showing results.


Everything looks promising, but I will have to wait until Spotlight indexing completes to make a final check.

Oct 24, 2013 7:46 AM in response to jmfinn9

I have encountered this issue too. Deleting the Envelopes files worked at first, but then the problem came back. There seems to be a glitch with Gmail: At one point, my Unread smart folder showed one unread message, but my inbox was empty. However, when I checked my trash, there was an unread message in my Gmail account. My smart folder was set to ignore mail in the Sent and Trash folders, so it should not have been there. I clicked on the message, then deleted it, and the Unread folder showed no read mail.

Oct 24, 2013 8:06 AM in response to David Green4

David (and all others),


I did a bit more playing around and ran a script that seems to repair the index, to the effect that the offending "hidden e-mail" popped up once I ran it and did a mailbox sync. To wit:


- Close Mail.

- Open Terminal application (Applications/Utilities)

- Copy and paste this script:

sqlite3 ~/Library/Mail/V2/MailData/Envelope\ Index vacuum;


- It will take about ten seconds to complete, whereupon you will be brought back to the prompt.


- Close Terminal and re-start mail.

- I find it is helpful to also open the activity window in Mail to see what it's doing, since it may take a bit to churn everything.

- The Activity Window is invoked by going to the "Window" pull-down then select "Activity."


- At this point, I first went through all of my mailboxes and selected "Mark All as Read" from the settings, if it was not greyed out (I used the one on the sidebar at the bottom that looks a bit like a gear-wheel. It also has other options such as delete mailbox, if that helps describe it better).


- Once I used that option through every last mailbox, including offline boxes I use as repositories for mail rules, I ran a full mail Synch (Pull down menu "Mailbox/Synchronise All Accounts) and let it do its thing.


- After monitoring the Activity Window and seeing it was all done, I scrolled through my mailboxes and there was the naughty e-mail that had been hiding away. When I opened it, my Unread Smart Mailboxed cleared right up.


I hope that helps or works for you and others.

smart mailbox unread counts wrong

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.