Drop html messages table width attribute to prevent side scrolling

This commit is contained in:
djmaze 2022-01-05 13:10:44 +01:00
parent 66c4c39fea
commit 476fe63999

View file

@ -399,8 +399,7 @@ abstract class HtmlUtils
{ {
$sResult = ''; $sResult = '';
$sHtml = null === $sHtml ? '' : (string) $sHtml; $sHtml = null === $sHtml ? '' : \trim($sHtml);
$sHtml = \trim($sHtml);
if (!\strlen($sHtml)) if (!\strlen($sHtml))
{ {
return ''; return '';
@ -429,7 +428,7 @@ abstract class HtmlUtils
$aNodes = $oDom->getElementsByTagName('*'); $aNodes = $oDom->getElementsByTagName('*');
foreach ($aNodes as /* @var $oElement \DOMElement */ $oElement) foreach ($aNodes as /* @var $oElement \DOMElement */ $oElement)
{ {
$aRemovedAttrs = array(); $aAttrsForRemove = array();
$sTagNameLower = \strtolower($oElement->tagName); $sTagNameLower = \strtolower($oElement->tagName);
$sStyles = $oElement->hasAttribute('style') ? \trim($oElement->getAttribute('style'), " \n\r\t\v\0;") : ''; $sStyles = $oElement->hasAttribute('style') ? \trim($oElement->getAttribute('style'), " \n\r\t\v\0;") : '';
@ -512,13 +511,18 @@ abstract class HtmlUtils
$sStyles .= '; color: '.$sLinkColor; $sStyles .= '; color: '.$sLinkColor;
} }
else if ('table' === $sTagNameLower && $oElement->hasAttribute('width'))
{
@$oElement->removeAttribute('width');
$aAttrsForRemove['width'] = true;
}
if ($oElement->hasAttributes() && isset($oElement->attributes) && $oElement->attributes) if ($oElement->hasAttributes() && isset($oElement->attributes) && $oElement->attributes)
{ {
$aHtmlAllowedAttributes = isset(\MailSo\Config::$HtmlStrictAllowedAttributes) && $aHtmlAllowedAttributes = isset(\MailSo\Config::$HtmlStrictAllowedAttributes) &&
\is_array(\MailSo\Config::$HtmlStrictAllowedAttributes) && \count(\MailSo\Config::$HtmlStrictAllowedAttributes) ? \is_array(\MailSo\Config::$HtmlStrictAllowedAttributes) && \count(\MailSo\Config::$HtmlStrictAllowedAttributes) ?
\MailSo\Config::$HtmlStrictAllowedAttributes : null; \MailSo\Config::$HtmlStrictAllowedAttributes : null;
$sAttrsForRemove = array();
foreach ($oElement->attributes as $sAttrName => $oAttr) foreach ($oElement->attributes as $sAttrName => $oAttr)
{ {
if ($sAttrName && $oAttr) if ($sAttrName && $oAttr)
@ -534,21 +538,10 @@ abstract class HtmlUtils
'fscommand', 'seeksegmenttime' 'fscommand', 'seeksegmenttime'
))) )))
{ {
$sAttrsForRemove[] = $sAttrName; $aAttrsForRemove[$sName] = true;
} }
} }
} }
if (\count($sAttrsForRemove))
{
foreach ($sAttrsForRemove as $sName)
{
@$oElement->removeAttribute($sName);
$aRemovedAttrs[\trim(\strtolower($sName))] = true;
}
}
unset($sAttrsForRemove);
} }
if ($oElement->hasAttribute('href')) if ($oElement->hasAttribute('href'))
@ -705,23 +698,23 @@ abstract class HtmlUtils
$aFoundCIDs, $aContentLocationUrls, $aFoundContentLocationUrls, $fAdditionalExternalFilter)); $aFoundCIDs, $aContentLocationUrls, $aFoundContentLocationUrls, $fAdditionalExternalFilter));
} }
if (\MailSo\Config::$HtmlStrictDebug && \count($aRemovedAttrs)) foreach ($aAttrsForRemove as $sName)
{ {
unset($aRemovedAttrs['class'], $aRemovedAttrs['target'], $aRemovedAttrs['id'], $aRemovedAttrs['name'], @$oElement->removeAttribute($sName);
$aRemovedAttrs['itemprop'], $aRemovedAttrs['itemscope'], $aRemovedAttrs['itemtype']); }
$aRemovedAttrs = \array_keys($aRemovedAttrs); if (\MailSo\Config::$HtmlStrictDebug && $aAttrsForRemove)
if (\count($aRemovedAttrs)) {
unset($aAttrsForRemove['class'], $aAttrsForRemove['target'], $aAttrsForRemove['id'], $aAttrsForRemove['name'],
$aAttrsForRemove['itemprop'], $aAttrsForRemove['itemscope'], $aAttrsForRemove['itemtype']);
if ($aAttrsForRemove)
{ {
$oElement->setAttribute('data-removed-attrs', \implode(',', $aRemovedAttrs)); $oElement->setAttribute('data-removed-attrs', \implode(',', \array_keys($aAttrsForRemove)));
} }
} }
} }
$sResult = static::GetTextFromDom($oDom, true); return static::GetTextFromDom($oDom, true);
unset($oDom);
return $sResult;
} }
/** /**