Merge pull request #2805 from techAPJ/patch-1

Suppress images for short emails
This commit is contained in:
Robin Ward 2014-09-24 15:27:34 -04:00
commit 84cf402482
4 changed files with 24 additions and 1 deletions

View File

@ -934,6 +934,9 @@ en:
disable_emails: "Prevent Discourse from sending any kind of emails"
strip_images_from_short_emails: "Strip images from emails having size less than 2800 Bytes"
short_email_length: "Short email length in Bytes"
pop3_polling_enabled: "Poll via POP3 for email replies."
pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)"
pop3_polling_period_mins: "The period in minutes between checking the POP3 account for email. NOTE: requires restart."

View File

@ -407,6 +407,8 @@ email:
email_prefix: ''
email_site_title: ''
disable_emails: false
strip_images_from_short_emails: true
short_email_length: 2800
files:
max_image_size_kb:
@ -785,4 +787,3 @@ uncategorized:
privacy_topic_id:
default: -1
hidden: true

View File

@ -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

View File

@ -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