From 0e78cd6e3a7c5fa1e700f2719ce497fcf9cc3ebb Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Fri, 24 Jul 2020 13:54:15 +1000 Subject: [PATCH] FIX: Add strip_secure_urls method to GroupSmtpMailer * this mailer needs some more cleanup and specs; this commit just adds the missing method so the mailer does not error completely in secure media environments --- app/mailers/group_smtp_mailer.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/mailers/group_smtp_mailer.rb b/app/mailers/group_smtp_mailer.rb index 15b9051b6e6..01ef9b5b17c 100644 --- a/app/mailers/group_smtp_mailer.rb +++ b/app/mailers/group_smtp_mailer.rb @@ -86,6 +86,19 @@ class GroupSmtpMailer < ActionMailer::Base result end + def strip_secure_urls(raw) + urls = Set.new + raw.scan(URI.regexp(%w{http https})) { urls << $& } + + urls.each do |url| + if (url.start_with?(Discourse.store.s3_upload_host) && FileHelper.is_supported_media?(url)) + raw = raw.sub(url, "

#{I18n.t("emails.secure_media_placeholder")}

") + end + end + + raw + end + def html_override(post, context_posts: nil) UserNotificationRenderer.render( template: 'email/notification',