Combines code for getting messages and threads.

Also changes table structure so that attachment is now has_attachment
for messages.