mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
Suppress images for short emails
This commit is contained in:
@ -94,6 +94,12 @@ module Email
|
||||
@message.header['X-Discourse-Post-Id'] = nil
|
||||
@message.header['X-Discourse-Reply-Key'] = nil
|
||||
|
||||
# Suppress images from short emails
|
||||
if SiteSetting.strip_images_from_short_emails && @message.html_part.body.to_s.bytesize <= SiteSetting.short_email_length && @message.html_part.body =~ /<img[^>]+>/
|
||||
style = Email::Styles.new(@message.html_part.body.to_s)
|
||||
@message.html_part.body = style.strip_avatars_and_emojis
|
||||
end
|
||||
|
||||
begin
|
||||
@message.deliver
|
||||
rescue *SMTP_CLIENT_ERRORS => e
|
||||
|
@ -137,6 +137,19 @@ module Email
|
||||
end
|
||||
end
|
||||
|
||||
def strip_avatars_and_emojis
|
||||
@fragment.css('img').each do |img|
|
||||
if img['src'] =~ /user_avatar/
|
||||
img.remove
|
||||
end
|
||||
|
||||
if img['src'] =~ /plugins\/emoji/
|
||||
img.replace img['title']
|
||||
end
|
||||
end
|
||||
return @fragment.to_s
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def replace_relative_urls
|
||||
|
Reference in New Issue
Block a user