לקח לי המון המון זמן למצוא לזה פיתרון
אתה כותב בPHP? יש לי פונקציה מוכנה.
function traitBody($body, $nolinks = true)
{
$body = html_entity_decode($body);
$body = quoted_printable_decode($body);
$no_quote = cutFrom($body, '<div class="gmail_quote"');
$body = strip_tags($no_quote) ? $no_quote : $body;
$no_signature = cutFrom($body, 'class="gmail_signature"');
$body = strip_tags($no_signature) ? $no_signature : $body;
$no_default = cutFrom($body, '<(?:span|div) class="gmail_default"');
$body = strip_tags($no_default) ? $no_default : $body;
$body = cutFrom($body, '-- <br />');
$body = cutFrom($body, '______________________________________');
$body = cutFrom($body, '<div id="composer_signature"');
$body = cutFrom($body, '<div id="mt-signature"');
$body = cutFrom($body, '<div class="gmail_extra"');
$body = cutFrom($body, '<div class="gmail_chip');
$body = cutFrom($body, '<!-- Email Footer : BEGIN -->');
$body = cutFrom($body, 'Content-Type: application');
$body = cutFrom($body, "Message d'origine");
$body = cutFrom($body, "This is a multipart message");
$body = cutFrom($body, "From:");
$body = cutFrom($body, "Encoding: quoted-printable", true);
$body = cutFrom($body, "Content-transfer-encoding:8bit", true);
$body = cutFrom($body, "Content-Transfer-Encoding: 8bit", true);
$body = cutFrom($body, "נשלח באמצעות מערכת");
$body = cutFrom($body, "Sent with");
$body = pregReplace($body, '<img.*>', ' ');
$body = pregReplace($body, '<br/?>', ' ');
$body = pregReplace($body, '<div', ' <div');
$body = pregReplace($body, '<span', ' <span');
$body = pregReplace($body, '\r|\n', ' ');
if ($nolinks) {
$body = pregReplace($body, '<a [^>]>http.*</a>', ' link ', 'U');
$body = pregReplace($body, '>[^<]*@[^>]*<', ' mail ');
$body = pregReplace($body, '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+', ' mail ');
}
$body = pregReplace($body, '<style.*/style>');
$body = pregReplace($body, '<script.*/script>');
$body = strip_tags($body);
$body = htmlspecialchars_decode($body, ENT_QUOTES);
$body = pregReplace($body, '<|>');
if ($nolinks) {
$body = pregReplace($body, '((\w+:\/\/\S+)|(\w+[\.:]\w+\S+))[^\s,\.]', ' link ', '');
}
return $body;
}
function pregExtract($string, $pattern)
{
return preg_match('#' . str_replace('~', '(.*)', $pattern) . '#is', $string, $match) ? $match[1] : '';
}
function pregReplace($string, $pattern, $subject = '', $options = 'U')
{
if (is_array($pattern))
$pattern = implode('|', $pattern);
$pattern = '#' . $pattern . '#is' . $options;
return preg_replace($pattern, $subject, $string);
}
function cutFrom($from, $string, $end = false)
{
$pos = strpos($from, $string);
if ($end)
$return = $pos ? substr($from, $pos + strlen($string)) : $from;
else
$return = $pos ? substr($from, 0, $pos) : $from;
return $return;
}
מקווה שיעזור לך