discourse/spec/lib/email
Martin Brennan e3d495850d
FEATURE: Overhaul email threading (#17996)
See https://meta.discourse.org/t/discourse-email-messages-are-incorrectly-threaded/233499
for thorough reasoning.

This commit changes how we generate Message-IDs and do email
threading for emails sent from Discourse. The main changes are
as follows:

* Introduce an outbound_message_id column on Post that
  is either a) filled with a Discourse-generated Message-ID
  the first time that post is used for an outbound email
  or b) filled with an original Message-ID from an external
  mail client or service if the post was created from an
  incoming email.
* Change Discourse-generated Message-IDs to be more consistent
  and static, in the format `discourse/post/:post_id@:host`
* Do not send References or In-Reply-To headers for emails sent
  for the OP of topics.
* Make sure that In-Reply-To is filled with either a) the OP's
  Message-ID if the post is not a direct reply or b) the parent
  post's Message-ID
* Make sure that In-Reply-To has all referenced post's Message-IDs
* Make sure that References is filled with a chain of Message-IDs
  from the OP down to the parent post of the new post.

We also are keeping X-Discourse-Post-Id and X-Discourse-Topic-Id,
headers that we previously removed, for easier visual debugging
of outbound emails.

Finally, we backfill the `outbound_message_id` for posts that have
a linked `IncomingEmail` record, using the `message_id` of that record.
We do not need to do that for posts that don't have an incoming email
since they are backfilled at runtime if `outbound_message_id` is missing.
2022-09-26 09:14:24 +10:00
..
authentication_results_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
cleaner_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
email_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
message_builder_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00
processor_spec.rb FEATURE: Limit maximum recipients for group emails (#17971) 2022-08-18 18:18:58 +03:00
receiver_spec.rb FEATURE: Overhaul email threading (#17996) 2022-09-26 09:14:24 +10:00
renderer_spec.rb Add RSpec 4 compatibility (#17652) 2022-07-28 10:27:38 +08:00
sender_spec.rb FEATURE: Overhaul email threading (#17996) 2022-09-26 09:14:24 +10:00
styles_spec.rb DEV: Use proper wording for contexts in specs 2022-08-04 11:05:02 +02:00