lib/email_reply_parser.rb
# normalize text so it is easier to parse
#
# text - text to normalize
#
# Returns a String
normalize text so it is easier to parse
text - text to normalize

Returns a String
normalize text so it is easier to parse text - text to normalize Returns a String
def normalize_text(text)
      text = text.dup.force_encoding('binary') if text.respond_to?(:force_encoding)
      text.gsub!("\r\n", "\n")
      if match = text.match(/^(On\s(.+)wrote:)$/m)
        text.gsub! match[1], match[1].gsub("\n", " ") unless match[1] =~ /\n\n/
      end
      text.gsub!(/([^\n])(?=\n_{7}_+)$/m, "\\1\n")
      text.gsub!(/([^\n])(?=\n-+)$/m, "\\1\n")
      text
    end
def normalize_text ( text ) text = text . dup . force_encoding ( 'binary' ) if text . respond_to? ( :force_encoding ) text . gsub! ( "\r\n" , "\n" ) if match = text . match ( / ^(On \s (.+)wrote:)$ /m ) text . gsub! match [ 1 ] , match [ 1 ] . gsub ( "\n" , " " ) unless match [ 1 ] =~ / \n \n / end text . gsub! ( / ([^ \n ])(?= \n _{7}_+)$ /m , "\\1\n" ) text . gsub! ( / ([^ \n ])(?= \n -+)$ /m , "\\1\n" ) text end
normalize text so it is easier to parse
text - text to normalize
normalize text so it is easier to parse text - text to normalize
# in 1.9 we want to operate on the raw bytes # Normalize line endings. # Check for multi-line reply headers. Some clients break up # the "On DATE, NAME <EMAIL> wrote:" line into multiple lines. # Remove all new lines from the reply header. as long as we don't have any double newline # if we do they we have grabbed something that is not actually a reply header # Some users may reply directly above a line of underscores or dashes. # In order to ensure that these fragments are split correctly, # make sure that all lines of underscores are preceded by # at least two newline characters.
text
<not_specific>