2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

Simple "cook" for email imports from mailing lists

This commit is contained in:
Robin Ward 2015-06-05 11:46:21 -04:00
parent 73646184aa
commit c6cd1928be
5 changed files with 63 additions and 16 deletions

36
lib/email_cook.rb Normal file
View file

@ -0,0 +1,36 @@
# A very simple formatter for imported emails
class EmailCook
def initialize(raw)
@raw = raw
end
def cook
result = ""
in_quote = false
quote_buffer = ""
@raw.each_line do |l|
if l =~ /^\s*>/
in_quote = true
quote_buffer << l.sub(/^[\s>]*/, '') << "<br>"
elsif in_quote
result << "<blockquote>#{quote_buffer}</blockquote>"
quote_buffer = ""
in_quote = false
else
result << l << "<br>"
end
end
if in_quote
result << "<blockquote>#{quote_buffer}</blockquote>"
end
result.gsub!(/(<br>){3,10}/, '<br><br>')
result
end
end