<commit_before># 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_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

        l.scan(regexp).each do |m|
          url = m[0]
          l.gsub!(url, "<a href='#{url}'>#{url}</a>")
        end
        result << l << "<br>"
      end
    end

    if in_quote
      result << "<blockquote>#{quote_buffer}</blockquote>"
    end

    result.gsub!(/(<br>){3,10}/, '<br><br>')
    result
  end

end<commit_msg>FIX: typo<commit_after># 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_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

        l.scan(EmailCook.url_regexp).each do |m|
          url = m[0]
          l.gsub!(url, "<a href='#{url}'>#{url}</a>")
        end
        result << l << "<br>"
      end
    end

    if in_quote
      result << "<blockquote>#{quote_buffer}</blockquote>"
    end

    result.gsub!(/(<br>){3,10}/, '<br><br>')
    result
  end

end
{'fraction_non_alphanumeric': 0.2556701030927835, 'fraction_numerical': 0.010309278350515464, 'mean_word_length': 2.176759410801964, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1409517', 'n_tokens_mistral': 768, 'n_tokens_neox': 750, 'n_words': 142}