Potentially fix T197, T194.

Summary:
T197 was due to yesterday's "fix" to T194.
Therefore revert it (i.e. remove the db_session.add(folder) in create_db_objects();
if no new_uids were added, there is no db_commit() before the save_folder_names() which
will try to create the same folder raising the error in T197).

This didn't really fix T194 anyway so it's not a huge loss.

So, take two at fixing T194:
Folder.create() adds the created Folder to the session;
there is some weirdness about association proxy + backref
(See: https://groups.google.com/forum/#!topic/sqlalchemy/6RV6ay3rwIs).
In particular, I'm not sure how autoflush behaves in this case when
the folder the FolderItem is instantiated with may not have been
explicitly added to the session.

As before, not certain this is a guaranteed fix but:
1. I'd like to test it against mg's failing accounts on Gunks.
2. I won't mark anything as resolved till we see it is.
3. It may work.

Test Plan: Sync on inboxapptest runs.

Reviewers: emfree

Reviewed By: emfree

Maniphest Tasks: T194

Differential Revision: https://review.inboxapp.com/D264
Add support for yahoo syncback actions

Summary:
Implemented all actions - needs review.

Christine, could you take a quick look at the code and tell me if it's okay?
I'd like to have your opinion on this specific things:

1. I'm not sure I'm doing the ORM requests the right way. There's probably something
   more efficient than loading all the fields from the db.

2. I'm a bit wary about the race condition we get when deleting a draft which is not yet
   reconciled. I'm open to suggestions about how to handle this.

fixed rebase bug

code for review

rebased latests changes + fixed rebasing bugs

ignore soft deletes - fixes draft deletion bug

draft deletion and reconciliation

refactor - moved draft deletion code from YahooCrispinClient to CrispinClient - ... we won't need it for yahoo because their servers don't support querying a specific header

Test Plan: manual testing, interacting with the REST API using curl.

Reviewers: spang

Reviewed By: spang

Subscribers: kav-ya

Differential Revision: https://review.inboxapp.com/D257
[outlook] Initial outlook support.

Summary: Support hotmail/outlook by mimicking yahoo's generic imap support

Test Plan: auth/sync a hotmail account

Reviewers: khamidou, spang

Reviewed By: spang

Subscribers: khamidou, emfree

Differential Revision: https://review.inboxapp.com/D260
[merge] Fix alembic history / diversion.
[Monocle]
Fully reset sync status on restarting foldersyncs.
Sync type (new/resumed) on account, rather than folder.
Fixes T191: Flanker DecodeError in EAS
[config] Add the default values back in for the client id / client secret for google and ms live.
Fixes  T201: Drafts API should support ?thread=filter.

Summary:
get_drafts() method added to inbox/api/filtering.Filter
draft_query_api() added to inbox/api/ns_api.py

Test Plan: Added test in tests/api/test_drafts.py

Reviewers: emfree

Differential Revision: https://review.inboxapp.com/D266
Revert "Fixes  T201: Drafts API should support ?thread=filter."
This reverts commit cfa8cb8935544229c9f923ecece8b95b0f145731.
Post-review push for 'Fixes T201: Drafts API should support ?thread=filter.'
Also, tests/general/test_mutable_json_type passes again.
Propogate sync_state='killed' to account sync if all its folder syncs have been killed.
[docs] fix missing comma.
Reduce writable IMAP connection pool size.

We don't really need 4 simultaneous writable connections. Maybe we don't even
need 2. This reduces the likelihood that we hit the simultaneous-connection
limit.
[oulook_domains] oops missing comma.
Prevent concurrent creation of duplicate connection pools.

Did you think that because a gevented process is basically still
single-threaded, it's free of your normal concurrency woes? Well, not so much.
Consider the following test case:

---
import random
from gevent import monkey; monkey.patch_all()
import gevent

def maybe_update_shared_dict(k, v, d={}, final=False):
    if d.get(k) is None:
        gevent.sleep()
        d[k] = v
    return d.get(k)

def test():
    print maybe_update_shared_dict('a', random.randint(0, 22))

threads = [gevent.spawn(test) for _ in range(10)]
gevent.joinall(threads)
---

Only the first call to maybe_update_shared_dict should store a value in the
dictionary d, and all the other greenlets should read it. But that's not
actually what happens, because concurrency.

This is basically what we were doing when creating IMAP connection pools. This
is an issue if you start the syncback service and it tries to execute a bunch
of actions for the same account at once -- you end up creating a bunch of
connection pools. Add per-account locks to prevent this.
Reduce writable connection pool size to 1 for now.

We were still getting 'too many simultaneous connection' errors...

Also add a bit of logging.
Support 'filename' and 'message' parameters on /files queries.

This is a preliminary commit, which doesn't properly return files that are
Blocks but not Parts. Could also use some unit tests.
Return more attachment information in API message representation.

Test Plan: curl http://localhost/n/<ns_id>/messages/<id of message with attachment>

Reviewers: charles

Subscribers: mg, bengotow

Differential Revision: https://review.inboxapp.com/D268
Schedule draft-deletion-syncback as a separate action from sending.

This prevents us from potentially re-sending a message if the drafts-syncback
call fails for some separate reason.
Catch UnicodeDecodeErrors in slow query logging.

Just an interim fix to keep this from breaking stuff while we investigate the
underlying issue.