diff options
author | Sean McGivern <sean@gitlab.com> | 2017-10-30 13:50:19 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-10-30 13:50:19 +0000 |
commit | eddc9e41a6df94e55f9df91241a83e2ae3439c49 (patch) | |
tree | fe4f01450914bebae4bfaee4191564c090cf5edc | |
parent | 9a58468bee9a28d5762fb9f75e4d457552f943c8 (diff) | |
download | gitlab-ce-eddc9e41a6df94e55f9df91241a83e2ae3439c49.tar.gz |
Only set Auto-Submitted header once39593-emails-on-push-are-sent-to-only-the-first-recipient-when-using-aws-ses
The emails on push feature reuses the same email object, to avoid the expensive
work of generating the email body.
This interceptor would previously set multiple values for the same header, as
that's the mail gem's default behaviour when called with the same header more
than once.
We don't want to change the emails on push service (although it's the only place
where this happens), but fixing the interceptor is just as sensible anyway.
3 files changed, 26 insertions, 6 deletions
diff --git a/changelogs/unreleased/39593-emails-on-push-are-sent-to-only-the-first-recipient-when-using-aws-ses.yml b/changelogs/unreleased/39593-emails-on-push-are-sent-to-only-the-first-recipient-when-using-aws-ses.yml new file mode 100644 index 00000000000..9a7109d054e --- /dev/null +++ b/changelogs/unreleased/39593-emails-on-push-are-sent-to-only-the-first-recipient-when-using-aws-ses.yml @@ -0,0 +1,5 @@ +--- +title: Only set Auto-Submitted header once for emails on push +merge_request: +author: +type: fixed diff --git a/lib/additional_email_headers_interceptor.rb b/lib/additional_email_headers_interceptor.rb index 2358fa6bbfd..3cb1694b9f1 100644 --- a/lib/additional_email_headers_interceptor.rb +++ b/lib/additional_email_headers_interceptor.rb @@ -1,8 +1,6 @@ class AdditionalEmailHeadersInterceptor def self.delivering_email(message) - message.headers( - 'Auto-Submitted' => 'auto-generated', - 'X-Auto-Response-Suppress' => 'All' - ) + message.header['Auto-Submitted'] ||= 'auto-generated' + message.header['X-Auto-Response-Suppress'] ||= 'All' end end diff --git a/spec/lib/additional_email_headers_interceptor_spec.rb b/spec/lib/additional_email_headers_interceptor_spec.rb index 580450eef1e..b5c1a360ba9 100644 --- a/spec/lib/additional_email_headers_interceptor_spec.rb +++ b/spec/lib/additional_email_headers_interceptor_spec.rb @@ -1,12 +1,29 @@ require 'spec_helper' describe AdditionalEmailHeadersInterceptor do - it 'adds Auto-Submitted header' do - mail = ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', body: 'hello').deliver + let(:mail) do + ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', body: 'hello') + end + + before do + mail.deliver_now + end + it 'adds Auto-Submitted header' do expect(mail.header['To'].value).to eq('test@mail.com') expect(mail.header['From'].value).to eq('info@mail.com') expect(mail.header['Auto-Submitted'].value).to eq('auto-generated') expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All') end + + context 'when the same mail object is sent twice' do + before do + mail.deliver_now + end + + it 'does not add the Auto-Submitted header twice' do + expect(mail.header['Auto-Submitted'].value).to eq('auto-generated') + expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All') + end + end end |