A lot small fixes

This commit is contained in:
RainLoop Team 2015-06-04 22:02:31 +04:00
parent 4457cdbc23
commit 09334159c2
38 changed files with 1496 additions and 239 deletions

View file

@ -126,7 +126,7 @@ class HtmlUtils
{
$aRemoveTags = array(
'link', 'base', 'meta', 'title', 'script', 'bgsound', 'keygen', 'source',
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset', 'video', 'audio'
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset', 'video', 'audio', 'area', 'map'
);
if ($bClearStyleAndHead)
@ -755,7 +755,8 @@ class HtmlUtils
if ('' !== $sTagNameLower && \in_array($sTagNameLower, array('svg', 'head', 'link',
'base', 'meta', 'title', 'style', 'x-script', 'script', 'bgsound', 'keygen', 'source',
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset', 'video', 'audio')))
'object', 'embed', 'applet', 'mocha', 'iframe', 'frame', 'frameset',
'video', 'audio', 'area', 'map')))
{
if (isset($oElement->parentNode))
{
@ -867,7 +868,8 @@ class HtmlUtils
foreach (array(
'id', 'class',
'contenteditable', 'designmode', 'formaction',
'data-bind', 'data-reactid', 'xmlns', 'srcset'
'data-bind', 'data-reactid', 'xmlns', 'srcset',
'data-x-skip-style'
) as $sAttr)
{
@$oElement->removeAttribute($sAttr);
@ -903,27 +905,50 @@ class HtmlUtils
$sAlt = $oElement->hasAttribute('alt')
? \trim($oElement->getAttribute('alt')) : '';
$sH = $oElement->hasAttribute('height')
? \trim($oElement->getAttribute('height')) : '';
$sW = $oElement->hasAttribute('width')
? \trim($oElement->getAttribute('width')) : '';
$sStyles = $oElement->hasAttribute('style')
? \trim(\trim(\trim($oElement->getAttribute('style')), ';')) : '';
if ($oElement->hasAttribute('src'))
if ($oElement->hasAttribute('src') && '' === $sAlt)
{
$aValues = array('4', '3', '2', '1', '0', '4px', '3px', '2px', '1px', '0px');
if (('' === $sAlt && \in_array($sH, $aValues) && \in_array($sW, $aValues)) ||
\preg_match('/(display:none|visibility:hidden)/i', \preg_replace('/[\s]+/', '', $sStyles)))
$aH = array(
'email.microsoftemail.com/open',
'github.com/notifications/beacon/',
'mandrillapp.com/track/open',
'list-manage.com/track/open'
);
$sH = $oElement->hasAttribute('height')
? \trim($oElement->getAttribute('height')) : '';
// $sW = $oElement->hasAttribute('width')
// ? \trim($oElement->getAttribute('width')) : '';
$sStyles = $oElement->hasAttribute('style')
? \preg_replace('/[\s]+/', '', \trim(\trim(\trim($oElement->getAttribute('style')), ';'))) : '';
$sSrc = \trim($oElement->getAttribute('src'));
$bC = \in_array($sH, array('1', '0', '1px', '0px')) ||
\preg_match('/(display:none|visibility:hidden|height:0|height:[01][a-z][a-z])/i', $sStyles);
if (!$bC)
{
if (isset($oElement->parentNode))
$sSrcLower = \strtolower($sSrc);
foreach ($aH as $sLine)
{
@$oElement->parentNode->removeChild($oElement);
continue;
if (false !== \strpos($sSrcLower, $sLine))
{
$bC = true;
break;
}
}
}
if ($bC)
{
$oElement->setAttribute('style', 'display:none');
$oElement->setAttribute('data-x-skip-style', 'true');
$oElement->setAttribute('data-x-hidden-src', $sSrc);
$oElement->removeAttribute('src');
}
}
}
@ -1002,12 +1027,14 @@ class HtmlUtils
$oElement->setAttribute('style', (empty($sStyles) ? '' : $sStyles.'; ').\implode('; ', $aStyles));
}
if ($oElement->hasAttribute('style'))
if ($oElement->hasAttribute('style') && !$oElement->hasAttribute('data-x-skip-style'))
{
$oElement->setAttribute('style',
\MailSo\Base\HtmlUtils::ClearStyle($oElement->getAttribute('style'), $oElement, $bHasExternals,
$aFoundCIDs, $aContentLocationUrls, $aFoundedContentLocationUrls, $bDoNotReplaceExternalUrl, $fAdditionalExternalFilter));
}
$oElement->removeAttribute('data-x-skip-style');
}
$sResult = $oDom->saveHTML();
@ -1023,7 +1050,7 @@ class HtmlUtils
$sResult = '<div data-x-div-type="html" '.$sHtmlAttrs.'>'.$sResult.'</div>';
$sResult = \str_replace(\MailSo\Base\HtmlUtils::$KOS, ':', $sResult);
$sResult = \preg_replace('/[\s]+/u', ' ', $sResult);
$sResult = \MailSo\Base\Utils::StripSpaces($sResult);
return \trim($sResult);
}
@ -1275,103 +1302,104 @@ class HtmlUtils
*/
public static function ConvertHtmlToPlain($sText)
{
$sText = trim(stripslashes($sText));
$sText = preg_replace('/[\s]+/', ' ', $sText);
$sText = preg_replace(array(
"/\r/",
"/[\n\t]+/",
'/<script[^>]*>.*?<\/script>/i',
'/<style[^>]*>.*?<\/style>/i',
'/<title[^>]*>.*?<\/title>/i',
'/<h[123][^>]*>(.+?)<\/h[123]>/i',
'/<h[456][^>]*>(.+?)<\/h[456]>/i',
'/<p[^>]*>/i',
'/<br[^>]*>/i',
'/<b[^>]*>(.+?)<\/b>/i',
'/<i[^>]*>(.+?)<\/i>/i',
'/(<ul[^>]*>|<\/ul>)/i',
'/(<ol[^>]*>|<\/ol>)/i',
'/<li[^>]*>/i',
'/<a[^>]*href="([^"]+)"[^>]*>(.+?)<\/a>/i',
'/<hr[^>]*>/i',
'/(<table[^>]*>|<\/table>)/i',
'/(<tr[^>]*>|<\/tr>)/i',
'/<td[^>]*>(.+?)<\/td>/i',
'/<th[^>]*>(.+?)<\/th>/i',
'/&nbsp;/i',
'/&quot;/i',
'/&gt;/i',
'/&lt;/i',
'/&amp;/i',
'/&copy;/i',
'/&trade;/i',
'/&#8220;/',
'/&#8221;/',
'/&#8211;/',
'/&#8217;/',
'/&#38;/',
'/&#169;/',
'/&#8482;/',
'/&#151;/',
'/&#147;/',
'/&#148;/',
'/&#149;/',
'/&reg;/i',
'/&bull;/i',
'/&[&;]+;/i',
'/&#39;/',
'/&#160;/'
), array(
'',
' ',
'',
'',
'',
"\n\n\\1\n\n",
"\n\n\\1\n\n",
"\n\n\t",
"\n",
'\\1',
'\\1',
"\n\n",
"\n\n",
"\n\t* ",
'\\2 (\\1)',
"\n------------------------------------\n",
"\n",
"\n",
"\t\\1\n",
"\t\\1\n",
' ',
'"',
'>',
'<',
'&',
'(c)',
'(tm)',
'"',
'"',
'-',
"'",
'&',
'(c)',
'(tm)',
'--',
'"',
'"',
'*',
'(R)',
'*',
'',
'\'',
''
), $sText);
$sText = \trim(\stripslashes($sText));
$sText = \MailSo\Base\Utils::StripSpaces($sText);
$sText = str_ireplace('<div>',"\n<div>", $sText);
$sText = strip_tags($sText, '');
$sText = preg_replace("/\n\\s+\n/", "\n", $sText);
$sText = preg_replace("/[\n]{3,}/", "\n\n", $sText);
$sText = \preg_replace(array(
"/\r/",
"/[\n\t]+/",
'/<script[^>]*>.*?<\/script>/i',
'/<style[^>]*>.*?<\/style>/i',
'/<title[^>]*>.*?<\/title>/i',
'/<h[123][^>]*>(.+?)<\/h[123]>/i',
'/<h[456][^>]*>(.+?)<\/h[456]>/i',
'/<p[^>]*>/i',
'/<br[^>]*>/i',
'/<b[^>]*>(.+?)<\/b>/i',
'/<i[^>]*>(.+?)<\/i>/i',
'/(<ul[^>]*>|<\/ul>)/i',
'/(<ol[^>]*>|<\/ol>)/i',
'/<li[^>]*>/i',
'/<a[^>]*href="([^"]+)"[^>]*>(.+?)<\/a>/i',
'/<hr[^>]*>/i',
'/(<table[^>]*>|<\/table>)/i',
'/(<tr[^>]*>|<\/tr>)/i',
'/<td[^>]*>(.+?)<\/td>/i',
'/<th[^>]*>(.+?)<\/th>/i',
'/&nbsp;/i',
'/&quot;/i',
'/&gt;/i',
'/&lt;/i',
'/&amp;/i',
'/&copy;/i',
'/&trade;/i',
'/&#8220;/',
'/&#8221;/',
'/&#8211;/',
'/&#8217;/',
'/&#38;/',
'/&#169;/',
'/&#8482;/',
'/&#151;/',
'/&#147;/',
'/&#148;/',
'/&#149;/',
'/&reg;/i',
'/&bull;/i',
'/&[&;]+;/i',
'/&#39;/',
'/&#160;/'
), array(
'',
' ',
'',
'',
'',
"\n\n\\1\n\n",
"\n\n\\1\n\n",
"\n\n\t",
"\n",
'\\1',
'\\1',
"\n\n",
"\n\n",
"\n\t* ",
'\\2 (\\1)',
"\n------------------------------------\n",
"\n",
"\n",
"\t\\1\n",
"\t\\1\n",
' ',
'"',
'>',
'<',
'&',
'(c)',
'(tm)',
'"',
'"',
'-',
"'",
'&',
'(c)',
'(tm)',
'--',
'"',
'"',
'*',
'(R)',
'*',
'',
'\'',
''
), $sText);
return trim($sText);
$sText = \str_ireplace('<div>',"\n<div>", $sText);
$sText = \strip_tags($sText, '');
$sText = \preg_replace("/\n\\s+\n/", "\n", $sText);
$sText = \preg_replace("/[\n]{3,}/", "\n\n", $sText);
return \trim($sText);
}
}

View file

@ -550,6 +550,17 @@ END;
return \MailSo\Base\Utils::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
}
/**
* @param string $sValue
*
* @return string
*/
public static function StripSpaces($sValue)
{
return \MailSo\Base\Utils::Trim(
\preg_replace('/[\s]+/u', ' ', $sValue));
}
/**
* @param string $sValue
*
@ -557,7 +568,7 @@ END;
*/
public static function IsUtf8($sValue)
{
return (bool) ( \function_exists('mb_check_encoding') ?
return (bool) (\function_exists('mb_check_encoding') ?
\mb_check_encoding($sValue, 'UTF-8') : \preg_match('//u', $sValue));
}
@ -1362,8 +1373,9 @@ END;
*/
public static function ClearFileName($sFileName)
{
return \MailSo\Base\Utils::ClearNullBite(\preg_replace('/[\s]+/u', ' ',
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sFileName)));
return \MailSo\Base\Utils::Trim(\MailSo\Base\Utils::ClearNullBite(
\MailSo\Base\Utils::StripSpaces(
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sFileName))));
}
/**
@ -1373,8 +1385,8 @@ END;
*/
public static function ClearXss($sValue)
{
return \MailSo\Base\Utils::ClearNullBite(
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue));
return \MailSo\Base\Utils::Trim(\MailSo\Base\Utils::ClearNullBite(
\str_replace(array('"', '/', '\\', '*', '?', '<', '>', '|', ':'), ' ', $sValue)));
}
/**

View file

@ -56,6 +56,11 @@ class Config
*/
public static $LargeThreadLimit = 50;
/**
* @var bool
*/
public static $MessageAllHeaders = false;
/**
* @var bool
*/

View file

@ -267,7 +267,7 @@ abstract class Driver
foreach ($mDesc as &$sLine)
{
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$sLine = \rtrim($mDesc);
$sLine = \rtrim($sLine);
}
}
else

View file

@ -179,33 +179,41 @@ class MailClient
*/
private function getEnvelopeOrHeadersRequestString()
{
return \MailSo\Imap\Enumerations\FetchType::BODY_HEADER_PEEK;
if (\MailSo\Config::$MessageAllHeaders)
{
return \MailSo\Imap\Enumerations\FetchType::BODY_HEADER_PEEK;
}
// return \MailSo\Imap\Enumerations\FetchType::ENVELOPE;
return \MailSo\Imap\Enumerations\FetchType::BuildBodyCustomHeaderRequest(array(
\MailSo\Mime\Enumerations\Header::RETURN_PATH,
\MailSo\Mime\Enumerations\Header::RECEIVED,
\MailSo\Mime\Enumerations\Header::MIME_VERSION,
\MailSo\Mime\Enumerations\Header::MESSAGE_ID,
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Header::FROM_,
\MailSo\Mime\Enumerations\Header::TO_,
\MailSo\Mime\Enumerations\Header::CC,
\MailSo\Mime\Enumerations\Header::BCC,
\MailSo\Mime\Enumerations\Header::SENDER,
\MailSo\Mime\Enumerations\Header::REPLY_TO,
\MailSo\Mime\Enumerations\Header::DELIVERED_TO,
\MailSo\Mime\Enumerations\Header::IN_REPLY_TO,
\MailSo\Mime\Enumerations\Header::REFERENCES,
\MailSo\Mime\Enumerations\Header::DATE,
\MailSo\Mime\Enumerations\Header::SUBJECT,
\MailSo\Mime\Enumerations\Header::SENSITIVITY,
\MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY,
\MailSo\Mime\Enumerations\Header::IMPORTANCE,
\MailSo\Mime\Enumerations\Header::X_PRIORITY,
\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO,
\MailSo\Mime\Enumerations\Header::RETURN_RECEIPT_TO,
\MailSo\Mime\Enumerations\Header::DISPOSITION_NOTIFICATION_TO,
\MailSo\Mime\Enumerations\Header::X_CONFIRM_READING_TO,
\MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS,
\MailSo\Mime\Enumerations\Header::X_DKIM_AUTHENTICATION_RESULTS,
), true);
//
// return \MailSo\Imap\Enumerations\FetchType::BuildBodyCustomHeaderRequest(array(
// \MailSo\Mime\Enumerations\Header::RETURN_PATH,
// \MailSo\Mime\Enumerations\Header::RECEIVED,
// \MailSo\Mime\Enumerations\Header::MIME_VERSION,
// \MailSo\Mime\Enumerations\Header::MESSAGE_ID,
// \MailSo\Mime\Enumerations\Header::FROM_,
// \MailSo\Mime\Enumerations\Header::TO_,
// \MailSo\Mime\Enumerations\Header::CC,
// \MailSo\Mime\Enumerations\Header::BCC,
// \MailSo\Mime\Enumerations\Header::SENDER,
// \MailSo\Mime\Enumerations\Header::REPLY_TO,
// \MailSo\Mime\Enumerations\Header::IN_REPLY_TO,
// \MailSo\Mime\Enumerations\Header::DATE,
// \MailSo\Mime\Enumerations\Header::SUBJECT,
// \MailSo\Mime\Enumerations\Header::X_MSMAIL_PRIORITY,
// \MailSo\Mime\Enumerations\Header::IMPORTANCE,
// \MailSo\Mime\Enumerations\Header::X_PRIORITY,
// \MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
// \MailSo\Mime\Enumerations\Header::REFERENCES,
// \MailSo\Mime\Enumerations\Header::X_DRAFT_INFO,
// \MailSo\Mime\Enumerations\Header::RECEIVED_SPF,
// \MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS,
// ), true);
// return \MailSo\Imap\Enumerations\FetchType::ENVELOPE;
}
/**
@ -1032,7 +1040,7 @@ class MailClient
$sReg = 'e?mail|from|to|subject|has|is|date|text|body|size|larger|bigger|smaller|maxsize|minsize';
$sSearch = \trim(\preg_replace('/[\s]+/', ' ', $sSearch));
$sSearch = \MailSo\Base\Utils::StripSpaces($sSearch);
$sSearch = \trim(\preg_replace('/('.$sReg.'): /i', '\\1:', $sSearch));
$mMatch = array();
@ -1079,7 +1087,7 @@ class MailClient
$sSearch = \str_replace($sToken, '', $sSearch);
}
$sSearch = \trim(\preg_replace('/[\s]+/', ' ', $sSearch));
$sSearch = \MailSo\Base\Utils::StripSpaces($sSearch);
}
foreach ($mMatch[1] as $iIndex => $sName)
@ -1353,7 +1361,7 @@ class MailClient
if ('' !== \trim($sMainText))
{
$sMainText = \trim(\trim(preg_replace('/[\s]+/', ' ', $sMainText)), '"');
$sMainText = \trim(\MailSo\Base\Utils::StripSpaces($sMainText), '"');
if ($bIsGmail)
{
$sGmailRawSearch .= ' '.$sMainText;
@ -1690,7 +1698,8 @@ class MailClient
\MailSo\Imap\Enumerations\FetchType::INTERNALDATE,
\MailSo\Imap\Enumerations\FetchType::FLAGS,
\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE,
$bSimple ? $this->getEnvelopeOrHeadersRequestStringForSimpleList() :
$bSimple ?
$this->getEnvelopeOrHeadersRequestStringForSimpleList() :
$this->getEnvelopeOrHeadersRequestString()
), \MailSo\Base\Utils::PrepearFetchSequence($aRequestIndexOrUids), $bIndexAsUid);

View file

@ -620,9 +620,9 @@ class Message
$this->oDeliveredTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::DELIVERED_TO, $bCharsetAutoDetect);
$this->sInReplyTo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::IN_REPLY_TO);
$this->sReferences = \trim(\preg_replace('/[\s]+/', ' ',
$oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES)));
$this->sReferences = \MailSo\Base\Utils::StripSpaces(
$oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::REFERENCES));
$sHeaderDate = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::DATE);
$this->sHeaderDate = $sHeaderDate;
$this->iHeaderTimeStampInUTC = \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sHeaderDate);

View file

@ -257,7 +257,7 @@ class Message
public function SetReferences($sReferences)
{
$this->aHeadersValue[\MailSo\Mime\Enumerations\Header::REFERENCES] =
\trim(\preg_replace('/[\s]+/', ' ', $sReferences));
\MailSo\Base\Utils::StripSpaces($sReferences);
return $this;
}