FIX: Handle incoming emails without email address in From header (#5177)

This commit is contained in:
Gerhard Schlager
2017-09-12 22:35:24 +02:00
committed by Régis Hanol
parent 6831efe2e9
commit 31ecb4fecf
6 changed files with 53 additions and 8 deletions

View File

@ -37,6 +37,10 @@ describe Email::Receiver do
expect { process(:no_body) }.to raise_error(Email::Receiver::NoBodyDetectedError)
end
it "raises a NoSenderDetectedError when the From header is missing" do
expect { process(:no_from) }.to raise_error(Email::Receiver::NoSenderDetectedError)
end
it "raises an InactiveUserError when the sender is inactive" do
Fabricate(:user, email: "inactive@bar.com", active: false)
expect { process(:inactive_sender) }.to raise_error(Email::Receiver::InactiveUserError)
@ -229,10 +233,14 @@ describe Email::Receiver do
end
it "handles invalid from header" do
expect { process(:invalid_from) }.to change { topic.posts.count }
expect { process(:invalid_from_1) }.to change { topic.posts.count }
expect(topic.posts.last.raw).to eq("This email was sent with an invalid from header field.")
end
it "raises a NoSenderDetectedError when the From header doesn't contain an email address" do
expect { process(:invalid_from_2) }.to raise_error(Email::Receiver::NoSenderDetectedError)
end
it "doesn't raise an AutoGeneratedEmailError when the mail is auto generated but is whitelisted" do
SiteSetting.auto_generated_whitelist = "foo@bar.com|discourse@bar.com"
expect { process(:auto_generated_whitelisted) }.to change { topic.posts.count }