Add clarifying comment.
Fix reconcile_messages() regression to only reconcile with local Inbox-created messages.

Summary:
Filtering by the inbox-uid header alone is not sufficient; more than one
message on the remote backend may have the same inbox-uid header.
Reconciliation should only occur with messages created locally, not messages synced;
that is incorrect and also causes issues like T550.

Test Plan: Regression test in inbox-eas.

Reviewers: emfree

Reviewed By: emfree

Differential Revision: https://review.inboxapp.com/D596
Use a more performant IMAP command for CONDSTORE queries.

Summary:
Doing a search by MODSEQ is deadly slow on Gmail, but doing
FETCH 1:* (...) (CHANGEDSINCE <modseq>) is pretty fast, particularly for modseq
values close to the highest modseq.

Note that this commit changes the semantics of
CrispinClient.new_and_updated_uids(modseq): previously, this would return UIDs
with MODSEQ >= modseq. Now it returns UIDs with MODSEQ > modseq. But this is
also what we actually want whenever we call it.

Test Plan:
Run both the old and new IMAP commands for a bunch of
randomly-chosen modseq values, and check that they return consistent results.

Reviewers: spang

Reviewed By: spang

Differential Revision: https://review.inboxapp.com/D625
[imap] Update logging to look like other logs.
Fix args in save_draft().
[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.
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.
[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
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
[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
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.
Store labels in ImapUid

Summary:
This is a minimal patch to store label information per-folder. Note that this is only about storing data, not updating thread info using it.

I'd like you to take a look at the MutableList class I've added -- this SQLAlchemy thing is black magic.

There's one big question though: how do we update this info in prod? I was thinking we could have a one-off program that would go through every message of every account and query label information but this sounds super complicated to get right.

Test Plan: Ran a sync.

Reviewers: kav-ya, emfree

Reviewed By: emfree

Projects: #sync-engine

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

Conflicts:
	tests/data/base_dump.sql
Create canonical tag objects at Namespace creation time.

Summary:
We assume that tags like 'sent' and 'drafts'are always available, for example
in the drafts/sending API functionality, but we previously only ensured
that they existed when we started a sync. This only caused problems.

Instead, just create the tag objects when a new Namespace is initialized.

Test Plan: Run unit tests; auth and sync an account.

Reviewers: kav-ya

Reviewed By: kav-ya

Differential Revision: https://review.inboxapp.com/D659
Switch to mainline flanker

Summary:
Our fork for flanker is out of date and my previous bugs have been fixed by them in other commits. Our fork only had 3 changes.

This issue is closed and I validated the fix: https://github.com/mailgun/flanker/pull/36#issuecomment-50381678

Do we still need this? Can we configure our VM to use the proper DNS server elsewhere? https://github.com/inboxapp/flanker/commit/ecbb70a133324fb5e6ff06b9546456905c7537aa

And I believe this was fixed in some other flanker commit: https://github.com/inboxapp/flanker/commit/32524df59b2ff27fd3236073210bde750ae4b24b

At least one user has also complained about decoding errors that are probably likely to our fork being left behind. I couldn't replicate the error with the latest version on PyPI.

I'm not sure the best way to get this deployed since our `pip install` has been cloing our fork locally. Running setup.sh worked in my VM to overwrite our fork with the new version, but this might need some TLC during production rollout.

Test Plan: All tests should still pass.

Reviewers: spang, emfree

Reviewed By: emfree

Differential Revision: https://review.inboxapp.com/D661
Apply gevent monkey-patching before running tests.

Fixes test failure.