tidying ImapDb and making error handling more consistent.
Merged Crispin's changes.
AJAX login flow set up. Do a  to get the mustache dependency.