I just made this mistake but have recovered from it after some trials and tribulations and thought I'd share the solution I found. I went to Time Machine and recovered yesterday's IMAP folder for the relevant account from:
Users/[your user]/Library/Mail/
Then I made a new Mailbox in mail...