mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Add setting to strip whitespaces from incoming emails. (#7375)
Some email clients add leading whitespaces which get are transformed in code blocks when processed.
This commit is contained in:
@@ -353,11 +353,32 @@ module Email
|
||||
end
|
||||
end
|
||||
|
||||
text_format = Receiver::formats[:plaintext]
|
||||
if text.blank? || (SiteSetting.incoming_email_prefer_html && markdown.present?)
|
||||
return [markdown, elided_markdown, Receiver::formats[:markdown]]
|
||||
else
|
||||
return [text, elided_text, Receiver::formats[:plaintext]]
|
||||
text, elided_text, text_format = markdown, elided_markdown, Receiver::formats[:markdown]
|
||||
end
|
||||
|
||||
if SiteSetting.strip_incoming_email_lines
|
||||
in_code = nil
|
||||
|
||||
text = text.lines.map! do |line|
|
||||
stripped = line.strip << "\n"
|
||||
|
||||
if !in_code && stripped[0..2] == '```'
|
||||
in_code = '```'
|
||||
elsif in_code == '```' && stripped[0..2] == '```'
|
||||
in_code = nil
|
||||
elsif !in_code && stripped[0..4] == '[code'
|
||||
in_code = '[code]'
|
||||
elsif in_code == '[code]' && stripped[0..6] == '[/code]'
|
||||
in_code = nil
|
||||
end
|
||||
|
||||
in_code ? line : stripped
|
||||
end.join
|
||||
end
|
||||
|
||||
[text, elided_text, text_format]
|
||||
end
|
||||
|
||||
def to_markdown(html, elided_html)
|
||||
|
||||
Reference in New Issue
Block a user