Hi John, I had a similar problem with all my emails. I had lost all the sub-folders in 'on my Mac' and tried all the other solutions that had been offered - the subfolders is where I sort all my main - in short I was knackered and panicked. I then stumbled across a solution that worked for me. This has bought back all my accounts and all my subfolders.
1. I removed and reinstalled all my mail accounts which bough back all mail that is on the email system.
To reinstall all subfolders in Mail - on my mac:
1. I created a new Mailbox called 'Test' which showed under On my Mac.
2. I opened Finder and navigated to Library
3. Under Mail I found the folder in V2 or V3 which had the folder named 'Test' (mine was in V3)
4. I then copied one of my missing folders that I had found under Mailboxes in V3 into this same folder.
5. I then deleted all the files named - envelope which forced a rebuild of the entire mailbox and it worked.
6. Once I had proven it worked for one I repeated steps 4 & 5 with all the missing folders and my on-my-mac had rebuilt perfectly.
7. You don't have to do them one at a time but can do them all in one go.
I hope this helps either you or anyone else who had the same problem as I did.
Please note: I'm no expert so I cannot guarantee this is a 100% fault free solution - that said it is 24 hours now and everything appears fine.
Good luck all.