mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 17:56:40 +08:00
FIX: incoming email matches the wrong user if null bounce key available in db
This commit is contained in:
parent
c6adf7f032
commit
fc0b7c9e26
@ -69,7 +69,7 @@ module Email
|
||||
begin
|
||||
return if IncomingEmail.exists?(message_id: @message_id)
|
||||
ensure_valid_address_lists
|
||||
@from_email, @from_display_name = parse_from_field(@mail)
|
||||
@from_email, @from_display_name = parse_from_field
|
||||
@from_user = User.find_by_email(@from_email)
|
||||
@incoming_email = create_incoming_email
|
||||
process_internal
|
||||
@ -249,6 +249,7 @@ module Email
|
||||
end
|
||||
|
||||
def email_log
|
||||
return nil if bounce_key.blank?
|
||||
@email_log ||= EmailLog.find_by(bounce_key: bounce_key)
|
||||
end
|
||||
|
||||
@ -472,7 +473,9 @@ module Email
|
||||
reply.split(previous_replies_regex)[0]
|
||||
end
|
||||
|
||||
def parse_from_field(mail)
|
||||
def parse_from_field(mail = nil)
|
||||
mail ||= @mail
|
||||
|
||||
if mail.bounced?
|
||||
Array.wrap(mail.final_recipient).each do |from|
|
||||
return extract_from_address_and_name(from)
|
||||
|
@ -163,6 +163,14 @@ describe Email::Receiver do
|
||||
expect(IncomingEmail.last.error).to eq("RuntimeError")
|
||||
end
|
||||
|
||||
it "matches the correct user" do
|
||||
user = Fabricate(:user)
|
||||
email_log = Fabricate(:email_log, to_address: user.email, user: user, bounce_key: nil)
|
||||
email, name = Email::Receiver.new(email(:existing_user)).parse_from_field
|
||||
expect(email).to eq("existing@bar.com")
|
||||
expect(name).to eq("Foo Bar")
|
||||
end
|
||||
|
||||
it "strips null bytes from the subject" do
|
||||
expect do
|
||||
process(:null_byte_in_subject)
|
||||
|
Loading…
x
Reference in New Issue
Block a user