mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 16:51:25 +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:
@ -218,9 +218,7 @@ RSpec.describe Email::Receiver do
|
||||
end
|
||||
|
||||
it "strips null bytes from the subject" do
|
||||
expect do process(:null_byte_in_subject) end.to raise_error(
|
||||
Email::Receiver::BadDestinationAddress,
|
||||
)
|
||||
expect { process(:null_byte_in_subject) }.to raise_error(Email::Receiver::BadDestinationAddress)
|
||||
end
|
||||
|
||||
describe "bounces to VERP" do
|
||||
@ -1366,13 +1364,29 @@ RSpec.describe Email::Receiver do
|
||||
expect(IncomingEmail.exists?(post_id: group_post.id)).to eq(false)
|
||||
end
|
||||
|
||||
it "processes a reply from the OP user to the group SMTP username, linking the reply_to_post_number correctly by
|
||||
matching in_reply_to to the email log" do
|
||||
it "processes a reply from the OP user to the group SMTP username, linking the reply_to_post_number correctly by matching in_reply_to to the email log" do
|
||||
email_log, group_post = reply_as_group_user
|
||||
|
||||
reply_email = email(:email_to_group_email_username_2)
|
||||
reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)
|
||||
expect do Email::Receiver.new(reply_email).process! end.to not_change {
|
||||
expect { Email::Receiver.new(reply_email).process! }.to not_change {
|
||||
Topic.count
|
||||
}.and change { Post.count }.by(1)
|
||||
|
||||
reply_post = Post.last
|
||||
expect(reply_post.reply_to_user).to eq(user_in_group)
|
||||
expect(reply_post.reply_to_post_number).to eq(group_post.post_number)
|
||||
end
|
||||
|
||||
it "handles multiple message IDs in the in_reply_to header by only using the first one" do
|
||||
email_log, group_post = reply_as_group_user
|
||||
|
||||
reply_email = email(:email_to_group_email_username_3)
|
||||
reply_email.gsub!(
|
||||
"MESSAGE_ID_REPLY_TO",
|
||||
"<#{email_log.message_id}> <test/message/id@discourse.com>",
|
||||
)
|
||||
expect { Email::Receiver.new(reply_email).process! }.to not_change {
|
||||
Topic.count
|
||||
}.and change { Post.count }.by(1)
|
||||
|
||||
@ -1386,7 +1400,7 @@ RSpec.describe Email::Receiver do
|
||||
|
||||
reply_email = email(:email_to_group_email_username_2_as_unknown_sender)
|
||||
reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)
|
||||
expect do Email::Receiver.new(reply_email).process! end.to change { Topic.count }.by(
|
||||
expect { Email::Receiver.new(reply_email).process! }.to change { Topic.count }.by(
|
||||
1,
|
||||
).and change { Post.count }.by(1)
|
||||
|
||||
@ -1400,7 +1414,7 @@ RSpec.describe Email::Receiver do
|
||||
|
||||
reply_email = email(:email_to_group_email_username_2_as_unknown_sender)
|
||||
reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)
|
||||
expect do Email::Receiver.new(reply_email).process! end.to not_change {
|
||||
expect { Email::Receiver.new(reply_email).process! }.to not_change {
|
||||
Topic.count
|
||||
}.and change { Post.count }.by(1)
|
||||
|
||||
@ -1417,7 +1431,7 @@ RSpec.describe Email::Receiver do
|
||||
|
||||
reply_email = email(:email_to_group_email_username_2)
|
||||
reply_email.gsub!("MESSAGE_ID_REPLY_TO", email_log.message_id)
|
||||
expect do Email::Receiver.new(reply_email).process! end.to change { Topic.count }.by(
|
||||
expect { Email::Receiver.new(reply_email).process! }.to change { Topic.count }.by(
|
||||
1,
|
||||
).and change { Post.count }.by(1)
|
||||
|
||||
|
Reference in New Issue
Block a user