mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FIX: Handle multiple In-Reply-To Message-ID in group inbox (#29912)
This fix handles the case where an In-Reply-To mail header can contain multiple Message-IDs. We use this header to try look up an EmailLog record to find the post to reply to in the group email inbox flow. Since the case where multiple In-Reply-To Message-IDs is rare (we've only seen a couple of instances of this causing errors in the wild), we are just going to use the first one in the array. Also, Discourse does not support replying to multiple posts at once, so it doesn't really make sense to use multiple In-Reply-To Message-IDs anyway.
This commit is contained in:
@ -927,23 +927,27 @@ module Email
|
||||
def create_group_post(group, user, body, elided)
|
||||
message_ids = Email::Receiver.extract_reply_message_ids(@mail, max_message_id_count: 5)
|
||||
|
||||
# incoming emails with matching message ids, and then cross references
|
||||
# Incoming emails with matching message ids, and then cross references
|
||||
# these with any email addresses for the user vs to/from/cc of the
|
||||
# incoming emails. in effect, any incoming email record for these
|
||||
# message ids where the user is involved in any way will be returned
|
||||
# message ids where the user is involved in any way will be returned.
|
||||
incoming_emails = IncomingEmail.where(message_id: message_ids)
|
||||
if !group.allow_unknown_sender_topic_replies
|
||||
incoming_emails = incoming_emails.addressed_to_user(user)
|
||||
end
|
||||
post_ids = incoming_emails.pluck(:post_id) || []
|
||||
|
||||
# if the user is directly replying to an email send to them from discourse,
|
||||
# If the user is directly replying to an email send to them from discourse,
|
||||
# there will be a corresponding EmailLog record, so we can use that as the
|
||||
# reply post if it exists
|
||||
if Email::MessageIdService.discourse_generated_message_id?(mail.in_reply_to)
|
||||
# reply post if it exists.
|
||||
#
|
||||
# Since In-Reply-To can technically have multiple message ids, we only
|
||||
# consider the first one here to simplify things.
|
||||
first_in_reply_to = Array.wrap(mail.in_reply_to).first
|
||||
if Email::MessageIdService.discourse_generated_message_id?(first_in_reply_to)
|
||||
post_id_from_email_log =
|
||||
EmailLog
|
||||
.where(message_id: mail.in_reply_to)
|
||||
.where(message_id: first_in_reply_to)
|
||||
.addressed_to_user(user)
|
||||
.order(created_at: :desc)
|
||||
.limit(1)
|
||||
|
Reference in New Issue
Block a user