From d2f3a6fb8954155edf99fec71dec35ecc83ba0dd Mon Sep 17 00:00:00 2001 From: pdontthink Date: Tue, 7 Jan 2020 06:49:42 +0000 Subject: [PATCH] Even better HTML email content style containment git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14839 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/mime.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/functions/mime.php b/functions/mime.php index 28c37e36..688cf876 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -2124,9 +2124,17 @@ function sq_fixstyle($body, $pos, $message, $id, $mailbox){ * body {background: blah-blah} * and change it to .bodyclass so we can just assign it to a
*/ - // Let's try out something that catches stuff like: body, p, div { or stuff like: body a { // $content = preg_replace("|body(\s*\{.*?\})|si", ".bodyclass\\1", $content); - $content = preg_replace("/body((?:\s*(?:,| )\s*[a-z0-9_-]+)*\s*\{.*?\})/si", ".bodyclass\\1", $content); + // Nah, this is even better - try to preface all CSS selectors with + // our
class ID "bodyclass" then correct generic "body" selectors + // TODO: this works pretty good but breaks stuff like this: + // @media print { body { font-size: 10pt; } } + // but there isn't an easy way to make this regex skip @media + // definitions... though lots of the ones in the wild will be + // correctly handled because they tend to end with a parenthesis, like: + // @media screen and (max-width:480px) { ... + $content = preg_replace('/([a-z0-9._-][a-z0-9 >+~|:._-]*\s*(?:,|{.*?}))/si', '.bodyclass $1', $content); + $content = str_replace('.bodyclass body', '.bodyclass', $content); global $use_transparent_security_image; if ($use_transparent_security_image) $secremoveimg = '../images/spacer.png'; -- 2.25.1