Commit ff555d25 authored by Stan Hu's avatar Stan Hu

Handle nil Content-Type in Service Desk emails

https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28865 changed
attachment handling in reply-by-email and Service Desk issues and
accidentally caused `Content-Type` to be a required field. If no
`Content-Type` message is provided, `Mail::Message` returns `nil`, and
the attachment handler would fail. We now handle this `nil` value
gracefully.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/331658
parent 950cb252
......@@ -40,7 +40,7 @@ module Gitlab
def filter_signature_attachments(message)
attachments = message.attachments
content_type = normalize_mime(message.content_type)
protocol = normalize_mime(message.content_type_parameters[:protocol])
protocol = normalize_mime(message.content_type_parameters&.fetch(:protocol, nil))
if content_type == 'multipart/signed' && protocol
attachments.delete_if { |attachment| protocol == normalize_mime(attachment.content_type) }
......
Return-path: <frank@example.org>
Envelope-to: gitlab+gitlab-instance-administrators-9a72b788-code-hello-world-php-2-issue-@qyber.black
Delivery-date: Sun, 23 May 2021 10:28:57 +0100
Received: from example.plus.com ([212.159.19.195] helo=nut.example.org)
by se.example.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
(Exim 4.93)
(envelope-from <frank@example.org>)
id 1lkkPp-009OFG-9z
for gitlab+gitlab-instance-administrators-9a72b788-code-hello-world-php-2-issue-@qyber.black; Sun, 23 May 2021 10:28:57 +0100
Received: ***REMOVED***
To: <gitlab+gitlab-instance-administrators-9a72b788-code-hello-world-php-2-issue-@qyber.black>
X-Mailer: mail (GNU Mailutils 3.10)
Message-Id: <E1lkkPn-00DuvG-Rf@set>
From: Frank C Example <frank@example.org>
Date: Sun, 23 May 2021 10:28:55 +0100
Subject: Testing Service Desk E-Mail
Test.
......@@ -46,5 +46,15 @@ RSpec.describe Gitlab::Email::AttachmentUploader do
expect(image_link[:url]).to include('gitlab_logo.png')
end
end
context 'with a message with no content type' do
let(:message_raw) { fixture_file("emails/no_content_type.eml") }
it 'uploads all attachments except the signature' do
links = described_class.new(message).execute(upload_parent: project, uploader_class: FileUploader)
expect(links).to eq([])
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