I continued to see this issue in Yosemite with a smart mailbox showing 2 unread messages even when no other mailbox showed unread items. The solution was embarassingly simple and obvious, hopefully helps others who are still seeing this:
1) Create new Smart Mailbox
- name "All Unread"
- match "All" conditions
- "Message is Unread" as only condition
- check boxes to include form Trash and Sent
2) Select all messages inside new "All Unread" mailbox
- Note: for me, all of these were marked as unread
3) Mark all selected messages as "Unread"
4) Mark all selected messages as "Read"
Doing this quickly and simply solved my problem. I didn't dig into it, but I assume the multiple databases tracking unread message counts got misaligned - this process brings them all into sync.
1. In Spotlight Search
2. Search "Spotlight"
3. open Spotlight System Preferences Menu
4. Privacy Tab
5. + Add Macintosh HD
6. - Remove Macintosh HD
8. just Wait till Flag Database is rebuilt
9. actually done
Flagged Mails in Smart Folders disappear for some time, rebuilding might take up to a few hours.
philipfifibachinger's suggestion is BY FAR the easiest way to fix the problem of flags not going away. I've had this problem several times now and have found that to be the easiest fix every time.
A couple notes about his post though:
1. Your spotlight system preferences may not appear in your spotlight search. If not, just click on the apple in the upper left corner of your screen, click system preferences, and click on spotlight.
2. Your computer might not be named Macintosh HD. In fact, most people have probably renamed it "John Doe's Macbook Air" or something like that. In any event, add that drive to the privacy list as explained by philip and then remove it a few seconds later.
3. It will take some time for the indexing to be done and for the flagged folders to rebuild. When you start a spotlight search, you'll see a status bar showing how long the indexing has left.
Using philipfifibachinger's Spotlight derived solution to rebuild didn't work for me unfortunately; I still had the Flagged unread count, despite having no messages showing in the Flagged folder. After some concern about deleting files from the system along the lines of William Kucharski's instructions given the various subsequent posts about machines left hanging, I decided to do a full back up and then try William's method.
It worked perfectly for me on Yosemite 10.10.1. Note for my Mail with c50k messages, the Flagged folder disappeared completely to start with, returning 5 or 10 minutes later. My heart sank, but as suggested the folder now actually contained the Flagged messages which I could then deal with. Many thanks William Kucharski.
From other posts I've surmised that Mail's indexing uses Spotlight. Bouncing Spotlight solve my problem of 3 mysterious unread messages indicated on the Unread smart mailbox. My problem popped up with a recent 10.10 update.
Go to root directory cd ./
Turn off Spotlight sudo mdutil -i off /
Turn on Spotlight sudo mdutil -i on /