Apply stopgap fix for message API slowness.

Basically the way we have to join messages to threads to filter by mailboxes is
crushingly slow on large mailboxes. This commit at least remedies the worst of
it by first loading only message ids, then loading the actual messages in a
second pass.