This is extremely trivial, but maybe it's a useful pointer regardless ... it has always annoyed me that junk mail, even when recognized as such, still contributes towards Mail.app's email count as displayed in the application's Dock icon. I should add that my junk filter is in perpetual training, as I still get false positives every now and then. The solution is simple:
- Go to Mail: Preferences: Junk Mail: Advanced.
- Under "Perform the following actions", click the plus button (+).
- Select "Mark as read".
That's it. No more eager interrupting what you're doing just to find that another piece of spam has arrived.
[
robg adds: I believe this issue is self-correcting once you tell Mail to exit training mode; my default rule, which I'm reasonably certain I never edited, contains the 'mark as read' option.]