Don't hold database sessions open for long periods during mailsync.

Summary:
This was causing us to create a ridiculous number of database
connections which sat around idle most of the time because the mailsync
code was waiting on network I/O (or simply sleeping).

The codebase still needs further audit, but this improves the situation a lot.

Test Plan: Deploy to Gunks.

Reviewers: kav-ya

Differential Revision: https://review.inboxapp.com/D284