Commit 60b5f228 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Strip out email body when rejecting email

This prevents pushing large payloads to Redis for the Sidekiq job
arguments
parent 11da5cd8
......@@ -118,7 +118,9 @@ class EmailReceiverWorker # rubocop:disable Scalability/IdempotentWorker
end
if reason
EmailRejectionMailer.rejection(reason, raw, can_retry).deliver_later
receiver.mail.body = nil
EmailRejectionMailer.rejection(reason, receiver.mail.encoded, can_retry).deliver_later
end
end
end
......@@ -44,6 +44,10 @@ module Gitlab
}
end
def mail
strong_memoize(:mail) { build_mail }
end
private
def handler
......@@ -54,10 +58,6 @@ module Gitlab
Handler.for(mail, mail_key)
end
def mail
strong_memoize(:mail) { build_mail }
end
def build_mail
Mail::Message.new(@raw)
rescue Encoding::UndefinedConversionError,
......
......@@ -37,6 +37,15 @@ RSpec.describe EmailReceiverWorker, :mailer do
expect(email.to).to eq(["jake@adventuretime.ooo"])
expect(email.subject).to include("Rejected")
end
it 'strips out the body before passing to EmailRejectionMailer' do
mail = Mail.new(raw_message)
mail.body = nil
expect(EmailRejectionMailer).to receive(:rejection).with(anything, mail.encoded, anything).and_call_original
described_class.new.perform(raw_message)
end
end
context 'when the error is Gitlab::Email::AutoGeneratedEmailError' do
......
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