Re: Mail conversation parser?
| From: | Turadg Aleahmad | Date: | Thu, 23 Sep 2004 23:19:08 +0000 |
| Subject: | Re: Mail conversation parser? | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-33524@lists.php.net to get a copy of this message | ||
Alan Knowles wrote:
Sounds interesting - you probably need to look at JWZ's notes on email threading to do this..Thanks, though I'm not looking to write a thread detection algorithm. We have a custom identifier for our forum threads and we don't use Reply-To. I was talking about a class for "parsing out the novel content of an e-mail reply à la Gmail". Gmail has a feature that hides the text quoted in replies since the original message is there on the same screen. The following code is my current algorithm for filtering out the quoted portion of the reply. I was thinking it may be useful to others and I thought that it could be expanded to handle the myriad ways different mail programs quote the previous message. So far I'm only certain the code below works with Thunderbird (and only with plain/text parts). Is this worthy of a PEAR package? What name? Mail_Reply, Text_Mail, ?? function isQuotedLine($line) {
return preg_match("/^>+/", $line);
}
function isAttributionLine($line) {
return strstr("wrote:", $line);
}
/**
* @param array bodyLines is an array of lines in a message
*/
function filterQuotedReply ($bodyLines) {
$keep = array();
// search from bottom until we hit novel content
for ($i = count($bodyLines); $i > 0; $i -=1) {
if (isQuotedLine($bodyLines[$i])) continue;
if (empty($bodyLines[$i])) continue;
if (isAttributionLine($bodyLines[$i])) continue;
$contentEnd = $i - 1;
break;
}
$buffer = "";
for ($i = 0; $i < $contentEnd; $i += 1)
$buffer .= $bodyLines[$i];
return $buffer;
}
-Turadg