diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-09 12:15:13 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-09 12:15:13 +0000 |
commit | 0b4adad74b76b34855e9a6d943f9b9188c3914fa (patch) | |
tree | 1084ffd8336bc8e9af6f7042a093bf78e0852ac3 /app/mailers | |
parent | ece36a21699c2a218b8bd14b22bea47d22218354 (diff) | |
download | gitlab-ce-0b4adad74b76b34855e9a6d943f9b9188c3914fa.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/mailers')
-rw-r--r-- | app/mailers/emails/service_desk.rb | 72 |
1 files changed, 49 insertions, 23 deletions
diff --git a/app/mailers/emails/service_desk.rb b/app/mailers/emails/service_desk.rb index b9d8735494a..c627f4633e4 100644 --- a/app/mailers/emails/service_desk.rb +++ b/app/mailers/emails/service_desk.rb @@ -20,15 +20,24 @@ module Emails sender_name: @service_desk_setting&.outgoing_name, sender_email: service_desk_sender_email_address ) - options = service_desk_options(email_sender, 'thank_you', @issue.external_author) - .merge(subject: "Re: #{subject_base}") - inject_service_desk_custom_email(mail_new_thread(@issue, options)) + options = { + from: email_sender, + to: @issue.external_author, + subject: "Re: #{subject_base}", + **service_desk_template_content_options('thank_you') + } + + mail_new_thread(@issue, options) + inject_service_desk_custom_email end def service_desk_new_note_email(issue_id, note_id, recipient) @note = Note.find(note_id) + setup_service_desk_mail(issue_id) + # Prepare uploads for text replacement in markdown content + setup_service_desk_attachments email_sender = sender( @note.author_id, @@ -36,11 +45,18 @@ module Emails sender_email: service_desk_sender_email_address ) - add_uploads_as_attachments if Feature.enabled?(:service_desk_new_note_email_native_attachments, @note.project) - options = service_desk_options(email_sender, 'new_note', recipient) - .merge(subject: subject_base) + options = { + from: email_sender, + to: recipient, + subject: subject_base, + **service_desk_template_content_options('new_note') + } - inject_service_desk_custom_email(mail_answer_thread(@issue, options)) + mail_answer_thread(@issue, options) + # Add attachments after email init to guide ActiveMailer + # to choose the correct multipart content types + add_uploads_as_attachments + inject_service_desk_custom_email end def service_desk_custom_email_verification_email(service_desk_setting) @@ -64,13 +80,14 @@ module Emails from: email_sender, to: @service_desk_setting.custom_email_address_for_verification, subject: subject, - content_type: "text/plain" + content_type: "text/plain; charset=UTF-8" } # Outgoing emails from GitLab usually have this set to true. # Service Desk email ingestion ignores auto generated emails. headers["Auto-Submitted"] = "no" - inject_service_desk_custom_email(mail_with_locale(options), force: true) + mail_with_locale(options) + inject_service_desk_custom_email(force: true) end def service_desk_verification_triggered_email(service_desk_setting, recipient) @@ -110,19 +127,16 @@ module Emails @sent_notification = SentNotification.record(@issue, @support_bot.id, reply_key) end - def service_desk_options(email_sender, email_type, recipient) - { - from: email_sender, - to: recipient - }.tap do |options| - next unless template_body = template_content(email_type) + def service_desk_template_content_options(email_type) + return {} unless template_body = template_content(email_type) - options[:body] = template_body - options[:content_type] = 'text/html' unless attachments.present? - end + { + body: template_body, + content_type: 'text/html; charset=UTF-8' + } end - def inject_service_desk_custom_email(mail, force: false) + def inject_service_desk_custom_email(force: false) return mail if !service_desk_custom_email_enabled? && !force return mail unless @service_desk_setting.custom_email_credential.present? @@ -184,20 +198,32 @@ module Emails "#{@issue.title} (##{@issue.iid})" end - def add_uploads_as_attachments + def setup_service_desk_attachments + @uploads_to_attach = [] + # Filepaths we should replace in markdown content + @uploads_as_attachments = [] + + return unless Feature.enabled?(:service_desk_new_note_email_native_attachments, @note.project) + uploaders = find_uploaders_for(@note) - return unless uploaders.present? + return if uploaders.nil? return if uploaders.sum(&:size) > EMAIL_ATTACHMENTS_SIZE_LIMIT - @uploads_as_attachments = [] uploaders.each do |uploader| - attachments[uploader.filename] = uploader.read + @uploads_to_attach << { filename: uploader.filename, content: uploader.read } @uploads_as_attachments << "#{uploader.secret}/#{uploader.filename}" rescue StandardError => e Gitlab::ErrorTracking.track_exception(e, project_id: @note.project.id) end end + def add_uploads_as_attachments + # We read the uploads before in setup_service_desk_attachments, so let's just add them + @uploads_to_attach.each do |upload| + mail.add_file(filename: upload[:filename], content: upload[:content]) + end + end + def find_uploaders_for(note) uploads = FileUploader::MARKDOWN_PATTERN.scan(note.note) return unless uploads.present? |