Fix singlethread deadlock with IMAP synchronization

This request includes the fix posted for issue #22.