Mail shows stale inbox count

I've had some odd behavior on my OS X mail client. Heres' my inbox:

enter image description here

Yet here is how many unread messages I have:

enter image description here

These values used to be synchronized. Note that the first value will not change even if I mark all other messages as read (subfolders included).

OS X 10.7.4
Mail = Version 5.2 (1278)


Try these two solutions:

  1. From the Finder, ⌥-click the Go menu and select Library whilst still holding ⌥.
  2. Move the folder ~/Library/Mail/ to the desktop or another convenient location.
  3. Launch Mail.app.
  4. From the File Menu choose Import Mailboxes…
  5. Choose Import Data from Apple Mail.
  6. Navigate to ~/Desktop or wherever you moved ~/Library/Mail/ to.
  7. Click on Choose.
  8. Wait until it imports.

or

  1. In a Finder window, navigate to ~/Library/Mail/V2/MailData, and delete any file that begins with Envelope Index, such as "Envelope Index" or "Envelope Index-shm" or "Envelope Index – awl". In my case, I had all 3 of these Envelope indexes, and moved them to the trash.

    Note: When accessing Library, keep in mind that your home Library is hidden in Lion. To access it, from the Finder, ⌥-click the Go menu and select Library whilst still holding ⌥.

  2. Restart Mail. It will then rebuild a new list of messages, which can take some time, so be patient.

    Another note for Exchange users: After removing the Envelope Indexes, my Exchange account email content was blank. To revive it, I had to delete my Exchange email account and add it again fresh. After adding it from scratch (and the download took a while since I have about 12K messages), the mystery Unread Message notifications were gone.