Commit graph

926 commits

Author SHA1 Message Date
Evan Morikawa e197de86e0 [local-sync] fix attribute scanning in sync worker
Summary:
Fixes https://phab.nylas.com/T7435

The old deepScan (now `scanForAttributeChanges`) and shallowScan (now
`fetchLatestAttributeChanges`) had some fatal flaws.

If you deep scanned it would attempt to load the message attributes of all
messages ever and cause very bad memory leaks.

Also, if you left a mailbox running for a long time, there was a query
that would eventually run `Message.findAll` and, even though it was just
returning the headers, would still run insanely expensive operations

This fixes (and renames) these issues.

Test Plan: manual

Reviewers: spang, halla, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3657
2017-01-13 12:00:45 -08:00
Christine Spang 7c8146f81b [local-sync] Fix parsing of existing messages derp 2017-01-13 11:15:24 -08:00
Christine Spang a23813a11c [local-sync] For generic IMAP, Thread based on Message-Id, In-Reply-To & References
Summary:
This swaps out our generic IMAP threading mechanism to use the threading
headers on the message instead of the prior way of grouping by subject
and then differentiating based on participants, as that design was
somewhat driven by what we could accomplish easily given legacy data
schema decisions and has serious caveats, such as different threads between
the same people with the same subject being misthreaded together. With K2, we
have free reign to change the data format, so we can do it right.

The algorithm is super simple:
- Define "references" as the union of the Message-Id, In-Reply-To, and
References headers on a message, filtered for valid RFC2822 Message-IDs
- On message sync, if any element of the new message's references
matches any element of an existing message's references, thread them
together

In order to accomplish this, we need to store References in a way that
allows each element to be indexed for fast lookup. That meant either
using the sqlite JSON1 extension + expression-based indices, or creating
a new table. I chose the latter as a time-tested and simple solution,
since we don't need the flexibility of JSON here.

Test Plan: manual - unit tests coming

Reviewers: khamidou, evan, juan

Reviewed By: evan, juan

Differential Revision: https://phab.nylas.com/D3651
2017-01-13 10:39:54 -08:00
Christine Spang 0dcbcee06c [local-sync] Messages generated for send should not be unread 2017-01-13 07:46:18 -08:00
Christine Spang 99309f9c69 [isomorphic-core] Disable nodemailer's automatic X-Mailer header
Examined the headers on a message we sent and found this:
> X-Mailer: nodemailer (2.5.0; +http://nodemailer.com/; SMTP/2.6.0[client:2.8.0])

No need to plaster which sendmail library we're using all over every
email our users send. Turn it off!
2017-01-12 14:16:47 -08:00
Juan Tejada 238b79d06c [local-sync] Don't sync spam until everything else is synced
Summary: Addresses T7426

Test Plan: manual

Reviewers: evan, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D3655
2017-01-12 13:53:17 -08:00
Mark Hahnenberg 59b5961a6c [syncback] Reuse currently open box if possible
Summary:
Previously we would unconditionally issue a SELECT when openBox was
called. Now we check if the currently open box is the one we want first and
return immediately if it is, avoiding the unnecessary SELECT (which can be
quite expensive on large folders like INBOX). We were also calling closeBox
after iterating all the messages in a thread to mark them as read/unread.
This was unnecessary and was causing extra SELECTs to be issued. Now we don't!
This diff is a 5x speedup over the old behavior when marking lots of
threads in the same folder as read all at once.

Test Plan: Run locally, measure perf with log statements

Reviewers: evan, juan

Reviewed By: evan, juan

Differential Revision: https://phab.nylas.com/D3654
2017-01-12 13:16:07 -08:00
Mark Hahnenberg 6a03bbe73f [local-sync] Fix error thrown when Gmail returns no search results
Summary:
We were returning the wrong type in the case that we got no messages
back from the Gmail search API.

Test Plan: Run locally

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3646
2017-01-12 11:57:07 -08:00
Jackie Luo 21049b2a1f Update Nylas N1 to Nylas Mail
Test Plan: Tested locally.

Reviewers: juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D3644
2017-01-12 11:25:39 -08:00
Juan Tejada ab7f994fef [local-sync] Ensure we get new mail ASAP via dedicated imap conn
Summary:
Add a new dedicated imap connection to listen for any updates or new mail on the inbox.
Previously, we wouldn't be able to receive new mail events on the inbox during the sync loop
because other mailboxes would be open while we sync them. This would cause big
delays in receiving new mail, especially if you have a lot of folders

Test Plan: manual

Reviewers: spang, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3650
2017-01-12 11:16:53 -08:00
Halla Moore 914d69557d [iso-core]: Make sure deltaStreamBuilder passes along delete deltas
Summary:
We don't want to inflate delete Transactions, but we do still want
to pass the delta itself along.

Test Plan: tested locally

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3647
2017-01-12 10:21:45 -08:00
Christine Spang ed57422412 [local-sync] Enable toggling ENABLE_SEQUELIZE_DEBUG_LOGGING on launch via an env var
It's much more convenient to be able to turn this on/off without
editing the code.
2017-01-12 07:43:34 -08:00
Christine Spang d36ae8db3c [local-sync] Still download messages when they have no body
There are plenty of valid use cases for sending subject-only emails,
and we also want to still download the headers and create message
objects if e.g. the email consists of only an event invitation or
an attachment.
2017-01-11 18:08:20 -08:00
Juan Tejada 3eb450e22c [local-sync] Make sure IMAPConnection times out correctly
Summary:
This commit passes down the `socketTimeout` option to node-imap. However, just
passing this option doesn't seem to work reliably, so this commit manually implements
the socketTimeout option for our IMAPConnection.

How it works is that basically every operation is wrapped with a timeout by
augmenting  the `createConnectionPromise` construct that already existed.

Test Plan:
Locally, tested by sleeping computer and turning off wifi. The
connection will successfully error and be restarted. It will reconnect when the
network is available again

Reviewers: khamidou, halla, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3642
2017-01-11 16:48:10 -08:00
Christine Spang e1271cf25c [local-sync] Give Nylas Mail messages a different Message-ID from API messages
Summary:
We may find it useful at some point to be able to tell which messages in
a user's mailbox were sent using N1/the REST API vs Nylas Mail.

Test Plan: manual

Reviewers: evan, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3631
2017-01-11 15:51:12 -08:00
Karim Hamidou 9136b0592b [fix] Add a poor man's two-phase commit algorithm for syncback tasks.
Summary:
Sometimes things go very wrong when trying to syncback an action. For example, the worker window could crash, preventing us from marking the current task as failed. What's worse, another sync iteration could try to run the task which crashed, thinking it a new one. To prevent this, this diff adds a fourth syncback task state, `INPROGRESS`.

New syncback tasks are marked as `INPROGRESS` before being executed. When they complete we mark them as `SUCCEEDED/FAILED`. Stray `INPROGRESS` tasks are automatically marked as `FAILED` at the beginning of every sync iteration, to make sure we don't retry them again.

Test Plan: Tested manually.

Reviewers: evan, juan

Reviewed By: evan, juan

Differential Revision: https://phab.nylas.com/D3635
2017-01-11 12:04:58 -08:00
Evan Morikawa 47f5880d18 [local-sync] fix multiple sync loops starting
A bug allowed multiple sync loop processes to start. This could lead to
double sending and the sync loop appearing as thouogh it couldn't be
interrupted
2017-01-10 18:24:38 -08:00
Juan Tejada 202d56d3f2 Fix error reporter causing crash due to infinite recursion 2017-01-10 15:30:30 -08:00
Christine Spang 9eb1aef139 [local-sync] Properly handle multiple occurrences of From/To/Cc/Bcc headers
Summary:
Well-behaved MUAs don't do this, but it is totally legal and we should
handle it.

The Python sync engine handles this properly also:
7db949fec9/sync-engine/inbox/util/addr.py (L26-L47)

(Found this out while scratching my head over the output format of
mimelib.parseHeaders---turns out it's an array for a reason:

> let to = mimelib.parseHeaders(`To: Christine Spang <spang@nylas.com>
... To: Foo Bar <foo@example.com>`);
undefined
> to
{ to:
   [ 'Christine Spang <spang@nylas.com>',
     'Foo Bar <foo@example.com>' ] }

)

Test Plan: unit test included

Reviewers: halla, jackie, mark

Reviewed By: mark

Differential Revision: https://phab.nylas.com/D3625
2017-01-10 15:07:36 -08:00
Christine Spang 15ac9f795b [local-sync] Remove deprecated comment
With the latest update to N1's CSS, this is no longer true---though a theme
can easily override the font to monospace if so desired.
2017-01-10 13:39:54 -08:00
Juan Tejada 79006f692d [local-sync] Fix check for new mail updates on inbox folder 2017-01-10 12:19:15 -08:00
Juan Tejada b74aad7314 [local-sync] Run send tasks before other syncback tasks
Summary: Update `_getNewSyncbackTasks` to return any send tasks first, and then others

Test Plan: locally

Reviewers: halla, evan

Reviewed By: halla, evan

Differential Revision: https://phab.nylas.com/D3627
2017-01-10 12:11:34 -08:00
Christine Spang 27b2c41fcc [local-sync] Make comment about Date/INTERNALDATE & message hashes better 2017-01-10 12:05:14 -08:00
Juan Tejada 80708dacbc [local-sync] Make syncback task execution interruptible
Summary:
See title. Got rid of that syncback-worker class which was kind of useless and
made things harder. My b.

Test Plan: locally

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3624
2017-01-10 10:45:53 -08:00
Christine Spang a234570118 [local-sync] Rename extract{Snippet,Contacts} in message-factory
Summary:
We have another function called extractContacts, in its own file,
extract-contacts.js, which is used to create Contact objects. This has
confused me a number of times and also leads to grep collisions.

This patch also makes the snippet unit tests pass again after a recent
API change.

Test Plan: included unit tests, manual

Reviewers: halla, evan, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3623
2017-01-10 10:41:35 -08:00
Christine Spang fb705fc5dd [local-sync] Remove unused message update hook
Summary:
Message bodies, drafts aside, are immutable, and we set the snippet on
new messages manually in parseFromImap()---meaning this hook, if
invoked, is likely to replace the snippet with a broken version computed
with this old implementation. If we need a hook in the future (e.g. for
updating drafts), it should use the snippet function from
message-factory.

Test Plan: n/a

Reviewers: juan, halla

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3622
2017-01-10 10:39:43 -08:00
Halla Moore 1e6f7a6e6f [local-sync] Don't delete messages via cascade when a folder is deleted
1. It could be expensive to delete many messages at the exact moment
   when the folder is deleted
2. The folder delete could actually just be a rename, and if we
   deleted all the messages, we would have to re-process them all
3. We already do a clean-up check for orphaned messages at the end
   of the sync loop, where we already know if the folder was
   actually deleted or just renamed
2017-01-10 10:37:08 -08:00
Evan Morikawa b03c0c9bc2 [isomorphic-core] don't try and inflate delete deltas
Summary:
If we inflate delete deltas, the object we're trying to find won't exist
anymore (we just deleted it!). This is likely causing the `While inflating
${sourceName} transactions, we couldn't find models for some ${modelName}
IDs` error.

Fixes T7436

Test Plan: manual

Reviewers: spang, juan, halla

Reviewed By: halla

Maniphest Tasks: T7436

Differential Revision: https://phab.nylas.com/D3621
2017-01-10 10:21:14 -08:00
Christine Spang ac08163c51 [local-sync] s/queryes/queries/ 2017-01-10 08:26:44 -08:00
Christine Spang b618c4ef28 [local-sync] Fix typo in ENABLE_SEQUELIZE_DEBUG_LOGGING 2017-01-10 08:16:16 -08:00
Halla Moore 2ed1a03d34 [local-sync, iso-core]: Cascade deletes on hasMany associations
Summary:
Delete associated children when a parent is deleted to prevent foreign
key constraint errors. Also make sure any child hooks are run.

Test Plan: tested locally

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3620
2017-01-09 18:13:09 -08:00
Halla Moore aaf0b04ae3 [local-sync] Add a hasAttachment attribute to threads
Summary: N1 uses this to show the little attachment icon in the thread list.

Test Plan: tested locally

Reviewers: evan, juan, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D3617
2017-01-09 17:20:55 -08:00
Christine Spang a959d546d6 [local-sync] Update comment 2017-01-09 15:24:55 -08:00
Juan Tejada 82dbc222b5 [local-sync] Fix send, correctly check for presence of headers 2017-01-09 15:17:19 -08:00
Juan Tejada d48ed92d66 [local-sync] Make the sync loop interruptible
Summary:
This commit introduces interruptible sync operations. Now, the `SyncWorker`, `FetchFolderList` operation and `FetchMessagesInFolder` operation can be interrupted at several points during their execution. This improves the performance of SyncbackTasks, which now run almost immediately.

To achieve this, this commit adds an Interruptible abstraction, which is an object that can run functions and interrupt them at points marked by the function. For more info on how this works, see the docs on the Interruptible class.

This commit also splits up the SyncWorker a little bit to make it smaller, byadding a SyncbackTaskWorker.

Depends on D3613

Test Plan: Manual

Reviewers: spang, mark, jackie, khamidou, evan, halla

Reviewed By: evan, halla

Differential Revision: https://phab.nylas.com/D3612
2017-01-09 14:43:15 -08:00
Evan Morikawa 73db7a4e46 [local-sync] fix changedsince highestmodseq causing N1 crash
Since we weren't giving Node IMAP the proper format for the changedsince
flag, and since node IMAP never warned of improper schemas, we weren't
properly requesting the correct range. This would cause us to request the
metadata attributes of EVERY message in the mailbox and attempt to store
them in a hash. This would eventually lead to a memory leak and take down
the worker window, which caused other subtle issues like sends failing
when the worker window dropped task half way through their perform remotes
and never re-sent the deltas notifying of their success or failure.

This was only triggered when new highestmodseq numbers fired on the remote
server, which would be triggered by the underlying mailbox getting folders
or labels changed on messages
2017-01-09 14:07:31 -08:00
Christine Spang 7073e19fe7 [local-sync] Don't filter contacts w/out emails out of To/From/Cc/Bcc fields
We separately filter out contacts without email addresses before
committing to the contacts table in the database for autocomplete (in
isContactMeaningful()), and if we filter out these already we can end up
excluding legitimate elements of the headers. For example, the Clutter
feature of Office 365 sends emails with a From: header like this:

From: Microsoft Outlook

Fixes: T7413
2017-01-09 13:45:18 -08:00
Halla Moore 1ba4a6eaf2 [local-sync] Add support for inline-images
Summary:
Extract files for inline attachments and store their content id

Fixes T7414

Test Plan: tested locally

Reviewers: evan, spang

Reviewed By: spang

Maniphest Tasks: T7414

Differential Revision: https://phab.nylas.com/D3609
2017-01-09 10:44:42 -08:00
Tomasz Finc 2c0fd79707 Fixing most lint errors in error-logger
Summary: Cleaning up almost all the linting errors in the logger

Test Plan: ... run the build

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3605
2017-01-09 10:38:48 -08:00
Evan Morikawa afdc5a3ef9 [local-api] linter fixes 2017-01-09 09:57:06 -08:00
Evan Morikawa 4a760ff5ec [local-sync] audit database indices
Summary:
Fixes T7398

We were create unnecessary and duplicate indices for the IDs of all of
our objects and increasing db write overhead.

We were not creating the correct reverse index for our join tables.

The search API'd db is already in scope of the accountId, this is an
unnecessary constraint on the query

Test Plan: manual

Reviewers: spang, juan

Reviewed By: juan

Maniphest Tasks: T7398

Differential Revision: https://phab.nylas.com/D3606
2017-01-09 09:45:33 -08:00
Christine Spang 6d72bb2aaf [local-sync] Optimize header & MIME structure download
Summary:
Headers can be quite big, so we might as well download and store only
the ones that we care about. This patch also makes it so we stop
downloading MIME structures twice per message.

While it's possible that we _may_ want to make more headers accessible
later, we don't currently make the generic pile of headers accessible to
N1 or N1 plugins in any way, so doing that would end up requiring
changes to the sync code regardless. I think it's worth optimizing the
base experience rather than trying to predict what we may want in the
future. Plus, it seems more likely that we'll want to build future
extensibility using thread metadata, rather than message headers.

On inboxapptest1@fastmail.fm, this patch decreases the size of the
generated sqlite file for a fully synced mailbox by 35%.

Test Plan: manual

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3611
2017-01-08 13:27:10 -08:00
Christine Spang 9d05bb9d1c [local-sync] don't play fast and loose with newlines, or a lack thereof 2017-01-07 14:34:03 -08:00
Christine Spang 8238fe9594 [local-sync] Correctly handle messages with non-alternative multipart text bodies
Summary:
It's possible to have multiple inline HTML parts in a message, or even
a multipart/alternative part that contains text and HTML, followed by a
plaintext signature. Previously, if there was more than one text part in
an email, we would pick the _last_ text/html or text/plain part that we
found, and treat that as the entire message body. This works most of the
time, but fails to display the full message body in some edge cases.
This patch fixes that by resolving multipart/alternative subparts to a
single part in the mimepart fetch stage, and then treating each desired
mime part separately when parsing the message, concatenating them if
there are multiple.

This makes K2's handling of multipart MIME message text better,
bug-wise, than the Python sync engine's, which has been mangling some
rare messages forever. (Example from my email: every email from the MIT
EECS Jobs List has never displayed the mailing list signature in N1.)

Note that this patch also removes our tentative support for PGP
encrypted messages. I'd rather add that back in later when I've dug up
some real example messages to test on, rather than leaving it in in its
current not-really-tested and probably not-really-working state, since
it makes it harder to make sure that the rest of the logic isn't broken.

Test Plan: manual for now - added examples of this to my growing list of regression tests to add to the message parser unit tests once I fix them

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3600
2017-01-07 14:11:27 -08:00
Christine Spang 78aa3291d6 [local-sync] Bump limit on finding matching threads
I'm kind of worried that weird stuff may happen on short, common
thread subjects. The Python sync engine has _no_ limit, and it seems
to work OK.
2017-01-07 13:13:22 -08:00
Christine Spang 4aa6cb3ca1 [local-sync] Port generic IMAP threading logic from Python Sync Engine
Summary:
We sync messages in the same order as the Python sync engine (newest to
oldest, generally), so we should be able to just use the same threading
algorithm. While we may still want to take into account References /
In-Reply-To at some point, this is a big step up from the current
thread-matching-only.

Test Plan: manual --- could pretty easily port the unit tests from the python codebase if we wanted

Reviewers: khamidou, juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3604
2017-01-07 13:11:33 -08:00
Halla Moore c4588ec011 [local-sync] Re-add code to associate labels with new messages
This code was accidentally removed during a merge conflict. Code was
originally added in commit 333647.
2017-01-07 12:48:37 -08:00
Jackie Luo e7de61b56a [local-sync] Designate role for archive folder 2017-01-06 16:53:24 -08:00
Evan Morikawa 33080805e3 [local-private] Disable mail merge, scheduler, send later, reminders 2017-01-06 15:37:18 -08:00
Evan Morikawa 6f54d9fa6a [local-sync] remove verbose sequelize flag in fork for perf
https://github.com/nylas/sequelize/compare/9cdd4d6bfaa1e7d61a700a6ac3c0e64e45a61...nylas-3.30.0

We spend a HUGE amount of CPU in the sqlite3 verbose logging since we generate stack traces for each and every query we send.

This fork removes the verbose call that causes that.
2017-01-06 15:18:57 -08:00
Juan Tejada 6284905714 Revert "Make K2 recover from connectivity losses."
This reverts commit 0b3e3d2f39.

Interrupting sync by closing connection causes errors downstream when
`syncNow` is called elsewhere. Instead of interrupting by closing the
connection, we will post a patch to interrupt the sync loop properly
2017-01-06 14:30:18 -08:00
Juan Tejada 83ef8c12b3 [local-sync] Restore global queue for message processing to improve perf
Summary:
Sync operations are mostly bound by I/O and the imap connection.
What we believe that is mostly affecting cpu and battery life is that node’s event
loop is being hosed with cpu intensive message processing operations.

To alleviate this, we do a few things:

- Restore a global message processing queue to process messages serially and meter cpu usage (message processing continues to be a fire and forget call from within sync operations)
- Move actual cpu intensive work to the message processing queue, i.e. `MessageFactory.parseFromImap`
- Keep track of message processing queue length, and skip sync operations if queue is too big to prevent massive memory consumption

This commit also renames the package from new-message-processor to
message-processor, given that now it processes both new and existing
messages, and we like to minimize confusion.

Test Plan: manual

Reviewers: spang, khamidou, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3602
2017-01-06 14:28:33 -08:00
Halla Moore c7f8796409 [local-sync, iso-core] Fix operations on Categories
Summary:
- Ensure delete deltas make it through to N1
- Don't fail if we can't find a category that needs to be deleted

Test Plan: local

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3593
2017-01-05 16:46:11 -08:00
Evan Morikawa 4030d7cb3b [local-sync] add attachments
Summary:
- Adds `File` objects onto the `Message`s so N1 sees attachments
- Ensures `File` is eagerly loaded for all messages
- Base 64 streams attachments through the local /download endpoint
- ExtractFile only uses disposition type attachment when extracting
  attachments
- Makes sure we save existing messages when processing them

Test Plan: manual :(

Reviewers: juan, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D3595
2017-01-05 16:33:38 -08:00
Christine Spang d6e0b7eb8d [local-sync] Do not consider HTML or plaintext attachments to be body parts
Summary:
We were previously not taking into account the 'Content-Disposition'
MIME header, which differentiates between parts intended for display
('inline') and parts that are instead transferred files ('attachment').
See the RFC for more details:

https://www.ietf.org/rfc/rfc2183.txt

Fixes: T7367

Test Plan: unit test coming soon---have the test data and going to fix all message parsing test cases at once

Reviewers: juan, jackie, evan, halla

Reviewed By: evan, halla

Differential Revision: https://phab.nylas.com/D3585
2017-01-05 16:18:48 -08:00
Jackie Luo 040426e80a [local-sync] Include from field in thread participants 2017-01-05 13:00:57 -08:00
Halla Moore c7bec7150a [local-sync] Make sure labels are properly associated to new messages
Summary:
Labels don't get added via passing in a labels attribute to
create(). We need to call addLabels() instead.

Test Plan: Tested locally

Reviewers: juan, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3581
2017-01-04 17:49:22 -08:00
Christine Spang 0cbe8e2600 [local-sync] Trim NUL bytes from body strings
These bytes will cause SQLite to blow up with the following error
on insertion:

'SQLITE_ERROR: unrecognized token'

Fixes: T7331
2017-01-04 15:47:16 -08:00
Christine Spang 0b53d8599f Update sequelize point version everywhere 2017-01-04 15:47:16 -08:00
Evan Morikawa 4237cf2bd5 refactor(send): split delivery from sent folder stuffing
Summary:
refactor multi-send

This diff started off by fixing sending with attachments.

The issue is that our `FileUploadStore` listened for
`Actions.sendDraftSuccess` as its signal to remove the files from the
.nylas temp directory. Unfortunately, the old MultiSend tasks, after
delivery of the message, would try and put the base message in the sent
folder. Since we already deleted the file from our local temp dir,
creating the base message for the sent folder would fail.

This exposed a much bigger issue which is that we don't consistently
distinguish between "delivery" of a message and any post-processing we do
(like filling the sent folder). This was leading to a variety of other
subtle issues.

For example, N1 assumes that if the SendMessage task fails, then we pop
the draft back up and ask the user to try again. Unfortunately, since we
were combining "delivery" and "post processing" it was possible for the
message to actually deliver, but fail when stuffing the sent folder, or
fail due to some other random bug. This would cause the user to send the
message twice.

To help us ensure we never "deliver" twice and handle errors more
intuitively, I separated out the two concepts.

Now there are "send" set of tasks and endpoints, and a
"EnsureMessageInSentFolder" set of tasks and endpoint (the latter used to
be ambiguously known as ReconcileMultiSend, whatever that meant)

The logic for send hasn't changed. This is mostly a renaming and moving
files around.

Test Plan: manual :(

Reviewers: jackie, juan, halla

Reviewed By: juan, halla

Differential Revision: https://phab.nylas.com/D3577
2017-01-04 15:41:35 -08:00
Christine Spang f5ef0323c0 [local-sync] Bump sequelize version to latest stable
Nothing major in here, just a couple little bugfixes.
2017-01-04 08:58:22 -08:00
Christine Spang c8e0f4453d [local-sync] Remove no-longer-used getLengthValidator function 2017-01-04 08:21:47 -08:00
Christine Spang dfcf5e0d11 [local-sync] Remove incorrect length validation on From field
Contrary to what you might think, a message can have both an empty From: header
and multiple From: headers / multiple addresses in a From header. In that case,
we must save all of them and let the client decide how to display.

Fixes: T7370
2017-01-04 08:19:35 -08:00
Karim Hamidou 0b3e3d2f39 Make K2 recover from connectivity losses.
Summary: I've found a pretty annoying bug --- N1 would stop syncing all accounts after the Internet connection dropped. It seems that deep inside node-imap or NodeJS itself, connections aren't timing out the right way. To work around this, this diff unilaterally restarts the sync every `nextSyncIn` milliseconds.

Test Plan: Tested manually by cutting internet access and checking that K2 recovered.

Reviewers: evan, juan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3573
2017-01-03 16:03:27 -08:00
Christine Spang 0ac22782cf [local-sync] Add node-iconv dependency
The 'encoding' library transparently upgrades to using iconv instead of
iconv-lite, if available. This allows us to support more encodings in
emails, such as ISO-2022-JP.

Fixes: T7358
2017-01-03 11:17:10 -08:00
Juan Tejada c3aa82adfc [local-sync] Convert to async 2017-01-03 09:37:33 -08:00
Evan Morikawa ac20d5b038 [local-sync] show messages sent to self
Summary:
If you sent an email to yourself it would not show up in your inbox. This
is because sent messages would never get a lastMessageReceived timestamp.
Since we order the inbox by lastMessageReceived, setting that to null to
on sent mail would mean it never shows up in the thread list.

Also fixed an assertion bug in SFDC that requires transactions to return a
promise.

Finally added extra debug interfaces that will show more info if the delta
stream detects an inconsistency

Test Plan: manual

Reviewers: juan, halla, jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3552
2017-01-03 09:31:34 -08:00
Mark Hahnenberg a0c8d8b692 [local-sync] Return IMAP UIDs for Messages via API
Summary: See title

Test Plan: Run locally

Reviewers: evan, spang, juan

Differential Revision: https://phab.nylas.com/D3569
2016-12-30 13:11:41 -08:00
Jackie Luo a2c9555e2a [local-sync] Fix dates for message hashing
Summary: We were creating duplicate `Message` objects because the formatting for the date was different between `buildForSend` and `parseFromImap`. Now, we create the initial hash using the same format that `buildmail` uses to ensure that we generate the same IDs.

Test Plan: Tested locally.

Reviewers: evan, juan, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D3559
2016-12-29 15:58:21 -08:00
Christine Spang 40c7b09e27 [local-sync] Use mimelib to parse contacts
Summary:
Because of the way we were attempting to parse contacts from
From/To/Cc/Bcc headers by converting them to JSON with a regex, we were
erroneously breaking contacts that contained commas in quoted names into
multiple contacts. This could result in things like parsing multiple
addresses for the From: header, incorrectly!

To resolve the problem, replace our homegrown logic with mimelib's
seemingly excellent parseAddresses(), which handles this and a myriad of
other cases correctly.

Fixes: T7370

Test Plan: unit tests included

Reviewers: mark

Reviewed By: mark

Differential Revision: https://phab.nylas.com/D3565
2016-12-29 15:48:12 -08:00
Christine Spang 952349ee72 [local-sync] Remove TEXT param on message.body model definition
This doesn't do anything with sqlite, and just generates the following
warning in the logs:

>> WARNING: SQLite does not support TEXT with options. Plain `TEXT` will be used instead.
>> Check: https://www.sqlite.org/datatype3.html
2016-12-29 15:47:52 -08:00
Christine Spang 09749c53da [local-sync] Fix lint 2016-12-29 10:59:17 -08:00
Christine Spang e30b299b39 [local-sync] Mark message factory tests for fixing later
Will fix these once I've finished up the current slew of bugfixes I'm
working on---kind of a pain to ensure they're passing in all
intermediate states.
2016-12-29 10:59:17 -08:00
Mark Hahnenberg 5fd23e0f72 [local-sync] Add search for Office365
Summary: See title

Test Plan: Run it locally

Reviewers: juan, evan

Differential Revision: https://phab.nylas.com/D3560
2016-12-27 12:06:54 -08:00
Christine Spang 8135e22213 [local-sync] Catch UniqueConstraintError when associating folders/labels with threads
Summary:
Similar to the fix in D3555, concurrent message processing may cause insert
races for folder and label thread associations. If the row is already present,
we can simply do nothing.

Test Plan: manual for now

Reviewers: jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3557
2016-12-23 18:35:09 -08:00
Christine Spang 6dcc12843c [local-sync] Fix message parsing when no Date header present
Summary:
When the Date: header is not present, use the INTERNALDATE from the IMAP server
instead.

Test Plan: manual for now - will add a regression test for this though

Reviewers: juan, jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3556
2016-12-23 18:32:29 -08:00
Christine Spang 0644d2663d [local-sync] Fix UniqueConstraintError inserting contacts from messages
Summary:
Because of JavaScript's asynchronous nature, it is possible that we will
be processing several downloaded messages concurrently. This can lead to
calling extractContacts() in an interleaved fashion, which it was not
designed to handle. It looks up which contacts are already in the
database and then performs inserts or updates accordingly, assuming
nothing has changed in the contacts table in between---which is not
true! If several messages have similar contacts, an insert race can
cause one of the inserts to throw an unhandled exception.

We fix this by simply catching the unique constraint error, and falling
back to an update instead. (There's not really a better way to deal
with write races other than to enforce that we process contacts from
messages serially, as transactions are of no help here.)

This commit also removes extractContacts()'s return value, which is not
currently used and I found confusing.

Test Plan: manual

Reviewers: juan, evan, mark, jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3555
2016-12-23 18:31:51 -08:00
Christine Spang de1b67287c fix(snippet-parsing): Don't add extraneous spaces after text format tags
Summary:
This was leading us to put funny things like 'Nylas !' in some snippets that used
tags like <i> and <b> for text formatting. This is probs a teeny little bit slower
than the previous version since it invokes a callback on a lot more nodes, but we
can't really fix this issue without knowledge of the preceding tag name.

Test Plan: unit test included!!

Reviewers: evan, jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3553
2016-12-23 18:26:35 -08:00
Christine Spang 99899be7c2 [models] Remove unnecessary Reply-To array length validation
Summary:
I have quite a few emails in my mailbox that have both multiple Reply-To
addresses. This is perfectly OK by the spec.

Fixes: T7369

Test Plan:
regression test coming - making a list and planning to update all the tests once I've hammered out the current crop of fixes I've identified

I also tested and made sure that N1 does the right thing in this case...
multiple Reply-To addresses are displayed correctly, and when you hit "Reply" a
new draft is started with both in the To: field. Makes sense given this is
something the Python sync engine supported too.

Reviewers: jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3558
2016-12-23 14:41:08 -08:00
Jackie Luo dda0830220 [local-sync] Allow folders and labels to be null in toJSON() 2016-12-22 14:58:18 -08:00
Christine Spang a947cc063a [local-sync] Use mimelib to parse headers
Using node-imap's parseHeader function to parse headers was resulting in
a huge number of message parse failures on Office365 accounts, because
the results contained unicode control character 9 and we'd then feed that
string to JSON.parse when extracting contacts, which would throw an
exception.

Using mimelib's header parsing function eliminates these errors.
2016-12-22 08:51:16 -08:00
Evan Morikawa c299fd9ebe perf(delta): replaces API delta stream with direct in-memory one
Summary:
This replaces the API delta stream with a direct in-memory one

Addresses T7300

Test Plan: manual

Reviewers: jackie, halla, juan

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3548
2016-12-21 18:42:52 -08:00
Juan Tejada 49c61fde0c [local-sync] Fix authentication notifications
Summary:
Associated N1 Diff: D3545

This commit ensures that authh notifications are showed when the
underlying sync worker fails and are cleared when an account is
successfully reconnected

To achieve this, we manually keep track and update syncStates where
appropriate via `Actions.updateAccount`, given that we have access to
N1's version of the account directly from local-sync.
Initially I was considering account delta stream to the cloud-api and the local-api, but that
just complicated things more than it helped.

This commit also fixes a bug with refreshing the gmail token in which we
we were only attempting a token refresh upon restarting the app

This addresses: T7346, T7305, T7335

Test Plan: Manual

Reviewers: halla, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3544
2016-12-21 07:22:39 -05:00
Evan Morikawa f0436e17d4 [local-sync] use async await in processNewMessage and fix logging 2016-12-20 17:09:17 -08:00
Evan Morikawa ab5a66d4e7 [local-sync]: better sync reasons 2016-12-20 16:46:58 -08:00
Evan Morikawa 25c20ce92c [local-sync] add logging for syncbackTasks 2016-12-20 16:13:59 -08:00
Evan Morikawa 93db26fdc7 [local-sync, isomophic-core] nicer logging 2016-12-20 16:04:28 -08:00
Christine Spang e924e74c1b [local-sync] Optimize snippet extraction
Summary:
We were seeing JS blocking in snippet extraction of up to 2k ms. This
is because we were walking the entire DOM of a message and extracting
all text, regardless of message size---and using our own homegrown
DOM walker function.

To remedy this, use the standard TreeWalker from the Chrome browser
APIs (which in benchmarks looks 2-4x faster) and also exit out of
the DOM walking process once we've accumulated enough text to create
a snippet. Informal eyeballing of timing metrics for this function suggests
the new implementation is something like 10-100x faster for some messages.

As a bonus, we get to delete some code and end up with a cleaner
implementation!

Test Plan: old unit tests yaay

Reviewers: juan

Reviewed By: juan

Subscribers: evan

Differential Revision: https://phab.nylas.com/D3543
2016-12-20 15:33:27 -08:00
Evan Morikawa 5015d105b8 [isomorphic-core] fix sending on Office 365
Summary:
Fixed sending on Office 365
nodemailer needed a special tls flag beyond the standard SSL.
See: http://stackoverflow.com/questions/29812132/error-sending-email-using-nodemailer-via-office365-smtp-meanjs-scaffold

Test Plan: manual

Reviewers: juan, jackie, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3541
2016-12-20 13:08:30 -08:00
Jackie Luo 6bbceda709 fix(tracking): Save updated metadata correctly and stop sending account ID with request
Summary:
Save metadata correctly by reassigning an object to value.

Since account IDs are different between N1 and N1 Cloud, use just the message ID, which should be unique.

Test Plan: Tested locally.

Reviewers: evan, juan

Reviewed By: evan, juan

Differential Revision: https://phab.nylas.com/D3524
2016-12-19 15:40:38 -08:00
Juan Tejada 7c701c6369 [local-sync] Fix date parsing and tests
Make sure that we use the header date for our date field because that's
the one we can control and depend on for message id generation
2016-12-19 15:35:50 -08:00
Evan Morikawa bd33c5fdc3 [local-sync] temporarily remove validation in send 2016-12-19 09:38:12 -08:00
Evan Morikawa d55a2af2cd [cloud-api] refactor cloud API routes to use es6 & fix Gmail Auth
Summary:
This is a refactor of the auth APIs to use async/await. Gmail Auth is
pretty confusing and I wanted to make it cleaner to read and easier to
use. This is also part of the general API upgrade to modern ES6

This also fixes the Gmail auth error we saw at showcase

Test Plan: manual

Reviewers: halla, jackie, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3535
2016-12-19 09:25:07 -08:00
Juan Tejada 5810bb6b79 [local-sync] Fix issue with imap connection mail event
Summary:
See https://github.com/mscdex/node-imap/issues/585 for details.

This issue was causing us constantly run the sync loop without pauses,
i.e. every next sync loop was scheduled immediately.

Currently, when we receive a new `'mail'`event, we trigger a new sync loop. Previously, when this happened while a sync loop was already in progress we would just ignore the event. However, my recent patch keeps track of how many times we tried to start a sync loop while one was already in progress. If the number of times this happens is > 0, it will schedule the next sync loop immediately (as opposed to waiting a constant amount seconds before the next loop).

The problem is that this new logic is making the sync worker always schedule the next sync loop immediately (without pausing for a few seconds). This is due to the following chain of events (assume we are just syncing `all` and `trash` folders):

This commit is a temporary workaround to this problem.

Test Plan: manual

Reviewers: evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3537
2016-12-19 08:08:59 -08:00
Evan Morikawa 39b0e6c3ee [isomorphic-core] add office365 in provider list 2016-12-16 18:51:11 -05:00
Halla Moore b46ffd4a3f [local-sync] Fix a couple bugs that popped up while sending
- Pass in the account when creating an ImapConnection
- Wrap the return value of the SendMessage task in an object
2016-12-16 15:43:39 -08:00
Evan Morikawa 5a1fb3c9ad [local-api] fix validation errors on send 2016-12-16 18:29:52 -05:00
Christine Spang c6a80efc44 [local-sync] Fix parseFromImap specs
Lots has changed for the better! Tests work again also.
2016-12-16 14:42:26 -08:00
Juan Tejada abc5f35255 [local-sync] Ensure send runs fast, clean up multisend tasks
Summary:
Associated N1 Diff: D3530

This commit converts multi-send from a 3 step process into a 2 step
process

The first step creates the base message and sends a message per
recipient, each with its customized message body for tracking.

The second step reconciles all sent messages, specifically removing any
sent messages created by gmail, and saving the correct message to the
sent folder

This commit also ensures that we run the send tasks immediately by
ensuring we restart the sync loop if its already running

Test Plan: Manual

Reviewers: evan, jackie, halla

Reviewed By: jackie, halla

Differential Revision: https://phab.nylas.com/D3529
2016-12-16 14:41:20 -08:00
Evan Morikawa d095551e90 [isomorphic-core] add office365 auth support
Summary:
Adds support for office 365
Depends on D3532

Test Plan: manual

Reviewers: jackie, halla, mark, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3533
2016-12-16 16:53:05 -05:00
Karim Hamidou 101b99f4a7 [feat] Refresh Gmail access tokens when needed
Summary:
This is a small patch but it's pretty complex, because of the numbers of moving parts. Gmail has two types of tokens, access and refresh tokens. Access tokens have a limited shelf life of one hour. After that they expire and you need to use your refresh token to get a new one.

We've decided to do the access token generation on the server, because we don't feel comfortable giving our users both our Google client id and secret. To do that, I've added an endpoint, `/gmail/auth/refresh` which returns a valid access token as well as an expiration date for the token.

The only place where we handle token expiration is in the sync workers. Before trying opening a new connection we check if our access token is expired. If yes, we get a new one from the API. If there's an issue doing this, we notify N1 using `NylasAPIHelpers.handleAuthenticationFailure`.

There's a second patch for N1 with tiny related fixes.

Test Plan: Tested manually. Will need to test more in the real world.

Reviewers: evan, jackie, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3522
2016-12-16 11:38:45 -08:00
Juan Tejada 86a2b13730 [local-sync] Fix sync worker
- Correctly await async functions
- Make sync in progress more explicit
2016-12-16 11:38:15 -08:00
Christine Spang e77fbc21e1 [local-sync] Update comment 2016-12-16 11:06:04 -08:00
Halla Moore 5a7aa45629 [local-sync] Fix a couple of message parsing bugs
Summary:
- Don't fail if there's no subject, just set it to `(no subject)`
- Support "BINARY" content-transfer-encoding. (This really means
that there is no encoding, so it's simple to add support for it)

Test Plan: tested locally

Reviewers: jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3528
2016-12-16 10:50:35 -08:00
Evan Morikawa 1d254a7aaa [*] Add basic babel toolchain
Summary:
Adds babel to K2
Creates a simple build script so it'll run on prod.

Test Plan: manual

Reviewers: jackie, halla, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3527
2016-12-16 13:08:21 -05:00
Juan Tejada b17be6b873 [local-sync] Fix sync worker - Restore fns removed by mistake 2016-12-15 20:43:52 -08:00
Juan Tejada 2c6be51970 [local-sync] Fix typo 2016-12-15 18:45:24 -08:00
Juan Tejada 2233992f27 [local-sync] Allow sync-worker to be restarted
Summary:
Add internal state to the sync worker to allow for it to be interrupted
and restarted.

The concept in this commit is that if we've tried to trigger a sync enough times
while its already in progress, bail and start over.

Usually, we manually trigger sync loops when we queue a new SyncbackTasks,
so that the newly queued task gets executed. This is necessary because the only
way to run SyncbackTasks is via the sync loop, for consistency and simplicity
reasons.

For example, we might run into a case where we queue a SendMessage task,
and we want it to be executed ASAP, but if we're in the middle of a
syncing a mailbox with a ton of folders, we wont get to the SendMessage
task after some considerable time.

Specifically this commit makes it so:

- If the number of sync attempts while in progress is > 0, make sure we schedule the next sync immediately
- If we reach a threshold of sync attempts while in progress, interrupt sync and restart

Test Plan: todo :(

Reviewers: mark, spang, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3520
2016-12-15 15:17:45 -08:00
Juan Tejada 5189407e38 [local-sync] Fix syncback tasks execution
Summary:
We were doing all of this fancy filtering and sorting to determine which
tasks to run, but in the end, we were just running the whole unsorted
list (using the wrong variable)

Also extracted getting the list of tasks into its own function, for
easier unit tests (it should really have some)

And, also wanted to make sure other people looked at this code, since I
believe no one has before.

Test Plan: todo

Reviewers: mark, khamidou, spang, halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3516
2016-12-15 14:41:53 -08:00
Evan Morikawa 2d145800ae [local-sync] fix missing dependency 2016-12-15 17:04:51 -05:00
Evan Morikawa b542edce02 [local-private] require Rx from nylas-exports 2016-12-15 15:32:29 -05:00
Juan Tejada 3910799683 [local-sync] Fix contact parsing from T7327
Summary: See description at T7327

Test Plan: Manual, but this should have unit tests

Reviewers: mark, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3513
2016-12-15 12:30:59 -08:00
Juan Tejada e17b6d8d17 [local-sync]: Move sendmail-client and errors to isomorphic-core
Summary:
Move sendmail-client and errors to isomorphic-core, given that they will
probably be used by cloud-workers (plugin backends) and cloud-api

Depends on D3510

Test Plan: Manual

Reviewers: halla

Reviewed By: halla

Differential Revision: https://phab.nylas.com/D3512
2016-12-15 12:29:56 -08:00
Juan Tejada c8e71464f9 [local-sync] Update send endpoints to use SyncbackTasks
Summary:
Associated N1 diff: D3511
Convert send endpoints to use syncback tasks for consistency with how we
perform other imap operations, but primarily:
- So that it triggers a sync loop immediately and we pick up changes quickly
- To keep track of various send operations as a single unit (e.g. sending + saving to sent folder or deleting from sent)

This commit also fixes SyncbackRequest error handling and processing in
N1-- previously we were saving error fields to the syncbackRequests with
a format that didn't match N1's API error and which wasn't properly
serializable. (Also rename HTTPError to APIError)

Test Plan: Todo/Manual

Reviewers: jackie, halla, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3510
2016-12-15 11:55:40 -08:00
Juan Tejada b6d8459d50 [local-sync] Report folder syncState to N1
Summary:
Associated N1 diff: D3515

Stop ignoring deltas for Folder.syncState updates

Test Plan: Manual

Reviewers: mark, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D3514
2016-12-15 11:08:20 -08:00
Christine Spang e5a9e2cc9e [local-sync] Allow logging parsed messages to disk with NYLAS_DEBUG env var
Summary:
I've found this useful for generating test cases and am tired
of adding and removing this code!

Test Plan: inspect output of /tmp/k2-parse-output

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3518
2016-12-15 10:45:48 -08:00
Christine Spang ac5c7e3d2c [local-sync] Escape HTML entities in plaintext
Summary: This was understandably causing some messages to fail to display correctly.

Test Plan: unit tests are already broken for message parsing -- will fix in follow up diff

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3517
2016-12-15 10:41:36 -08:00
Evan Morikawa ee831ba0aa [local-private, local-sync] temporarily disable specs
[local-private] Disable more broken specs

Disable specs

Reenable local-sync tests
2016-12-15 12:57:24 -05:00
Juan Tejada b79488ae43 [local-sync, cloud-api, cloud-workers] Fix msg id collision, tracking and sending issues, some refactoring
Summary:
This diff solves a few separate issues from T7313, T7316, T7282, and it refactors
the send code a little bit.

Initially, the problem that led to this diff was generating message ids that
wouldn't collide (which was causing errors in the message-processor). Collisions
in ids were being caused by messages that contained the exact same participants,
subject and date (most likely due bots or scripts sending emails in quick
succession)

To prevent collisions this commit adds the `message-id` header as part of the
database message id, and ensures that we set it correctly before sending, and
that it remains consistent through send, multi-send, and the sync loop.

During the refactor and review, I removed some code that assumed that we were
syncing drafts (which we aren't), and also fixes a few other known and
unknown issues around sending, message creation, and tracking, like assigning
the correct date header (we were previously assigning the draft creation date
from within N1), fixing the tracking regex, among other smaller bugs/typos.

Will address inline TODOs in a separate diff

Test Plan: TODO!!! I will add tests in another diff

Reviewers: evan, halla, jackie, khamidou

Reviewed By: halla, jackie

Differential Revision: https://phab.nylas.com/D3507
2016-12-14 19:35:48 -08:00
Mark Hahnenberg a45bd4515a [local-sync] Fix Contact.toJSON
Summary:
We forgot to refactor `publicId` to just `id`, which was breaking contact
deltas in N1.

Test Plan: Run locally

Reviewers: khamidou, evan, juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3508
2016-12-14 17:20:56 -08:00
Mark Hahnenberg cfc8d3e315 [local-sync] Implement /thread/search endpoint for generic IMAP
Summary: See title

Test Plan: Run locally

Reviewers: juan, evan

Reviewed By: juan, evan

Maniphest Tasks: T7281

Differential Revision: https://phab.nylas.com/D3498
2016-12-14 11:50:22 -08:00
Halla Moore 138c79bf71 [local-sync] Fix contact validation
Summary:
Allow other fields to be passed in with participants, so that Contact
objects can be passed in as JSON. Also fix an error check.

Test Plan: tested locally

Reviewers: jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3504
2016-12-14 10:43:20 -08:00
Christine Spang c214ba1e34 [local-sync] Parse DOM to extract snippets
Summary:
This fixes multiple issues, including snippets telling you you
ought to look at the HTML as well as cruft like HTML entities
and CSS in snippets.

Test Plan: unit tests included o.O

Reviewers: juan

Reviewed By: juan

Subscribers: evan

Differential Revision: https://phab.nylas.com/D3500
2016-12-13 16:32:22 -08:00
Jackie Luo 5243629831 [local-sync] Update URLs and regex 2016-12-13 16:26:05 -08:00
Mark Hahnenberg b47cd28d89 [local-sync] Implement /threads/search endpoint for Gmail
Summary: See title

Test Plan: Ran it locally

Reviewers: khamidou, juan, evan

Reviewed By: juan, evan

Differential Revision: https://phab.nylas.com/D3496
2016-12-13 13:44:00 -08:00
Jackie Luo 4a6f1dd012 fix(tracking): Update server URLs and send MESSAGE_ID 2016-12-13 12:53:48 -08:00
Halla Moore 547ff416e7 [local-sync] Fix a couple of multi-send bugs
Summary:
1) Send the custom body, rather than the generic body
2) Extract contacts correctly so that the saved sent message has all the
   participants, rather than just the last one

Test Plan: Tested locally

Reviewers: jackie

Reviewed By: jackie

Differential Revision: https://phab.nylas.com/D3499
2016-12-13 11:45:59 -08:00
Evan Morikawa 655175d94f [cloud-api, local-sync] reordering for lerna 2016-12-12 10:37:43 -05:00
Evan Morikawa 5a5aeb6bb3 [local-private] move old edgehill src/pro into packages/local-private
Summary: This is a test

Test Plan: Testing

Reviewers: juan

Differential Revision: https://phab.nylas.com/D3493

[local-private] add old edgehill src/pro into packages/local-private
2016-12-12 10:09:58 -05:00
Mark Hahnenberg f32d0df7e0 [local-sync] Increment streamAll offset by chunkSize (#5)
Otherwise we'll infinite loop if there are more than 2000 results.
2016-12-09 11:15:04 -08:00
Mark Hahnenberg 60bca4acb2 [local-sync] Add index for Thread.id (#4) 2016-12-09 11:12:47 -08:00
Christine Spang 587f7787a6 fix(local-sync): Fix charset interpretation in message parsing
Summary:
This commit fixes the following bugs in message parsing:
- we were unilaterally decoding MIME bodies as UTF-8; instead, decode according
  to the charset data in the mimepart header
- '7bit' content-transfer-encoding means us-ascii, NOT utf-7
- only interpret valid content-transfer-encodings (previously we were trying
  to treat various charsets as transfer-encodings)
- clearer naming: s/values/parsedMessage/
- unify snippet cleanup between plaintext & stripped HTML (merging
  whitespace etc.)

Test Plan: units tests coming

Reviewers: juan

Differential Revision: https://phab.nylas.com/D3491
2016-12-09 11:01:04 -08:00
Jackie Luo 162dbbd141 fix(error): Treat error as object, not string 2016-12-08 18:32:23 -08:00
Jackie Luo 4a11bfe977 fix(message-factory): Unlink circular dependency 2016-12-08 18:10:17 -08:00
Jackie Luo 6e111c073a fix(message-ids): Use correct hashing for headers 2016-12-08 17:55:39 -08:00
Jackie Luo fae855f0fe feat(message-ids): Hash message IDs and replace in draft before sending 2016-12-08 17:48:34 -08:00
Evan Morikawa 947eb99b8d [local-sync] fix builds. Routes with trailing slash and main extension 2016-12-08 14:17:42 -08:00
Jackie Luo 7a763b604e feat(tracking): Add routes for open and link tracking 2016-12-08 13:38:29 -08:00
Juan Tejada 1ba56c5c05 [local-sync] Fix lint error 2016-12-08 10:28:29 -08:00
Evan Morikawa 2f786a8e91 [local-sync] fix delta sync not getting threads with updated labels 2016-12-07 17:47:49 -08:00
Evan Morikawa d161a30a34 [local-sync] Add global dbs and cleanup orphan messages 2016-12-07 16:39:01 -08:00
Juan Tejada 878735f52e [local-sync] Add todos 2016-12-07 16:16:45 -08:00
Juan Tejada a185a8a5fe [local-sync] Fix file/contact creation
We were getting sql unique constraint violation errors for ids because
we were attempting to create objects with the same id within the same
transaction.

This commit ensures that only attempt to write a contact with the same
id once, and that we check for all exsiting contacts before hand.

For file, we ensure that we don't attempt to write 2 files with the same
id more than once
2016-12-07 14:48:57 -08:00
Halla Moore 56f8d41b8c [local-sync] feat(send): Add support for attachments
Also move some helper function logic onto the Message model
2016-12-07 14:16:36 -08:00
Juan Tejada 8307976df8 [local-sync]: Fix label/folder id creation
We were using the stripped version of label/folder names for the id
hash, e.g. [Gmail]/Drafts would be Drafts.
However, we can't do this because it might collide with other names. e.g. if the
user created a Drafts label, it would end up colliding with [Gmail]/Drafts

Minor lint fix
2016-12-07 13:39:41 -08:00
Evan Morikawa edbf869ff7 [isomorphic-core] add more auth error states 2016-12-07 10:10:49 -08:00
Christine Spang a23c68092e [local-sync] Add specs for message parsing
Summary:
This commit also fixes snippets for HTML-only messages to strip out HTML
tags, and makes us preserve whitespace for plaintext emails by
displaying them in <pre class="nylas-plaintext"> tags, and makes us log
messages that fail to parse at all to a tempdir.

The only issue I found with using <pre> tags for plaintext email was
that some lines may trigger scrolling, so there is an associated commit
(D3484) that changes the CSS for <pre class="nylas-plaintext"> to wrap
lines.

In the future, we can add regression tests to this test suite whenever
we fix parsing bugs.

Test Plan: unit tests included

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3483
2016-12-07 07:25:28 -08:00
Ben Gotow c3bd3dc297 [local-sync] Don’t update contacts if name is the same 2016-12-06 17:51:12 -08:00
Evan Morikawa 6ac46d1079 remove console log 2016-12-06 17:20:43 -08:00
Evan Morikawa 7e485228af [cloud-api] fix param names 2016-12-06 16:03:31 -08:00
Evan Morikawa 83ef47d049 [*] package.json updates from lerna 2016-12-06 16:03:31 -08:00
Evan Morikawa 8cbda7505a [*] fix auth 2016-12-06 16:03:31 -08:00
Evan Morikawa 2cbb90bb3b [*] DRY Auth 2016-12-06 16:03:31 -08:00
Evan Morikawa 896f981408 [isomorphic-core] extract AuthHelpers to DRY 2016-12-06 16:03:31 -08:00
Juan Tejada 7468e8123e [local-sync] Update DeleteSentMessage task for ordering 2016-12-06 15:54:45 -08:00
Juan Tejada fda7fe18cc [local-sync] Ensure order correct order when running syncback requests
When running syncback requests, if a task is meant to change the UID of
a message (e.g. move it to a new folder), that task should be run after
other tasks that don't affect the UID. Otherwise, when trying to run the
other tasks, they would reference a UID that is no longer valid.

This commit will make sure that we run any tasks that will change message uids last,
/and/ make sure that we don't run more than 1 task that will affect the uids of
the same messages in a row (i.e. without running a sync loop in between)
2016-12-06 15:45:34 -08:00
Halla Moore e785d73bdc [local-sync, iso-core] feat(send): add finishing touches to gmail multi-send
Delete the sent messages that gmail automatically creates and save our
generic form of the draft as a sent message.
2016-12-06 11:37:47 -08:00
Juan Tejada 1a24840062 [local-sync] Correctly sync folders and labels
This commit will correctly keep track of folder and label ids when
creating them from N1.

Previously, when we sent the request to create a folder or label to our api,
we would immediately get back a serverId because it was created optimistically
in the back end— given that K2 is strictly non-optimistic, we won’t have a serverId
until some undetermined time in the future, and we need to somehow reference
the object that /was/ optimistically created in N1 to update the ui when
we do get the server id.

Since we can deterministically generate ids for folders and labels,
we "guess" what its going to be, and include it in the props of the syncback request
returned to N1. This is the simplest solution to get thing working
correctly right now, but we’ll need to revisit this in the future for
other types of objects (drafts, contacts, events), and revisit how we
will manage optimistic updates in N1 when we merge the 2 codebases
with K2 (given that K2 was designed to be non-optimisitc).
2016-12-05 18:56:36 -08:00
Ben Gotow aed1d59916 [local-sync] fix(folder-list): Support children when parent has no attribs 2016-12-05 16:20:17 -08:00
Ben Gotow 1e3b346c94 [local-sync] feat(specs): Add basic tests for folder sync 2016-12-05 16:07:49 -08:00
Karim Hamidou 04b1763965 [fix] Fix transaction creation for contacts
Summary:
Fixes T7283. We weren't creating deltas for contacts because we were inserting contacts using `UPSERT`, which requires us to add another sequelize hook.  Unfortunately, support for this hook is only available on sequelize 4.x.

I didn't want to upgrade our sequelize version right now and cause of bunch of mysterious failures, so I've simply changed the `UPSERT` to be either an `INSERT`or `UPDATE`. We didn't really need it anyway.

Test Plan: Checked that N1 was receiving contact deltas.

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T7283

Differential Revision: https://phab.nylas.com/D3481
2016-12-05 15:37:17 -08:00
Ben Gotow 269d61171a [local-sync] fix(specs): New specs for threading 2016-12-05 15:00:37 -08:00
Halla Moore 63032a2449 [local-sync] Fix(send): change some validation fields for multi-send 2016-12-05 12:55:56 -08:00
Ben Gotow 30c8bedd7a [local-sync] fix(specs): run npm test in local-sync dir 2016-12-05 12:16:53 -08:00
Ben Gotow 017e22c88d [*] Allow zero elements in the replyTo field 2016-12-05 09:57:47 -08:00
Halla Moore 6a51036e48 [local-sync, iso-core, cloud-core] feat(send): add multi-send support
Also renames JSONType() -> buildJSONColumnOptions() and
JSONARRAYType() -> buildJSONARRAYColumnOptions() to prevent passing
those return values in as just the type value instead of the entire
options object.
2016-12-02 15:20:31 -08:00
Evan Morikawa 2ba326dfc6 [local-sync] only enable logging in dev mode of N1 2016-12-02 17:34:05 -05:00
Christine Spang 9752eea9f7 [local-sync] Set thread IDs to the ID of a message in the thread
Since message IDs are now static but there's no good way to generate
static thread IDs while syncing an account from newest message first,
we give threads the ID of any message on that thread and, when setting
metadata, look up the local thread ID by first going through the
message table.
2016-12-02 14:13:47 -08:00
Evan Morikawa d9f3edad0f [isomorphic-core] ignore folder deltas due to just syncState version issues 2016-12-02 16:25:42 -05:00
Evan Morikawa b06566d8bd [local-sync] make syncbackRequest objects N1-ready 2016-12-02 16:14:42 -05:00
Juan Tejada b36f61812d [local-sync]: Don't create or sync \NonExistent or \NoSelect folders 2016-12-02 12:14:09 -08:00
Juan Tejada f1491fa4cc fix observable disposable 2016-12-02 12:09:35 -08:00
Juan Tejada 5ac3fe9ea8 [local-sync] Fix starred role on folders 2016-12-02 12:07:21 -08:00
Ben Gotow 5ff7a92197 [*] fix(deltas): 0 as first cursor, deltas from redis are already JSON 2016-12-01 18:54:26 -08:00
Ben Gotow 7712269402 [*] fix(deltas): Cloud-API not filtering deltas at all, refactor a few things
- Don’t need functions in delta.js which must be called to return promsies. Fun of promsies is that you don’t need to care when they’re built to attach a .then.

- Make boundary between route handler and delta stream builder more explicit, don’t do query parsing in helpers, always reply from handler.

- Remove pushJSON extension to outputStream which never actually received JSON.

- Remove `takeUntil` - disposing of the downstream observable should dispose of all the merged/upstream observables

- Rename inflate => stringify since the returned value is a string not an object.

- Remove support for delta streams with no cursors. Don’t think this was supposed to be a feature.

- Add accountId to Transaction models

- Make database hooks shared in isomorphic core
2016-12-01 18:41:46 -08:00
Karim Hamidou 15cfe2cec0 Strip the '[Gmail]/' prefix from folder names.
Summary:
T7253 has two related parts:
1. Stripping the '[Gmail]/' prefix from any canonical Gmail folders
2. Handling nested IMAP folders.

This diff fixes 1. Changes for 2. are forthcoming.

Test Plan: Tested manually. Checked that the part was stripped from the N1 folder list.

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3475
2016-12-01 16:49:09 -08:00
Juan Tejada d650be5429 [local-sync] Refactor tasks and /actually/ fix moving between Gmail folders
Moving to between gmail folders (all, spam, trash) or moving to inbox,
involves changing labels /and/ folders, simultaneously. For this I added
a task to perform both operations, and apply labels first before
attempting to move the folder
2016-12-01 16:37:49 -08:00
Ben Gotow 4b4ab726e2 [💄] fix eslint issues before they get overwhelming 2016-12-01 15:37:48 -08:00
Karim Hamidou aa49f85980 Fix bug where we wouldn't create an id for file parts. 2016-12-01 15:30:01 -08:00
Juan Tejada 2d932dd090 [*] Generate persistent id for Accounts based on email+settings
This also ensures that we can use the accountId as part of the ids for
other models, like labels and folders

Before this commit, labels and folders with the same name for different
accounts would have the same id, screwing things up in n1
2016-12-01 14:51:33 -08:00
Ben Gotow 47d8614ed7 [local-sync] Ship first sync metrics to honeycomb 2016-12-01 14:23:52 -08:00
Juan Tejada ce27b0db2a [local-sync] Fix setlabels task
Make sure we /remove/ the labels when we get an empty set of label ids
2016-12-01 14:03:19 -08:00
Evan Morikawa aba77ca637 [cloud-api] add npm start for pm2 launch 2016-12-01 16:33:05 -05:00
Juan Tejada b43be69cd3 [local-sync] Give better name to thread folders task 2016-12-01 13:30:47 -08:00
Juan Tejada 8939364dc3 [local-sync]: Add distinct ids to folders and labels 2016-12-01 11:57:29 -08:00
Ben Gotow 209122c346 [cloud-api] Fix more broken package.jsons 2016-12-01 11:39:25 -08:00
Karim Hamidou 47e0683cac First step to getting persistent id in K2
Summary:
This diff adds persistent unique ids for messages and contacts. For messages, we just take a hash of the headers. For contacts, we hash the contact's email address.

This diff bundles a couple of tiny fixes too, like always trying to restart an account's sync, even after an exception.

Note that since there's no reliable way to have persistent ids for threads, we'll have to change our code to use message ids instead. Alas, that's a story for another (massive) diff.

Test Plan: Tested manually.

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3468
2016-12-01 11:15:13 -08:00
Ben Gotow 3d79f9b8be [local-sync] Run message processor for one message at a time
This avoids issues that arise when we process two messages on the same thread concurrently!
2016-11-30 17:26:23 -08:00
Ben Gotow 94722f27ab [local-sync] Fix “Add INBOX label” issue 2016-11-30 16:26:53 -08:00
Ben Gotow d8703b90c4 [local-sync] Fix deletion of labels 2016-11-30 16:26:53 -08:00
Ben Gotow bf9db2738c [local-sync] Fix ingestion of flags and labels 2016-11-30 16:26:53 -08:00
Ben Gotow 935d8cf141 [local-sync] Fix transaction log to only ignore syncState 2016-11-30 16:25:28 -08:00
Ben Gotow 2476cae297 [local-sync] Sync a bit faster for testing 2016-11-30 16:25:28 -08:00
Juan Tejada 1470565bcf [local-sync] Fix observable for deltas
We were missing a return :'(
2016-11-30 16:12:35 -08:00
Ben Gotow 1e01878e5a fix(sync): Fix attribute updates applying to threads 2016-11-30 13:55:49 -08:00
Evan Morikawa a36b1e1f28 [*] add delta endpoints and DRY deltaStreamBuilder
[cloud-core] add objectType to Metadata

[*] binding fixes to delta stream
2016-11-30 13:41:09 -05:00
Juan Tejada a37b90a209 [local-sync] Remove unecessary db queries in detect-thread 2016-11-30 10:17:59 -08:00
Ben Gotow ece519553f fix(sync): Issue with CONDSTORE args not passed to fetch 2016-11-29 18:02:25 -08:00
Ben Gotow 82f505b659 refactor(sync-worker): Convert IMAP operations to async/await 2016-11-29 17:04:01 -08:00
Ben Gotow fb9d770cc6 refactor(sync-worker) async/await for Karim 2016-11-29 16:20:18 -08:00
Ben Gotow 0c79ebb86a [local-sync] Synchronize K2 accounts with N1 accounts 2016-11-29 16:07:33 -08:00
Karim Hamidou 0879b6390e Make db reset synchronous. 2016-11-29 15:13:42 -08:00
Juan Tejada 20be7cc513 [local-sync] properly save folders when detecting thread 2016-11-29 15:04:45 -08:00
Karim Hamidou ac818f30fe Add a shortcut to restart the sync for an account from scratch. 2016-11-29 14:59:37 -08:00
Ben Gotow 48fff4f4e1 fix(dashboard): Remove sync policy 2016-11-29 14:58:52 -08:00
Juan Tejada b459076415 [local-sync] minor fix 2016-11-29 12:52:36 -08:00
Juan Tejada b7b0808689 [local-sync]: Load all db models 2016-11-29 12:38:49 -08:00
Juan Tejada 2fe5f73401 [iso-core] Fix dependencyin model 2016-11-29 11:56:00 -08:00
Juan Tejada a9be3bb3ed [local-sync]: Refactor message ingestion to write new messages only once
This will only generate 1 delta per new message instead of 2
Adds a MessageFactory to create messages from imapmessage objects, and
unifies and cleans up that logic
Also modified the message-processor to be more suited for local sync,
made emphasis that it's only for processing new messages, and got rid of
the while "pipeline" concept

- TODO message-processor specs are broken
2016-11-29 11:24:27 -08:00
Evan Morikawa fc24ffea63 [isomorphic-core]: move Transaction model to isomorphic-core 2016-11-29 13:57:19 -05:00
Ben Gotow f804c53522 [dashboard] Put dashboard into work window 2016-11-28 18:02:42 -08:00
Halla Moore 10f62f6b5a [local-sync, iso-core] feat(send): Support basic sending for gmail accounts 2016-11-28 14:46:31 -08:00
Ben Gotow 217ba1e020 [sync]: Sync again immediately if more emails remain 2016-11-28 12:00:57 -08:00
Juan Tejada f9b6e63958 [local-sync] Support parsing 8bit encoded messages 2016-11-28 11:41:16 -08:00
Evan Morikawa 048e077cc5 [local-sync] retry sync after error 2016-11-28 10:39:23 -08:00
Evan Morikawa 2c0c6164ec [local-sync] print sync error when in error state 2016-11-28 10:37:04 -08:00
Juan Tejada 64cb03f4cd Move non shared-models to local sync / remove duplicate DatabaseTypes 2016-11-26 12:48:48 -08:00
Ben Gotow 4bbfd6b906 fix(storage): Move to ~/.nylas-k2 2016-11-23 17:08:38 -08:00
Ben Gotow 5c37abc578 [n1] fix(sync): Add support for message encodings 2016-11-23 17:07:09 -08:00
Ben Gotow dd28d6b146 [n1] fix(api): Add support for messages?thread_id=1 2016-11-23 16:25:45 -08:00
Ben Gotow 42e20f106c fix(account): 2016-11-23 15:47:49 -08:00
Ben Gotow cfb1356be6 fix(account): Include name 2016-11-23 15:24:41 -08:00
Ben Gotow e7386ff4ae Gmail auth: resolved settings tests 2016-11-23 15:23:46 -08:00
Ben Gotow 30a94a6c9b [cloud] Store resolved settings for returning to client 2016-11-23 14:51:39 -08:00
Juan Tejada 3f050ea150 fix dangling paren 2016-11-23 14:26:24 -08:00
Juan Tejada f0caf042bd [local-sync]: Restore message-processor
Don't use pubsub for scheduling a message for processing, just use
nextTick
2016-11-23 14:25:15 -08:00
Evan Morikawa 78b96d24ca [local-sync] fix promise instance of check 2016-11-23 14:22:38 -08:00
Evan Morikawa 931943bea6 [local-sync] fix unnecessary transaction JSON parse and binding issue 2016-11-23 13:43:00 -08:00
Juan Tejada f45425a7b6 [local-sync] Remove unused message-types 2016-11-23 13:30:51 -08:00
Karim Hamidou 43030789a8 Make the delta stream work
Also replaces our LocalPubsubConnector by a TransactionConnector which
just uses EventEmitter.
2016-11-23 13:08:59 -08:00
Evan Morikawa 60801262c7 [local-sync] return as auth_token instead of token for N1 2016-11-23 12:35:48 -08:00
Juan Tejada f98c38fef4 [iso-core]: Make loadModels reusable by cloud-core 2016-11-23 12:16:58 -08:00
Evan Morikawa eacbb99f15 rearrange logging so message comes first in console 2016-11-23 12:01:47 -08:00
Karim Hamidou c05bc8ee63 Remove redis dependency
Conflicts:
	packages/local-sync/src/local-sync-worker/sync-process-manager.js
2016-11-23 11:50:13 -08:00
Juan Tejada f2a032c87c [iso-core]: Update api for loadModels 2016-11-23 11:49:32 -08:00
Evan Morikawa edd49c0f4a Use 2578 as port on example 2016-11-23 11:48:48 -08:00
Evan Morikawa 0243edeee3 [local-sync] Remove Gmail auth from local-sync 2016-11-23 11:07:04 -08:00
Juan Tejada 53a1f6e824 [local-sync]: Properly remove all refs to global.Metrics 2016-11-23 11:01:48 -08:00
Juan Tejada 654260b1a5 [iso-core] Use sequelize.import now that eval is enabled 2016-11-23 11:01:29 -08:00
Evan Morikawa 9707092cc9 Add logger fallback 2016-11-23 10:53:02 -08:00
Karim Hamidou ba58409f2c Fix module loading bug
Conflicts:
	packages/isomorphic-core/src/models/index.js
	packages/local-sync/package.json
2016-11-23 10:51:03 -08:00
Juan Tejada dcb78302b8 fix loadModels 2016-11-23 10:32:46 -08:00
Evan Morikawa 2cce4e0d7d Add sqlite3 since sequelize can't use better-sqlite3 2016-11-23 10:32:07 -08:00
Evan Morikawa 4eacd22846 Fix JSON parsing error 2016-11-23 10:19:35 -08:00
Evan Morikawa ae42c37606 Add better-sqlite3 2016-11-23 10:18:47 -08:00
Juan Tejada 5b7214e464 [local-sync]: Let local-sync start, add loadModels to iso-core 2016-11-23 10:18:35 -08:00
Evan Morikawa 3fac21458c Update local port to 2578 2016-11-23 10:12:02 -08:00
Evan Morikawa cd65135feb [isomorphic-core] add trailing ./ 2016-11-23 09:34:38 -08:00
Evan Morikawa 0793e97f33 [*] package.json updates post lerna bootstrap 2016-11-23 09:33:54 -08:00
Evan Morikawa 1112d3bccd [local-sync] update package.json to include missing deps 2016-11-23 09:27:41 -08:00
Evan Morikawa c3cca9f518 [isomorphic-core] Remove packages no longer used in isomorphic-core 2016-11-23 09:12:59 -08:00
Evan Morikawa b5bf4e07c4 [isomorphic-core] Move files into src folder for isomorphic-core 2016-11-23 09:12:54 -08:00
Evan Morikawa 21977a25ca [isomorphic-core] Rename nylas-core -> isomorphic-core 2016-11-23 09:12:50 -08:00
Evan Morikawa d01b4ffe77 [isomorphic-core] Uppdate refs nylas-core => isomorphic-core 2016-11-23 09:12:45 -08:00
Juan Tejada 814e014e39 Final nylas-core and cloud-core cleanup
- Remove unused exported PromiseUtils from cloud-core, import instead
from nylas-core where needed
- Remove unused MessageTypes from cloud-core
- Move MessageTypes from nylas-core to local-sync. It's completely
isolated to local-sync
2016-11-22 20:36:38 -08:00
Juan Tejada 3b7c40a870 [local-sync] Misc fixes from database-connector move 2016-11-22 20:25:43 -08:00
Juan Tejada 792ed2bb5c local[sync] Move missing file for local-syncs database-connector 2016-11-22 20:18:19 -08:00
Juan Tejada 0a24c01b5a [local-sync] fix path for local pubsub-connector 2016-11-22 20:13:35 -08:00
Juan Tejada 957ba73bd0 [local-sync] Make local logger es6 for compilation 2016-11-22 20:10:54 -08:00
Juan Tejada 296846adf5 [local-sync] Remove logger and metrics from local-sync and nylas-core 2016-11-22 20:07:11 -08:00
Evan Morikawa 3ff98f45a9 Rename generic Errors to IMAPErrors 2016-11-22 18:24:46 -08:00
Evan Morikawa 65fafc0390 Move SyncPolicy out of nylas-core to DefaultSyncPolicy 2016-11-22 18:20:34 -08:00
Evan Morikawa 106d7e57a1 Rename DatabaseConnector to LocalDatabaseConnector and move 2016-11-22 17:51:43 -08:00
Evan Morikawa 2b1c787eec Move PubSubConnector to LocalPubSubConnector out of nylas-core 2016-11-22 17:51:43 -08:00
Evan Morikawa c019e9a23b Move SchedulerUtils out of nylas-core to local-sync/src/shared 2016-11-22 17:07:48 -08:00
Juan Tejada 008a294242 fix(deps) Fix deps for local-sync and nylas-core 2016-11-22 16:55:08 -08:00
Evan Morikawa 951feae657 [local-sync]: moved spec into similarly named folder and updated refs 2016-11-22 16:08:10 -08:00
Evan Morikawa 9e867fa4fd [local-sync]: move folders into src folder 2016-11-22 16:03:38 -08:00
Ben Gotow 18c0ff40ba [cloud] fix(*): More misplaced packages 2016-11-22 15:40:18 -08:00
Evan Morikawa 25cca505b7 Moved cloud-metrics into cloud-core 2016-11-22 15:34:00 -08:00
Evan Morikawa e772e11196 [local]: rename folder nylas-api to local-api 2016-11-22 15:34:00 -08:00
Halla Moore 845139826b [local-sync] Check for missing Category roles by localized display names
Sometimes imap mailboxes aren't properly flagged with their roles, so we
check the display names against known variations to see if we can find any
missing roles.
2016-11-22 15:31:35 -08:00
Juan Tejada 5e42a7dd9e Merge branch 'master' of github.com:nylas/K2 2016-11-22 15:16:00 -08:00
Ben Gotow 1ec3c2e162 [cloud] fix(*): remove all traces of loggly 2016-11-22 15:13:48 -08:00
Juan Tejada 637d3ac6cc fix local-sync package 2016-11-22 15:13:28 -08:00
Evan Morikawa d4608dd3a6 Update package.json post lerna install 2016-11-22 14:52:42 -08:00
Karim Hamidou 372beeef52 More structure adapts.
Conflicts:
	packages/local-sync/package.json
2016-11-22 14:26:48 -08:00
Karim Hamidou 4d91dcd3a3 Basic structure changes to run K2 in N1 2016-11-22 14:23:16 -08:00
Ben Gotow 424ee4e1d2 [local] Fix package json 2016-11-22 13:55:04 -08:00
Karim Hamidou 0c5dd6ded7 Flesh out skeleton. 2016-11-22 12:25:27 -08:00
Juan Tejada ddd5641463 fix(folders): Properly update thread folders on sync 2016-11-22 12:24:13 -08:00
Karim Hamidou 3d31150bbb (fix) Set up base structure for local sync. 2016-11-22 12:01:45 -08:00
Ben Gotow 27ba2544dd Pull in cloud packages 2016-11-22 10:58:27 -08:00
Juan Tejada f2dbb2144b feat(labels): Add functioning endpoint for updating labels for messages & threads
- This commit also correctly sets the labels on the corresponding thread
whenever a message has its labels updated
- Fix removing labels from messages
2016-11-22 09:58:41 -08:00
Juan Tejada 45d682c957 feat(api): Can now set labels for messages 2016-11-21 17:41:57 -08:00
Evan Morikawa 1b1d356753 fix(package): re-order package.json files 2016-11-21 17:07:52 -08:00
Juan Tejada eba33080ac fix(messages): Fix raw message api endpoint 2016-11-21 14:36:54 -08:00
Ben Gotow 8efd4f7935 Fix another linter issue 2016-11-21 14:05:38 -08:00
Ben Gotow e87e67cea3 Fix linter issues 2016-11-21 14:00:35 -08:00
Halla Moore 7906e3303d Add placeholders for various routes that N1 uses. 2016-11-21 13:50:34 -08:00
Halla Moore 0fe6343137 Remove filtering from the collection APIs.
Affected collections were categories, contacts, files, messages, and threads.
2016-11-21 13:50:29 -08:00
Ben Gotow e10e51ab5d A few changes to support linking to K2 via the new GUI 2016-10-11 00:44:10 -07:00
Ben Gotow f9f78968b1 Use defaultValue as a template, fix critical sync issue 2016-07-15 19:01:50 -07:00
Ben Gotow 549ced6128 Revert change, @evan’s fix is better 2016-07-15 16:28:13 -07:00
Ben Gotow 18a8e5f09a Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-15 16:25:21 -07:00
Ben Gotow 7efe5db7e9 USE_CONSOLE_LOG for simple console logs 2016-07-15 16:25:18 -07:00
Halla Moore 8140076e17 Remove auto-scaling for the collapsed dashboard view, at least for now. 2016-07-15 16:09:17 -07:00
Ben Gotow 5095f0626f Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-15 13:29:25 -07:00
Halla Moore 0dad9bf7fa Auto-scale MiniAccounts in the collapsed, ungrouped dashboard view 2016-07-15 13:20:09 -07:00
Evan Morikawa dffb87bd4a Report errors earlier 2016-07-15 13:15:26 -07:00
Evan Morikawa 5e0bcc5eff Quieter logging on dev 2016-07-15 13:07:12 -07:00
Ben Gotow e13097045b Log boxname and category name as well 2016-07-15 12:39:28 -07:00
Halla Moore 0abd70c746 Add option to group by process in collapsed dashboard view 2016-07-15 12:31:07 -07:00
Ben Gotow 579fe43fdf Log when recovering from uidvalidity, don’t do it on first sync 2016-07-15 11:47:26 -07:00
Ben Gotow 95793877c6 Do file creation in a transaction, and with fewer saves 2016-07-15 11:14:35 -07:00
Ben Gotow e5bada04d3 Do contact insertion in a transaction 2016-07-15 10:23:01 -07:00
Ben Gotow 979401883d Make db connection pools smaller 2016-07-15 10:22:49 -07:00
Ben Gotow ac3f96e2d4 Fix accounts syncing in a hard loop due to redis loopback 2016-07-15 10:07:33 -07:00
Ben Gotow 13a723e663 Correctly detect condstore to lower db load 2016-07-15 09:46:31 -07:00
Ben Gotow 13879db9c8 Wait until tables are created before queueing sync 2016-07-14 19:32:13 -07:00
Ben Gotow 08c7ca8b0d Use EC2 instance ID instead of hostname 2016-07-14 18:52:30 -07:00
Ben Gotow 5062f8d02b Sort process ids 2016-07-14 18:33:46 -07:00
Ben Gotow 1996666516 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-14 18:18:54 -07:00
Ben Gotow daaa67818d Add missing unique indexes, only create tables when authing account 2016-07-14 18:18:48 -07:00
Halla Moore 6e2ae25519 Add a sum line to the dashboard's process load counts 2016-07-14 18:01:52 -07:00
Evan Morikawa 45f132b746 Fix thread moving to support new Promises 2016-07-14 17:37:38 -07:00
Ben Gotow a229ba1a90 Sort process entries on the dashboard 2016-07-14 17:34:33 -07:00
Ben Gotow 1ce7787632 Disable sequelize logging 2016-07-14 17:21:21 -07:00
Ben Gotow 1d08faece3 Fixes to still support sqlite 2016-07-14 17:21:02 -07:00
Ben Gotow 2f3ca2a906 Merge branch 'master' of ssh://github.com/nylas/k2
# Conflicts:
#	packages/nylas-core/hook-transaction-log.js
#	packages/nylas-core/models/account/transaction.js
2016-07-14 17:17:22 -07:00
Ben Gotow de3151cab4 Move to single database with many tables for accts 2016-07-14 17:14:16 -07:00
Evan Morikawa 1eef4c3428 Remove logs and rename variables 2016-07-14 16:36:13 -07:00
Annie 5b3f5c8a91 fixed thread syncing 2016-07-14 16:28:09 -07:00
Ben Gotow ea497f7ea2 A few changes for upcoming db refactoring 2016-07-14 15:48:48 -07:00
Halla Moore b14d5f7e8d Add process load counts to the dashboard 2016-07-14 14:51:54 -07:00
Juan Tejada 099e200ec5 Only log sync errors if they are permanent errors 2016-07-14 13:44:43 -07:00
Juan Tejada 37b2323cc7 Add metric for sync errors 2016-07-14 12:00:05 -07:00
Evan Morikawa 0921df432b Uses default from address 2016-07-14 11:40:46 -07:00
Evan Morikawa 6ce54c2a34 Add send endpoint 2016-07-14 11:34:30 -07:00
Juan Tejada b58c11605c Moves metrics into its own pkg to be able to instrument other services
- With the Metrics module inside nylas-core, and bc of our current lerna
setup, we required other modules like sequelize and redis before requiring
newrelic, thus preventing them from being properly instrumented
2016-07-14 11:20:58 -07:00
Juan Tejada 592b2af986 Update metric type for accounts_syncing_count 2016-07-14 10:49:40 -07:00
Juan Tejada 16b91ea394 Update metrics with signalfx - report # of syncing accts per host 2016-07-14 10:39:05 -07:00
Juan Tejada 0c900b072d Add new relic to all pkgs + Revert to PromiseUtils methods
- PromiseUtils does not conflict with newrelics changes to Promise
- Other misc fixes
2016-07-13 19:08:24 -07:00
Ben Gotow ec9f8581f7 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-13 18:26:49 -07:00
Ben Gotow 66951b4b1a Add more logging to process claiming 2016-07-13 18:26:46 -07:00
Annie a07174cc4e fixed json parsing of message 2016-07-13 18:19:13 -07:00
Halla Moore 0706701378 Make the grayAfter time more appropriate for production, 10 mins 2016-07-13 18:00:17 -07:00
Halla Moore 49f475cdd1 Add collapsed dashboard view 2016-07-13 17:45:54 -07:00
Juan Tejada 5c1704ac8e Fix thenReturn + misc logger fixes 2016-07-13 17:41:07 -07:00
Ben Gotow 07e3f3ab19 Make dashboard boxes slightly smaller 2016-07-13 17:34:42 -07:00
Ben Gotow 2a05e69e4c Sort IDs as numbers not strings 2016-07-13 17:25:39 -07:00
Ben Gotow b43b623ca6 Expand promise utils 2016-07-13 17:22:02 -07:00
Juan b60595f0f8 Merge pull request #3 from nylas/remove-bluebird
Remove bluebird
2016-07-13 16:54:21 -07:00
Ben Gotow 35c32a3645 After authing an account, close IMAP connection 2016-07-13 16:42:13 -07:00
Juan Tejada ab9c01a249 Remove bluebird
- Implement `each` and `promisifyAll` + other bluebird fns
2016-07-13 16:35:22 -07:00
Evan Morikawa 87905d0145 Fix transaction log to ignore syncState changes 2016-07-13 16:31:34 -07:00
Halla Moore fcbaac302b Change dashboard error appearances 2016-07-13 16:31:14 -07:00
Halla Moore 971b64b4c2 Add other dashboard optimizations
Fix typo in Account's shouldComponentUpdate method
Consolidate intervals into custom window events
Manually update ElapsedTime contents
2016-07-13 16:31:14 -07:00
Ben Gotow 93942e792d Also conert imap errors in createConnectionPromise 2016-07-13 16:20:43 -07:00
Evan Morikawa 8c33c4976f Better IMAP Error handling 2016-07-13 15:57:59 -07:00
Halla Moore 0b9933b514 Re-render accounts in more scenarios and update onWebsocketConnectedFake 2016-07-13 14:53:56 -07:00
Halla Moore b03b8b537d Optimize dashboard rendering
Add version to local copy of account and only re-render entire account
if the version is different. Create an ElapsedTime component that
re-renders on its own, and update SyncGraph to re-render on its
own as well.
2016-07-13 14:34:27 -07:00
Ben Gotow a5e3ddb445 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-13 12:39:11 -07:00
Ben Gotow a11ee2987b Change proxy to honor null values, create helper for open box name 2016-07-13 12:39:07 -07:00
Evan Morikawa 3d64affc52 Delta stream adhere to old Nylas spec 2016-07-13 12:37:38 -07:00
Halla Moore f2f6dec35a Add dashboard optimizations
Make account elements absolutely positioned and opaque
Send account updates all at once, at timed intervals
2016-07-13 12:35:49 -07:00
Juan Tejada 7f72ab7f14 Add loggly logging service to test it out
- Adds env to all logs, cleans up code a bit
2016-07-13 11:58:46 -07:00
Ben Gotow ffc2593c4e Log all box attributes to help track down bug 2016-07-13 11:42:34 -07:00
Annie 6e19cd84f5 Added view query param for contact and message routes 2016-07-13 11:37:35 -07:00
Ben Gotow 7056a4b8f4 Fix bug with accounts that have uidmin=0, not 1 2016-07-13 11:30:22 -07:00
Ben Gotow ecc8bd67d3 Clean up dashboard websocket code a bit 2016-07-13 11:11:32 -07:00
Ben Gotow 8629b5a055 New function to stub dashboard view 2016-07-13 10:57:05 -07:00
Ben Gotow ea4d5d0054 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-12 18:33:33 -07:00
Annie 17f920fb90 Ordered inbox messages chronologically 2016-07-12 18:33:19 -07:00
Ben Gotow eac4f72431 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-12 18:32:00 -07:00
Ben Gotow e89975456b Fix scenario where sync worker is re-assigned the same account before fully releasing it 2016-07-12 18:31:55 -07:00
Evan Morikawa e658f066dd Change transaction schema to match current API 2016-07-12 18:31:00 -07:00
Halla Moore 1ce430cd2a Add an auto refresh option to the dashboard's syncback requests modal 2016-07-12 18:27:04 -07:00
Halla Moore 8e790a0e15 Spruce up the dashboard
Consloidate modal functionality into its own component and make
general appearance fixes, especially with the Syncback Request
Details.
2016-07-12 18:27:04 -07:00
Ben Gotow 3e8623d383 Move charset definition to single location 2016-07-12 18:03:08 -07:00
Ben Gotow a62e858389 Make charset explicit on connection and models 2016-07-12 17:41:16 -07:00
Ben Gotow efc8d8ba12 Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-12 16:46:17 -07:00
Ben Gotow 562cedf971 Fix sync worker stopping forever on errors 2016-07-12 16:46:14 -07:00
Annie 83a6a8008b Add thread id to message model 2016-07-12 16:27:57 -07:00
Ben Gotow 9d7343eb91 Fix UTF7 reference - prod will not use ssh 2016-07-12 16:24:03 -07:00
Ben Gotow ae082c5b53 Fix support for Gmail accts with non-english folders 2016-07-12 16:12:04 -07:00
Ben Gotow 8b1e9564cf Fix UTF7 support — module didn’t support Node6 2016-07-12 16:11:29 -07:00
Ben Gotow 7d92438d57 Change firstSyncCompletion to string, cast to int for JSON 2016-07-12 15:23:55 -07:00
Ben Gotow dfa16fb5fc Allow firstSyncCompletion to be null 2016-07-12 15:04:12 -07:00
Ben Gotow 84d8979265 Add ability to auth gmail account via /auth 2016-07-12 13:24:48 -07:00
Halla Moore 3e6e5e95b9 Add dashboard functionality to clear sync errors 2016-07-12 12:20:12 -07:00
Ben Gotow 674da27296 Fix flipped errored / ended handlers 2016-07-12 12:15:46 -07:00
Ben Gotow b0a6ec066b Sync non-active accounts more infrequently 2016-07-12 09:53:04 -07:00
Ben Gotow ac627f1580 Remove use of Rx.toPromise(), which wasn't behaving as expected 2016-07-12 01:33:56 -07:00
Ben Gotow b44272621d Misc cleanup, put account ids on dashboard 2016-07-12 00:59:41 -07:00
Ben Gotow 4fb848e91f fix for re-authing the same account 2016-07-11 21:38:05 -07:00
Annie 87091a414a Merge branch 'master' into contacts 2016-07-11 18:30:28 -07:00
Annie c5dce43da7 Merge branch 'master' of github.com:nylas/K2 2016-07-11 18:30:19 -07:00
Annie d575e63ede replaced console logs with new logger 2016-07-11 18:30:08 -07:00
Ben Gotow 73fc371825 Make the graphs on the dashboard retina 💄 2016-07-11 18:24:18 -07:00
Juan Tejada afeb0e7b27 Create one CloudWatch stream per host
- This prevents `InvalidSequenceTokenException` when running in
production with multiple machines in an elastic beanstalk environment
- See
https://github.com/mirkokiefer/bunyan-cloudwatch/issues/1#issuecomment-193116799
2016-07-11 17:57:43 -07:00
Juan Tejada 413a77c323 Log unhandled errors in api and sync 2016-07-11 17:42:49 -07:00
Ben Gotow 74430dd80e Merge branch 'master' of ssh://github.com/nylas/k2 2016-07-11 16:56:27 -07:00
Ben Gotow 492ac21bb6 Primitive account deletion via DELETE /account 2016-07-11 16:56:18 -07:00
Annie caee5dbef0 Merge branch 'master' of github.com:nylas/K2 into contacts 2016-07-11 16:42:15 -07:00
Juan Tejada f8b8dfb87f Revert to running pm2 in no-daemon mode in dev
- Add a stream for pretty logging in dev mode
2016-07-11 16:40:48 -07:00
Annie 1fc30fa810 Merge branch 'master' of github.com:nylas/K2 2016-07-11 16:37:44 -07:00
Annie e673573fcd added folder view api route 2016-07-11 16:37:39 -07:00
Juan Tejada ae51646de6 Comment out new relic for now 2016-07-11 16:33:56 -07:00
Juan Tejada 2dc31cb576 Add number of syncing accounts to sync process manager heartbeat 2016-07-11 16:24:48 -07:00