-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '5988-info-requests-in-headers' into develop
- Loading branch information
Showing
4 changed files
with
120 additions
and
11 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
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 |
---|---|---|
|
@@ -322,4 +322,88 @@ | |
expect { decode_attached_part(mail.parts.last, mail) }.not_to raise_error | ||
end | ||
end | ||
|
||
describe :get_emails_within_received_headers do | ||
|
||
it 'returns an empty list if there is no Received header' do | ||
mail = get_fixture_mail('bcc-contact-reply.email') | ||
expect(get_emails_within_received_headers(mail)).to eq([]) | ||
end | ||
|
||
it 'returns an empty list if the Received header contains no email addresses' do | ||
mail = Mail.new(<<~EOF.strip_heredoc) | ||
From: "FOI Person" <foiperson@localhost> | ||
To: "Bob Smith" <bob@localhost> | ||
Cc: [email protected] | ||
Envelope-To: [email protected] | ||
Received: abc id abc from notAnEmail | ||
Date: Tue, 13 Nov 2007 11:39:55 +0000 | ||
Bcc: "BCC Person" <bccperson@localhost> | ||
Subject: Test | ||
Reply-To: | ||
Test | ||
EOF | ||
|
||
expect(get_emails_within_received_headers(mail)).to eq([]) | ||
end | ||
|
||
it 'returns a list containing the email if the Received header contains one email address' do | ||
mail = Mail.new(<<~EOF.strip_heredoc) | ||
From: "FOI Person" <foiperson@localhost> | ||
To: "Bob Smith" <bob@localhost> | ||
Cc: [email protected] | ||
Envelope-To: [email protected] | ||
Received: abc id abc from [email protected] | ||
Date: Tue, 13 Nov 2007 11:39:55 +0000 | ||
Bcc: "BCC Person" <bccperson@localhost> | ||
Subject: Test | ||
Reply-To: | ||
Test | ||
EOF | ||
|
||
expect(get_emails_within_received_headers(mail)). | ||
to eq(['[email protected]']) | ||
end | ||
|
||
it 'returns a (single dimensional) list containing the emails if the Received header contains multiple email addresses' do | ||
mail = Mail.new(<<~EOF.strip_heredoc) | ||
From: "FOI Person" <foiperson@localhost> | ||
To: "Bob Smith" <bob@localhost> | ||
Cc: [email protected] | ||
Envelope-To: [email protected] | ||
Received: abc id abc from [email protected] | ||
also there is [email protected] | ||
Date: Tue, 13 Nov 2007 11:39:55 +0000 | ||
Bcc: "BCC Person" <bccperson@localhost> | ||
Subject: Test | ||
Reply-To: | ||
Test | ||
EOF | ||
|
||
expect(get_emails_within_received_headers(mail)). | ||
to eq(['[email protected]', '[email protected]']) | ||
end | ||
|
||
it 'recognises the Received header when it is not capitalised' do | ||
mail = Mail.new(<<~EOF.strip_heredoc) | ||
From: "FOI Person" <foiperson@localhost> | ||
To: "Bob Smith" <bob@localhost> | ||
Cc: [email protected] | ||
Envelope-To: [email protected] | ||
received: abc id abc from [email protected] | ||
Date: Tue, 13 Nov 2007 11:39:55 +0000 | ||
Bcc: "BCC Person" <bccperson@localhost> | ||
Subject: Test | ||
Reply-To: | ||
Test | ||
EOF | ||
|
||
expect(get_emails_within_received_headers(mail)). | ||
to eq(['[email protected]']) | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -48,12 +48,29 @@ | |
expect(InfoRequest.holding_pen_request.incoming_messages.count).to eq(1) | ||
end | ||
|
||
it "puts messages with the request address in Bcc: in the holding pen" do | ||
request = FactoryBot.create(:info_request) | ||
receive_incoming_mail('bcc-contact-reply.email', | ||
email_to: 'dummy@localhost', | ||
email_bcc: request.incoming_email) | ||
expect(InfoRequest.holding_pen_request.incoming_messages.count).to eq(1) | ||
|
||
it "attaches messages with an info request address in the Received headers to the appropriate request" do | ||
ir = info_requests(:fancy_dog_request) | ||
expect(ir.incoming_messages.count).to eq(1) # in the fixture | ||
mail_content = <<~EOF | ||
From: "FOI Person" <foiperson@localhost> | ||
Received: from smtp-out.localhost | ||
by example.net with esmtps | ||
(Exim 4.89) | ||
(envelope-from <[email protected]>) | ||
id ABC | ||
for #{ir.incoming_email}.com; Mon, 23 Nov 2020 00:00:00 +0000 | ||
Test | ||
EOF | ||
receive_incoming_mail(mail_content) | ||
expect(ir.incoming_messages.count).to eq(2) # one more arrives | ||
expect(ir.info_request_events[-1].incoming_message_id).not_to be_nil | ||
|
||
deliveries = ActionMailer::Base.deliveries | ||
expect(deliveries.size).to eq(1) | ||
mail = deliveries[0] | ||
expect(mail.to).to eq([ 'bob@localhost' ]) # to the user who sent fancy_dog_request | ||
deliveries.clear | ||
end | ||
|
||
it "puts messages with multiple request addresses in Bcc: in the holding pen" do | ||
|