Fix Imap mock

see #265
Improve error handling

see #260