mirror of
https://github.com/discourse/discourse.git
synced 2025-05-18 04:13:13 +08:00
Merge pull request #2805 from techAPJ/patch-1
Suppress images for short emails
This commit is contained in:
commit
84cf402482
@ -934,6 +934,9 @@ en:
|
|||||||
|
|
||||||
disable_emails: "Prevent Discourse from sending any kind of emails"
|
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_enabled: "Poll via POP3 for email replies."
|
||||||
pop3_polling_ssl: "Use SSL while connecting to the POP3 server. (Recommended)"
|
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."
|
pop3_polling_period_mins: "The period in minutes between checking the POP3 account for email. NOTE: requires restart."
|
||||||
|
@ -407,6 +407,8 @@ email:
|
|||||||
email_prefix: ''
|
email_prefix: ''
|
||||||
email_site_title: ''
|
email_site_title: ''
|
||||||
disable_emails: false
|
disable_emails: false
|
||||||
|
strip_images_from_short_emails: true
|
||||||
|
short_email_length: 2800
|
||||||
|
|
||||||
files:
|
files:
|
||||||
max_image_size_kb:
|
max_image_size_kb:
|
||||||
@ -785,4 +787,3 @@ uncategorized:
|
|||||||
privacy_topic_id:
|
privacy_topic_id:
|
||||||
default: -1
|
default: -1
|
||||||
hidden: true
|
hidden: true
|
||||||
|
|
||||||
|
@ -94,6 +94,12 @@ module Email
|
|||||||
@message.header['X-Discourse-Post-Id'] = nil
|
@message.header['X-Discourse-Post-Id'] = nil
|
||||||
@message.header['X-Discourse-Reply-Key'] = 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
|
begin
|
||||||
@message.deliver
|
@message.deliver
|
||||||
rescue *SMTP_CLIENT_ERRORS => e
|
rescue *SMTP_CLIENT_ERRORS => e
|
||||||
|
@ -137,6 +137,19 @@ module Email
|
|||||||
end
|
end
|
||||||
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
|
private
|
||||||
|
|
||||||
def replace_relative_urls
|
def replace_relative_urls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user