2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:36:40 +08:00

FEATURE: handle bounced emails

This commit is contained in:
Régis Hanol 2016-05-02 23:15:32 +02:00
parent b7b5caa50e
commit 8e611ec7a1
27 changed files with 354 additions and 23 deletions

View file

@ -55,14 +55,57 @@ describe Email::Receiver do
expect { process(:bad_destinations) }.to raise_error(Email::Receiver::BadDestinationAddress)
end
it "raises an BouncerEmailError when email is a bounced email" do
it "raises a BouncerEmailError when email is a bounced email" do
expect { process(:bounced_email) }.to raise_error(Email::Receiver::BouncedEmailError)
expect(IncomingEmail.last.is_bounce).to eq(true)
end
it "raises an AutoGeneratedEmailReplyError when email contains a marked reply" do
expect { process(:bounced_email_2) }.to raise_error(Email::Receiver::AutoGeneratedEmailReplyError)
end
context "bounces to VERP" do
let(:bounce_key) { "14b08c855160d67f2e0c2f8ef36e251e" }
let(:bounce_key_2) { "b542fb5a9bacda6d28cc061d18e4eb83" }
let!(:user) { Fabricate(:user, email: "foo@bar.com", active: true) }
let!(:email_log) { Fabricate(:email_log, user: user, bounce_key: bounce_key) }
let!(:email_log_2) { Fabricate(:email_log, user: user, bounce_key: bounce_key_2) }
before do
$redis.del("bounce_score:#{user.email}:#{Date.today}")
$redis.del("bounce_score:#{user.email}:#{2.days.from_now.to_date}")
end
it "deals with soft bounces" do
expect { process(:soft_bounce_via_verp) }.to raise_error(Email::Receiver::BouncedEmailError)
email_log.reload
expect(email_log.bounced).to eq(true)
expect(email_log.user.active).to eq(true)
expect(email_log.user.user_stat.bounce_score).to eq(1)
end
it "deals with hard bounces" do
expect { process(:hard_bounce_via_verp) }.to raise_error(Email::Receiver::BouncedEmailError)
email_log.reload
expect(email_log.bounced).to eq(true)
expect(email_log.user.active).to eq(true)
expect(email_log.user.user_stat.bounce_score).to eq(2)
Timecop.freeze(2.days.from_now) do
expect { process(:hard_bounce_via_verp_2) }.to raise_error(Email::Receiver::BouncedEmailError)
email_log_2.reload
expect(email_log_2.bounced).to eq(true)
expect(email_log_2.user.active).to eq(false)
expect(email_log_2.user.user_stat.bounce_score).to eq(4)
end
end
end
context "reply" do
let(:reply_key) { "4f97315cc828096c9cb34c6f1a0d6fe8" }