Wrong Content-Type of Service Desk `new_note` email body when using a template and having an attachment
Summary
When a custom .gitlab/service_desk_templates/new_note.md
markdown template is provided, mails generated by replying to a service desk issue with an attachment will contain the rendered partial html of the markdown template in a text/plain
section of the multipart mail, instead of a properly formatted text/html
part. Without an attachment the content-type is correctly set to text/html
and without custom templates an HTML and plain text version are sent using the default templates (see service_desk_new_note_email.text.erb, service_desk_new_note_email.html.haml).
Steps to reproduce
- Enable Service Desk for a Repository
- Create
.gitlab/service_desk_templates/new_note.md
with some markdown content - Open an issue via the service desk mail
- Create a Response in GitLab containing a file or inline image.
Example Project
https://gitlab.com/ech0_de/service_desk_attachment_bug/-/issues/1
What is the current bug behavior?
The resulting new_note mail is composed as a multipart mail, with the first part containing html output with a text/plain
content type.
What is the expected correct behavior?
The resulting email should use a text/html
content type and the content should be embedded within an html shell (i.e., <html><body>
tags).
Relevant logs and/or screenshots
Excerpt from the mail sent by GitLab.
----==_mimepart_642e75c63848e_2a56af41501b1
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<h1 dir="auto">
<a id="user-content-this-is-a-custom-new_note-template" class="anchor" href="#this-is-a-custom-new_note-template" aria-hidden="true"></a>this is a custom new_note template</h1>
<ul dir="auto">
<li>
#1: issue IID</li>
<li>
ech0_de/service_desk_attachment_bug#1: project path appended with the issue IID</li>
<li>Here is a response with an attachment:
<strong>dummy.pdf</strong>: note text</li>
<li>
<a href="https://gitlab.com/-/sent_notifications/REDACTED/unsubscribe">https://gitlab.com/-/sent_notifications/REDACTED/unsubscribe</a>: unsubscribe URL</li>
<li>: system header message</li>
<li>: system footer message</li>
<li>: custom additional text</li>
</ul>
----==_mimepart_642e75c63848e_2a56af41501b1
Content-Type: application/pdf;
filename=dummy.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=dummy.pdf
JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0Zp
[...]
Output of checks
This bug happens on GitLab.com
Results of GitLab environment info
n/a
Results of GitLab application Check
n/a
Possible fixes
Without attachments the text/html
mimetype is set in service_desk.rb#L79. I was not able to find where the text/plain
content type is set, but I think Rails' ActionMailer defaults to text/plain
when not using a rails template.