Rewrite imap string parsing.