Return the same API representation for 'blocks' and 'parts'.

Summary:
Fixes issue #41. For files which have been uploaded but not actually attached
to a message, we simply set thee 'message' attribute to null.

Also remove some outdated code which defined a namespace property for Part
objects -- we now explicitly save the namespace_id in the Block parent class.

Test Plan: curl http://localhost:5555/n/<ns_id>/files

Reviewers: spang

Reviewed By: spang

Differential Revision: https://review.inboxapp.com/D234
Automatically start syncs for newly-registered accounts.

Summary:
In inbox/mailsync/service.py, poll for accounts that have been registered but
don't have syncs started, and start them.

Also remove support for the 'startall/stopall' functionality in bin/inbox-sync,
which is not that useful and adds unnecessary complexity to the normal
start/stop sync implementation.

Test Plan:
Auth a new account and check that the sync starts; run
`bin/inbox-sync start <email_address>` and `bin/inbox-sync stop <email_address>`.

Reviewers: kav-ya, spang

Reviewed By: kav-ya, spang

Subscribers: kav-ya

Differential Revision: https://review.inboxapp.com/D237
Set load_on_pending=True for namespace relationship of versioned objects.

This prevents errors when constructing the transaction log. Otherwise, if e.g.
a Block object was constructed with
block = Block(namespace_id=ns_id, ...)
then attempts to access block.namespace in the after_flush handler may
erroneously return None.
Set load_on_pending for Part.message.

Like commit 526f9620, fixes errors when constructing the transaction log.
Support read and update operations on user-created tags.

Summary:
Addresses issue #45. Deletes will take a little more care because we need to
ensure that the tag gets removed from all threads.

Test Plan: Unit tests added.

Reviewers: kav-ya

Reviewed By: kav-ya

Differential Revision: https://review.inboxapp.com/D240
Fix folder mapping KeyError when starting some IMAP syncs.

We were creating the {name: id} mapping for folders before we had
necessarily created folder objects for all folders belonging to an IMAP
account, which meant that sometimes we'd get a KeyError starting up the
sync because we couldn't find a Folder object for a given folder.
Remove old, deprecated search code.
Don't retry IMAP syncs on MailsyncError, ValueError, or AttributeError.

Summary:
These are always totally fatal errors that we throw manually, or
programming errors, so we shouldn't retry. Retrying just adds extra log spam.

Test Plan: ./runtests & manual verification by throwing errors under the retry

Reviewers: emfree

Reviewed By: emfree

Differential Revision: https://review.inboxapp.com/D244
Decrease default IMAP pool size from 8 to 6.

How low can we go?
Store Message objects even if DecodingError occurs.

Summary:
It turns out that we do want to keep around message metadata even if we
fail to parse the entire message, since e.g. we don't want to keep
trying to download the UID over and over again, which we *will*, since
we determine which UIDs to download by looking at which UIDs we have
locally. It would be messier to relax the imapuid.message_id constraint
than to just store Message rows for the failed messages too.

Plus, this way we get to take a look at any metadata that *did* parse
successfully, and have better ways to expose failed messages to
developers.

This also fixes a NoResultFound error which is triggered by the previous
DecodingError codepath, where we tried to create imapuid rows in Gmail
syncs without corresponding Message rows.

Fixes T122 and GH #31.

Test Plan: ./runtests, manually throw mime.DecodingError & verify behaviour

Reviewers: emfree

Reviewed By: emfree

Maniphest Tasks: T122

Differential Revision: https://review.inboxapp.com/D243
Better structlog logging in models/message.py.
Properly configure logging level.
Fix KeyError in Gmail mailsync's add_new_imapuids()

Messages can still move around while a given IMAP session is open, so
sometimes we'll start adding ImapUid entries but not get the flag info
while the message is still in the given folder. (For example, when a
message is archived in the middle of this operation.)

The right thing to do in this situation is to skip adding the ImapUid
entry; we'll catch the message later via the All Mail sync.
Fix call to update_imap_flags in order to properly set is_draft attribute.

Gmail uses a '\\Draft` *label*, not the '\\Draft' IMAP flag, so by omitting
that second parameter we weren't marking synced drafts as such.
Don't check is_latest attribute on drafts that aren't SpoolMessage instances.

Fixes T157.
Remove bad assertion and skip missing UIDs instead.

Similar to the KeyError issue, if UIDs disappear in the middle of a flag
update operation, we just shouldn't update them.

Fixes T153.
Set loglevel for logging fixture.
Fix type error when syncing back an unarchive action.

We were passing a Folder object to remote_move(), but that function expects a
folder name. Fix this, and rename the parameters to be more explicit.
[SCHEMA] Store client_id and client_secret on GmailAccount objects.

This is an interim change to allow account syncs to run using a developer's
client ID and client secret, as opposed to the ones specified in the sync
engine config. If these parameters aren't stored, we still use the configured
ones, so that auth and sync in the dev VM work as before.
Remove unused imports in mailsync/backends/base.py.