FIX: Inline secure images with duplicated names (#13926)

Inlining secure images with the same name was not possible because they
were indexed by filename. If an email contained two files with the same
name, only the first image was used for both of them. The other file
was still attached to the email.
This commit is contained in:
Bianca Nenciu
2021-08-03 18:58:34 +03:00
committed by GitHub
parent 413de9361f
commit 52520638ca
4 changed files with 27 additions and 15 deletions

View File

@@ -26,7 +26,8 @@ module Email
class Sender
def initialize(message, email_type, user = nil)
@message = message
@message = message
@message_attachments_index = {}
@email_type = email_type
@user = user
end
@@ -240,7 +241,7 @@ module Email
# Embeds any of the secure images that have been attached inline,
# removing the redaction notice.
if SiteSetting.secure_media_allow_embed_images_in_emails
style.inline_secure_images(@message.attachments)
style.inline_secure_images(@message.attachments, @message_attachments_index)
end
@message.html_part.body = style.to_s
@@ -328,6 +329,7 @@ module Email
Discourse.store.download(attached_upload).path
end
@message_attachments_index[original_upload.sha1] = @message.attachments.size
@message.attachments[original_upload.original_filename] = File.read(path)
email_size += File.size(path)
rescue => e

View File

@@ -253,7 +253,7 @@ module Email
@@plugin_callbacks.each { |block| block.call(@fragment, @opts) }
end
def inline_secure_images(attachments)
def inline_secure_images(attachments, attachments_index)
stripped_media = @fragment.css('[data-stripped-secure-media]')
upload_shas = {}
stripped_media.each do |div|
@@ -269,10 +269,8 @@ module Email
upload = uploads.find { |upl| upl.sha1 == upload_shas[div['data-stripped-secure-media']] }
next if !upload
original_filename = upload.original_filename
if attachments[original_filename]
url = attachments[original_filename].url
if attachments[attachments_index[upload.sha1]]
url = attachments[attachments_index[upload.sha1]].url
onebox_type = div['data-onebox-type']
style = if onebox_type