function filterF(i, el) {
  var pattern = /(From|To|Sent|Subject|Cc|Date):/i;
  return el.textContent.match(pattern);
}

// convert From...To... blocks into one-liners
var matches = $(document).find("*").filter(filterF).get().reverse();

while (matches.length > 0) {
  var parent = $(matches[0]).parent();
  var localMatches = parent.find("*").filter(filterF);

  // insert breakpoint after either the last element of localMatches
  var breakpoint = "breakpoint";
  $(localMatches[localMatches.length-1]).insertAfter("<div id=" + breakpoint + "></div>");
  $(localMatches[0]).nextUntil("#" + breakpoint).each(function(i, el) {
    $(el).remove();
  });
  $(localMatches[0]).remove();
  $("#" + breakpoint).remove();

  matches = $(document).find("*").filter(filterF).get().reverse();
}

// remove blockquotes but preserve contents
$($("blockquote").get().reverse()).each(function(i, el) {
  var contents = $(el).contents();
  contents.insertAfter($(el));
  $(el).remove();
});

@@ -388,15 +388,8 @@
 ter 
-either 
 the 
@@ -423,127 +423,210 @@
 s%0A  
-var breakpoint = %22breakpoint%22;%0A  $(localMatches%5BlocalMatches.length-1%5D).insertAfter(%22%3Cdiv id=%22 + breakpoint + %22%3E%3C/div%3E%22
+$(%22%3Cdiv id=breakpoint%3E%3C/div%3E%22).insertAfter(localMatches%5BlocalMatches.length-1%5D);%0A  var breakpoint = $(%22#breakpoint%22);%0A  // save all text content of the block%0A  var textContent = $(localMatches%5B0%5D).text(
 );%0A 
@@ -655,22 +655,16 @@
 xtUntil(
-%22#%22 + 
 breakpoi
@@ -690,16 +690,49 @@
 , el) %7B%0A
+    textContent += $(el).text();%0A
     $(el
@@ -784,38 +784,345 @@
 ();%0A
+%0A
   
-$(%22#%22 + breakpoint).remove()
+console.log(textContent);%0A  // extract relevant info from the text%0A  var from = textContent.match(/From:(.*)%5Cn/i)%5B1%5D.trim();%0A  var date = textContent.match(/Date:(.*)%5Cn/i)%5B1%5D.trim();%0A  var output = %22%3Cp class='converted'%3EOn %22 + date + %22, %22 + from + %22 wrote:%5Cn%3C/p%3E%22;%0A%0A  $(output).insertAfter(breakpoint);%0A  breakpoint.remove();%0A%0A  break
 ;%0A%0A 

Extract text of the From...To... blocks