I ran into the same problem, but managed to fix it. (We are indeed using mDaemon)
I'm not sure how I fixed it, but it seems that you must create a second mailbox in Mail for the account you are trying to access. I created a POP3 account when doing so. Not long afterward (and sometimes during - I have multiple accounts) the IMAP account started working, and I could delete the POP3 one.
Still, this bug is very annoying. Especially as Mail sits there for an hour just to set up the account.