As Nylas customer, we experienced quite some issues with distinct emails getting merged under the same thread. By documenting the use cases hopefully this will help understand that the algorithm is flawed for some common use cases & need to be addressed ASAP.
Based on the logic(https://github.com/nylas/sync-engine/blob/master/inbox/util/threading.py#L14), Nylas will merge ANY new email with the first thread in the Nylas account, that has a similar subject(https://github.com/nylas/sync-engine/blob/master/inbox/util/threading.py#L20) AND at least two participants in the email share the headers as the parcicipants in the thread(https://github.com/nylas/sync-engine/blob/master/inbox/util/threading.py#L41).
Below i'll describe the use cases that came to my mind that will merge distinc emails under the same Nylas thread. It is obvious that more complex scenarios could happen.
Note that this bug is only happening upon inbound emails.
To simplify things let's assume N as the Nylas inbox and P[1..X] the participants.
1: A Nylas account send distinct outbounds to P1 & P2 with the same subject, P1 & P2 reply but none of their email client set the email headers properly. The Nylas account will see two inbound with the same subject and at least two common participant headers, and merge them.
[from: [name: "Company", emai: N], subject: "late payment", To: [name: "Foo", email: P1]]
[from: [name: "Company", email: N], subject: "late payment", To: [name: "bar", email: P2]]
[from: [name: "", email: P1], subject: "Re: late payment", To: [name: "", email: N]]
[from: [name: "", email: P2], subject: "Re: late payment", To: [name: "", email: N]]
2: A Nylas account is being cc'ed on two distinct inbound threads with a similar subject, from the same sender. The Nylas account will see two inbounds with the same subject, and at least two common participant headers, thus merge them.
[from: [name: "P1", email: P1], subject: "New Cars available", To: [name: "USA factory", email: P2], Cc: [name: "My Boss", email: N]]
[from: [name: "P1", email: P1], subject: "Re: new cars available", To: [name: "Customer", email: P3], Cc: [name: "My Boss", email: N]]
3: P1 and p2 email P3 and P4, but cc a nylas account. Because P3 and P4 have been saved with the same name in the email client of P1 and P2, the Nylas account will merge the emails under the same thread.
[from: [name: "Employee 1", emai: P1], subject: "Today's meeting summary", To: [name: "Building manager", email: P3], Cc: [name: "Boss", email: N]]
[from: [name: "Employee 2, email: P2], subject: "Today's meeting summary", To: [name: "Building manager", email: P4], Cc: [name: "Boss", email: N]]
Based on those examples, it should be easy to see that a Nylas inbox will merge inbound emails under the first thread that has the same subject, and at least two participants with the same email header.
curl -X POST https://TOKEN_INBOX_1:@api.nylas.com/send --data '{"from":[{"name":"INBOX_1","email":"INBOX_1"}],"cc":[{"name":"My Boss","email":"INBOX2"}],"to":[{"name":"USA factory","email":"P2"}],"subject":"New Cars available","body":"thread between inbox 1 and P2, inbox 2 in cc"}'
curl -X POST https://TOKEN_INBOX_1:@api.nylas.com/send --data '{"from":[{"name":"INBOX_1","email":"INBOX_1"}],"cc":[{"name":"My Boss","email":"INBOX2"}],"to":[{"name":"Customer","email":"P3"}],"subject":"Re: New Cars available","body":"thread between inbox 1 and P3, inbox 2 in cc"}'
Note that i found another interesting use case. When you send an outbound, and receive automatic reply, most of the time the email clients will change the subject, so this might create a new nylas thread - haven't tested yet.