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
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
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
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