[SCHEMA] Properly cascade folder deletions to imap bookkeeping.

Summary:
If we sync a folder deletion from the remote, we have to cascade it to
ImapFolderInfo and ImapFolderSyncStatus rows, or we get
```
IntegrityError: (IntegrityError) (1048, u"Column 'folder_id' cannot be null")
'UPDATE imapfoldersyncstatus SET updated_at=%s, folder_id=%s WHERE
imapfoldersyncstatus.id = %s' (datetime.datetime(2014, 10, 20, 19, 22, 47,
851225), None, 1524)
```

Note that we already do precisely this cascade for ImapUids.

Test Plan: Regression test added.

Reviewers: kav-ya

Reviewed By: kav-ya

Differential Revision: https://review.inboxapp.com/D633
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.
[SCHEMA] EAS Two-Device-Per-Account migrations.

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

Summary: Matching changes to D629.

Test Plan: None

Reviewers: emfree

Reviewed By: emfree

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