In my case, this was easily solved. Click on a folder or inbox that is missing mail. Then from the menu, Mailbox - Rebuild.
A worst case would be - assuming that you do have all the mail on your IMAP server - backup (or just move) the mailboxes on your Mac, and then delete and re-create the accounts. DON'T do this unless you're sure you made a copy OR that all your emails are on your IMAP server.