discourse/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.rb enqueue spam/dmarc failing emails instead of hiding (#8674) 2020-01-21 11:12:00 -05:00
build_email_helper.rb DEV: Upgrading Discourse to Zeitwerk (#8098) 2019-10-02 14:01:53 +10:00
cleaner.rb FEATURE: Remove attachments and truncate raw field for incoming emails (#8253) 2019-10-30 16:54:35 +11:00
message_builder.rb FEATURE: Log the SMTP response in EmailLog (#17056) 2022-06-15 10:28:30 +10:00
message_id_service.rb FEATURE: Overhaul email threading (#17996) 2022-09-26 09:14:24 +10:00
processor.rb FEATURE: Limit maximum recipients for group emails (#17971) 2022-08-18 18:18:58 +03:00
receiver.rb FEATURE: Overhaul email threading (#17996) 2022-09-26 09:14:24 +10:00
renderer.rb FIX: during concurrent emails generation renderer should not be reused 2019-10-10 08:50:48 +11:00
sender.rb FEATURE: Overhaul email threading (#17996) 2022-09-26 09:14:24 +10:00
styles.rb FEATURE: Enables support for dark mode emails (#16520) 2022-04-20 13:00:04 -05:00
validator.rb FIX: Parse address lists in embedded emails (#14514) 2021-10-06 15:07:29 +03:00