Improved handling of non-ideal messages, handle message header encoding

Here is more work I've added.  The older commits are mainly about managing degenerate cases and gracefully handling semi-invalid data.

The latest commit is to deal with a change in the GMail IMAP interface, where many GMail-added message headers are now put in UTF-8 encoding (e.g. "=?utf-8?q?blahblahblah?=") even if their values are entirely ASCII.  This was breaking some of the message indexing.