-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loop through exact matches and delivery emails to each info request. This is now possible because we check `InfoRequest#already_received?` when calling `InfoRequest#receive`. Previously this could result in requests receiving an email multiple times due to the same email coming in to the mail server multiple times, once for each address in the `To` header. Fixes #7913
- Loading branch information
1 parent
d388347
commit 5a24157
Showing
2 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,85 @@ | |
deliveries.clear | ||
end | ||
|
||
it "should append the email to each exact request address, unless that request has already received the email" do | ||
ir = info_requests(:fancy_dog_request) | ||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
expect(ir.incoming_messages.count).to eq(1) # in the fixture | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
expect(ir.incoming_messages.count).to eq(2) # one more arrives | ||
# send the email again | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
# this shouldn't add to the number of incoming mails | ||
expect(ir.incoming_messages.count).to eq(2) | ||
# send an email with a new Message-ID | ||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: ir.incoming_email | ||
) | ||
# this should add to the number of incoming mails | ||
expect(ir.incoming_messages.count).to eq(3) | ||
end | ||
|
||
it 'should append the email to every request matches, unless the requests has already received the email' do | ||
info_request_1 = FactoryBot.create(:info_request) | ||
info_request_2 = FactoryBot.create(:info_request) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(0) | ||
expect(info_request_2.incoming_messages.count).to eq(0) | ||
|
||
raw_email_data = <<~EML | ||
From: EMAIL_FROM | ||
To: EMAIL_TO | ||
Message-ID: [email protected] | ||
Subject: Basic Email | ||
Hello, World | ||
EML | ||
|
||
# send email to one request | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: info_request_1.incoming_email | ||
) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(1) | ||
expect(info_request_2.incoming_messages.count).to eq(0) | ||
|
||
# send same email to both requests, should only be delivered to the | ||
# request which hasn't already received the email | ||
receive_incoming_mail( | ||
raw_email_data, | ||
email_to: [ | ||
info_request_1.incoming_email, | ||
info_request_2.incoming_email | ||
].join(', ') | ||
) | ||
|
||
expect(info_request_1.incoming_messages.count).to eq(1) | ||
expect(info_request_2.incoming_messages.count).to eq(1) | ||
end | ||
|
||
it "should store mail in holding pen and send to admin when the email is not to any information request" do | ||
ir = info_requests(:fancy_dog_request) | ||
expect(ir.incoming_messages.count).to eq(1) | ||
|