Improve database parallelization

Prior attempts to use multiple threads to access the SQLite database
failed due to locking reasons.  This re-attempt fixes this, alloc'ing
four threads per database and slightly changing the locking strategy
for read-write transactions.

Part of the prior issues may have been an attempt to use a connection
pool (this patch simply opens a new connection for each transaction,
which for our purposes seems fine).  The read-write strategy of
deferring locking until the write portion of the transaction was also
too optimistic, causing transactions to stall in the middle of their
operations.
Synchronize with Sent Mail immed. after sending one: Refs bug #714450

This doesn't completely solve bug #714450 but it does display a reply
or forwarded message more quickly in a conversation (rather than wait
for the Account object to signal that a Folder's contents has changed,
which is polled and may take minutes to notice).

This also slightly rearranges the priority order for background
synchronization, recognizing that some Folders (Drafts, Sent Mail) are
as active as All Mail but quicker to synchronize with (i.e. don't wait
for All Mail to complete synchronization before checking those).
Prevent AccountSynchronizer from deadlock

Occassionally the EmailPrefetcher would not signal its work was
completed, causing the AccountSynchronizer to deadlock (it waits
until the EmailPrefetcher completes before closing the Folder and
moving on to the next one).  The problem was due to the
EmailPrefetcher not clearing a timeout id, making other code think
other work was outstanding when it was in fact completed.
Improved Folder connection retry

Folder now checks the open_count (as well as other details) to
determine if it should retry a closed connection; this prevents
certain race conditions where the Folder will continue to be reopened
even though it was legitimately closed by the caller.
Reduce database pauses: Refs bug #725929

Although not completely solved, this reduces database pauses
(along with prior commit improving parallelization of database) by
how ImapDB.Folder accesses the database.  In particular, one code
path required an INNER JOIN that simply took too long (~8s) on large
databases, locking the entire db in the process.  Tests and hacking
showed that, annoyingly, manually performing the INNER JOIN by
intersecting the results of two SQL transactions was more efficient.

In addition, creating/merging emails into the database is done in
chunks with a small pause between each chunk to allow other tasks
the opportunity to get to the database.  Create/merge is one of the
most expensive operations on the database.