# A very simple formatter for imported emails class EmailCook def self.url_regexp /^((?:https?:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.])(?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/ end def initialize(raw) @raw = raw end def cook result = "" in_text = false in_quote = false quote_buffer = "" @raw.each_line do |l| if l =~ /^\s*>/ in_quote = true quote_buffer << l.sub(/^[\s>]*/, '') << "
" elsif in_quote result << "
#{quote_buffer}
" quote_buffer = "" in_quote = false else sz = l.size l.scan(EmailCook.url_regexp).each do |m| url = m[0] l.gsub!(url, "#{url}") end result << l if sz < 60 result << "
" if in_text result << "
" end in_text = false else in_text = true end end end if in_quote result << "
#{quote_buffer}
" end result.gsub!(/(
\n*){3,10}/, '

') result end end