Handle threads spanning multiple folders in generic actions

Summary:
This is a diff that fixes T501 and T549. It's only a proof of concept on the generic actions. Here's some of the changes:
- refactor the generic actions to remove `syncback_action`. The whole higher-order stuff was used only because we wanted to retry actions and it didn't mesh well with executing the same action on multiple folders. Also note that the code doesn't care about retrying things on IMAP failures because (in theory) the syncback service handles this for us.
- I made some cleanups to the syncback code and I bundled some fixes to the tests (sorry but this branch originally started as test fixes).

Test Plan: Ran the actions on a fastmail account.

Reviewers: kav-ya, emfree

Reviewed By: emfree

Projects: #sync-engine

Maniphest Tasks: T501

Differential Revision: https://review.inboxapp.com/D622
[tests/contacts/remote_sync] Mark the `test_auth_error_handling` test as xfail for now as it seems to consistently fail on my machine + CI.
Specify gevent.event import.

You can't do
```
import gevent
e = gevent.event.Event()
```
before monkeypatching, which mostly may affect tests.
setup: changed config file mode bits

Changed the configuration file mode bits from 600 to 644 for the
/etc/inboxapp/config.json and /etc/inboxapp/secrets.yml configuration
files to avoid issues when starting bin/inbox-start.
Merge pull request #96 from filipposironi/master

setup: changed config file mode bits
[build/setup.sh] Add libsodium setup to install flow.

Summary:
Workaround for the "error: sodium.h: No such file or directory" bug in
pynacl and/or cffi: https://github.com/pyca/pynacl/issues/79

Fixes https://github.com/inboxapp/inbox/issues/95

Test Plan: `vagrant up --provision` from scratch

Reviewers: charles

Reviewed By: charles

Subscribers: mg

Differential Revision: https://review.inboxapp.com/D635
Ensure we can log message decoding errors from non-ASCII folder names.

Test Plan: Regression test added.

Reviewers: kav-ya

Reviewed By: kav-ya

Differential Revision: https://review.inboxapp.com/D636
The one where we create a special case just for iCloud

Summary:
iCloud is pretty weird: sending an email from SMTP/IMAP doesn't save it under the "Sent". This patch introduces a special case for iCloud and a new action to save a message (`save_sent_message`).

I'd like to have your opinion on this, especially about the default vars I added to make things work.

Test Plan: Ran test_sending.py and checked that two files were created.

Reviewers: kav-ya, emfree

Reviewed By: emfree

Projects: #sync-engine

Maniphest Tasks: T478

Differential Revision: https://review.inboxapp.com/D631
Fix set_starred syncback actions.
[build/setup.sh] Fix install permissions when the host has umask 0077

Test Plan:
- Add "umask 0077" to my .bashrc
- vagrant destroy
- vagrant up --provision
- Check the permissions of
  /usr/local/lib/python2.7/dist-packages/pip-1.5.6.egg-info/entry_points.txt
  inside the VM.  It should be world-readable.

Reviewers: siro

Reviewed by: siro
Spawn a remote debugger in a separate greenlet

Summary: This code adds support for spawning a remote debugger if the DEBUG_CONSOLE_ON is specified. The debuggers listens on localhost on port $PID for telnet connections. It gives access to a simple REPL with the possibility of using the heapy heap profiler to inspect the heap.

Test Plan: Ran the code.

Reviewers: emfree, charles

Reviewed By: charles

Projects: #sync-engine

Differential Revision: https://review.inboxapp.com/D637
Add support for user-provided IMAP settings; refactor auth.

Summary:
This commit implements support for user-provided IMAP and SMTP settings, along
with related cleanup and refactoring in the auth code.

* Allow IMAP and SMTP endpoints for ImapAccounts to be overridden on a
  per-account basis.
* Define a "custom" provider for accounts with such overrides.
* Refactor auth modules to move functionality into AuthHandler classes.
* Refactor OAuth code, consolidating functionality split between the
  inbox.oauth and inbox.auth.oauth modules.
* Define interactive_auth() method on AuthHandler subclasses, to handle the
  flow of authing via bin/inbox-auth. Previously, this functionality was partly
  implemented in create_auth_account functions, and partly scattered.

Test Plan:
Add unit tests; add account with custom settings and ensure that
sync and sending works; run bin/inbox-auth for different account types.

Reviewers: charles

Reviewed By: charles

Differential Revision: https://review.inboxapp.com/D639
Fix typos in OAuth interactive auth.
Also fix create_account parameters in unit tests.
Add super simple search interface and indexing script to API.

Test Plan: None, for now.

Reviewers: kav-ya

Reviewed By: kav-ya

Differential Revision: https://review.inboxapp.com/D644
[SCHEMA] EAS Two-Device-Per-Account migrations.

Also,
Add BaseMailSyncMonitor._cleanup()
Move thread state fns out of BaseMailSyncMonitor.
Update bin/clear-db.

And,
Migration to fix EASUid cascade deletes.

Summary: Matching changes to D629.

Test Plan: None

Reviewers: emfree

Reviewed By: emfree

Differential Revision: https://review.inboxapp.com/D632
Fix post cherry-pick migration ordering.
Implement a "raw" message endpoint

Summary: This patch adds a new endpoint: "/messages/<id>/rfc2822" which returns the raw message.

Test Plan: Ran the code.

Reviewers: emfree

Reviewed By: emfree

Projects: #sync-engine

Differential Revision: https://review.inboxapp.com/D640
fix migration branch
Remove unused code.