Hi,
I was trying to set up an email account with Mail using my hostgator email account to use IMAP. I've just recently upgraded to Yosemite. Like the other poster above, "Use This Mailbox A..." worked for me, and I wanted to reiterate that here for future generations to unearth via google...
I have seen a TON of messageboard questions to this error... "An error occurred while moving messages to mailbox “(null)”." This happened for trash, junk, and draft saving of emails.
I could see the various folders underneath my mapped email account main folder, but they weren't showing up in my mail's groupings. Except, when they'd try, they'd show up with a big grey dot beside them an an arrow down.
So, I saw some help files on rebuilding my mailbox from here: Mailbox>Rebuild.
I tried that and it wouldn't work. But, then, I noticed this setting just above it... Mailbox>Use This Mailbox As...
That's the trick. Just pick your IMAP junk folder, and pick "junk". Pick your IMAP's deleted folder, and pick "trash".
Boom boom boom, and the error message disappears and everything is "live" on my IMAP account. 😀
Worked like a charm!
Jon