I ran into a similar situation, and I believe this is caused by an IMAP server not following the IMAP spec properly, at least according to this article by Oracle.
I've implemented the suggested changes in this article - here is a Gist with the code. Please give it a shot by replacing your EmailHandler.java file with this and let me know if you have any luck.
By the way, who is your email provider? I had trouble with GoDaddy.