rebuildthreads: Load all messages to memory first

This seems to avoid an SQLite issue where we keep trying to
process and insert a message with a null Message ID.