FIX: Prevent resurrecting old topics via email reply for group inboxes with SMTP enabled (PR #13382)

We already reject email replies to public topics via SiteSetting.disallow_reply_by_email_after_days and raising the OldDestinationError. This PR introduces similar behaviour for group inboxes, but without the rejection, and only when SMTP is enabled for the group.

If a reply is sent via email and the post is older than SiteSetting.disallow_reply_by_email_after_days days ago, then we create a new topic instead of making a reply in the old one and link back to the original topic. This is done to prevent long running group inbox discussions. The new topic looks like this:


Completely unrelated JS test failure

Logic to create new topic in this branch if destination_too_old?(post) && group.smtp_enabled and else is very similar (there is a difference in raw content).

What do you think if we merge them? Something like:

last_post = post_ids.any? && post = Post.where(id: post_ids).order(:created_at).last
if !post || (destination_too_old?(post) && group.smtp_enabled)
  create_topic # with different raw if necessary, maybe define method to calculate raw

this line is non obvious, what is going on here?

See discourse/receiver.rb at dfbac403fa367fc801bd86280f202d9fbf0302ec · discourse/discourse · GitHub, we also do it when the user is normally creating a topic via email to the group discourse/receiver.rb at dfbac403fa367fc801bd86280f202d9fbf0302ec · discourse/discourse · GitHub

I might just move it into create_topic because we have a similar call in create_reply:

Yeah good point about the similarity…will clean it up.

yeah moving it to create_topic may work especially if create_reply already has it.

@SamSaffron @lis2 I have addressed the review issues, please take another look :slight_smile:

      target_post = post_ids.any? && Post.where(id: post_ids).order(:created_at).last