Commit eddc9e41 authored by Sean McGivern's avatar Sean McGivern

Only set Auto-Submitted header once

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.
parent 9a58468b
---
title: Only set Auto-Submitted header once for emails on push
merge_request:
author:
type: fixed
class AdditionalEmailHeadersInterceptor class AdditionalEmailHeadersInterceptor
def self.delivering_email(message) def self.delivering_email(message)
message.headers( message.header['Auto-Submitted'] ||= 'auto-generated'
'Auto-Submitted' => 'auto-generated', message.header['X-Auto-Response-Suppress'] ||= 'All'
'X-Auto-Response-Suppress' => 'All'
)
end end
end end
require 'spec_helper' require 'spec_helper'
describe AdditionalEmailHeadersInterceptor do describe AdditionalEmailHeadersInterceptor do
it 'adds Auto-Submitted header' do let(:mail) do
mail = ActionMailer::Base.mail(to: 'test@mail.com', from: 'info@mail.com', body: 'hello').deliver 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['To'].value).to eq('test@mail.com')
expect(mail.header['From'].value).to eq('info@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['Auto-Submitted'].value).to eq('auto-generated')
expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All') expect(mail.header['X-Auto-Response-Suppress'].value).to eq('All')
end 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 end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment