Fix UID-based logic since the former didn't work on all IMAP servers.
Some small whitespace fixes.