Install inbox under 'inbox-sync' egg to avoid namespace collision.

The Python SDK is now 'inbox', so call this 'inbox-sync' instead.
Remove deprecated "message_id" field from Block representation.

Also update docs.
Strip all stack locals from Sentry exception messages.

Summary:
Having them is nice for debugging, but per discussion with @dlitz there's just
too much potential to leak information.

Test Plan: Unit test added.

Reviewers: dlitz

Reviewed By: dlitz

Subscribers: dlitz

Differential Revision: https://review.inboxapp.com/D487
startup: Remove clean_pyc; log a warning if ./src/ is detected.

Summary:
This caused a race condition that would break startup when multiple
parallel sync engines were started at the same time.

clean_pyc() should be a no-op now anyway, since our requirements.txt no
longer has any `-e git+https://` lines in it.

Also:
- Removed `sys.dont_write_bytecode = True`.  It doesn't really make
  sense to do it here, since we've already started importing things and
  writing .pyc files at this point.  If we actually want to avoid
  writing .pyc files at all (which I doubt), we should set
  PYTHONDONTWRITEBYTECODE=1 in the environment before starting Python.

- Moved `find . -name \*.pyc -delete` to earlier in the setup process
  so that old pyc files are removed before we start installing Python
  stuff, rather than afterwards.

Test Plan:
Run bin/inbox-start once under Vagrant to make sure it
doesn't crash.

Reviewers: charles

Reviewed By: charles

Maniphest Tasks: T463

Differential Revision: https://review.inboxapp.com/D479
Remove provider prefixes from tags; add 'readonly' attribute.

Summary:
Instead of mangling label names like 'jobs' to tag names like
'gmail-jobs', keep the original name. Instead add a 'readonly' attribute to the
tag representation.

Test Plan:
Run data migration script; sync a new account; check that tag names
look good for both.

Reviewers: khamidou, bengotow

Reviewed By: khamidou, bengotow

Subscribers: bengotow

Differential Revision: https://review.inboxapp.com/D497
[DEPENDENCIES] Bump dnspython version.

In order to get the fix for https://github.com/rthalley/dnspython/issues/31,
which we were encountering in the wild.
Properly limit query for existing calendar object by account.
[sendmail/client] Better error handling / logging when errors occur while trying to send mail.~

Summary:
OAuthError bubbles up to top if we can't login to the account during
sendmail. Instead, catch that exception and turn it into a generic sendmail
exception with proper logging. Note: exception still bubbles up to top, need
more generic way of handling these issues (i.e. keep retrying and/or eventually
fail), however that needs to be done across all actions.

Fixes T479

Test Plan: review code / regression

Reviewers: emfree

Reviewed By: emfree

Maniphest Tasks: T479

Differential Revision: https://review.inboxapp.com/D501
[actions] Filter actions to limit them the sync-host that the account is syncing on.

Summary:
Forces the syncback service to only perform actions for which the account is associated with the same machine.

There are a few other changes that need to be made before we can have
multi-machine mailsync (none of which seem to be very significant), however
this one at the least is straightforward.

Test Plan: regression + system tests

Reviewers: emfree

Reviewed By: emfree

Differential Revision: https://review.inboxapp.com/D503
[syncback] Fix tests to work with sync_host filtering in syncback_service (?).
[SCHEMA] Optionally throttle IMAP initial sync for certain accounts.

Summary:
Needs some more testing, but here is the basic gist of it for IMAP. We only
sleep after downloading a message from the initial sync backlog, not after
downloading a message more recent than the sync start. This means that there
may still be up to a minute's latency, but at least you will still get your
new mail if you're getting more than one new message a minute. (It may be
possible to get cleverer.)

Note that we also do one thread per minute rather than one message per minute
on Gmail inbox folders, for simplicity.

Test Plan:
Run syncs for accounts with the 'throttled' flag set to both True
and False. Check that we sleep and output the according debug logging only in
the latter case.

Reviewers: spang

Reviewed By: spang

Differential Revision: https://review.inboxapp.com/D505
[SCHEMA] Add Message.namespace_id column, part 1.

Summary:
This is important both for performance and for assurance of namespace
isolation. In this commit, we merely add the column without requiring that it
be non-null. This is so that we can run the (time-consuming) migration online,
and then alter the column to be non-nullable in a subsequent (faster)
migration.

Associated cleanups:
* Move the contents of Message.__init__, which previously was responsible
  for constructing a Message instance from synced data, to a
  Message.create_from_synced method for greater clarity. Remove unused flags
  argument.
* Remove Message.create_draft_message, which wasn't really doing much.

Test Plan: Run syncs, unit tests.

Reviewers: charles

Reviewed By: charles

Subscribers: spang, mg

Differential Revision: https://review.inboxapp.com/D496
[SCHEMA] Add Message.namespace_id column, part 2.

Summary:
This is just the followup schema change, in which we set
Message.namespace_id to be non-nullable once we've populated it for all rows.

Test Plan: Run migration.

Reviewers: charles

Reviewed By: charles

Differential Revision: https://review.inboxapp.com/D498
[SCHEMA] s/account_id/namespace_id/ for contacts,events,calendars.

Summary:
This makes contacts and events consistent with the rest of our objects, wihich
we partition by namespace rather than account.

Test Plan: Unit tests.

Reviewers: charles

Reviewed By: charles

Differential Revision: https://review.inboxapp.com/D502
Fix argument ordering in mime parsing.
Fix missing argument in BaseSync provider specialization.
Update GMessage namedtuple construction in Gmail sync.

Need to pass a value for 'throttled' now.
Condense successive alter tables in migrations.
Defer initialization of Crispin connection pool so that it can be retried.

CrispinConnectionPool.__init__ calls CrispinConnectionPool._set_account_info(),
which does auth and related stuff. We were calling this in the FolderSyncEngine
constructor, which meant that the folder sync would just silently die if some
sort of error occurred. Not good.

In general we really shouldn't be doing this sort of work in any class
constructors at all.
[sync/missing folders] Create folders on the backend when not present. Required for hovermail.

Summary:
Providers don't always provide all of the folders that we are
expecting. One such provider is hovermail. In order to support such providers,
we need to create these folders on-demand. This may not be the best place to do
so, however I couldn't think of a better place (perhaps initial sync?).

Fixes T446

Test Plan: sync hovermail account, perform self-send test.

Reviewers: emfree

Reviewed By: emfree

Maniphest Tasks: T446

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