Prerequisites
Describe the issue
Roundcube's HTML email sanitization process shows inconsistent behavior when rewriting CSS selectors, specifically when the <body> element has a class attribute. This results in broken styles and malformed HTML structure.
Expected behavior
CSS selectors should be consistently rewritten and the HTML structure should remain valid regardless of whether classes are applied to <p> elements or <body> elements.
Actual behavior
When a <body> element has a class attribute, Roundcube:
- Fails to include the
rcmBody wrapper div that should be present according to the CSS selector rewriting pattern
- Creates duplicate IDs (
id="message-htmlpart1" appears twice in the DOM)
- Generates CSS selectors that don't match the actual DOM structure
Steps to reproduce
Test Case 1 (Working - class on <p> element):
Input HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
@media (min-width: 600px) {
.p_class_name {
color: red;
}
}
</style>
</head>
<body>
<p class="p_class_name">Working CSS selector</p>
</body>
</html>
Output (Working correctly):
<div id="messagebody">
<div class="message-htmlpart" id="message-htmlpart1">
<!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<style type="text/css">
@media (min-width: 600px) {
#message-htmlpart1 div.rcmBody .v1p_class_name {
color: red;
}
}
</style>
<div class="rcmBody" id="message-htmlpart1">
<p class="v1p_class_name">Working CSS selector</p>
</div>
</div>
</div>
Test Case 2 (Broken - class on <body> element):
Input HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
@media (min-width: 600px) {
.body_class_name {
color: red;
}
}
</style>
</head>
<body class="body_class_name">
<p>Broken CSS selector</p>
</body>
</html>
Output (Broken):
<div id="messagebody">
<div class="message-htmlpart" id="message-htmlpart1">
<!-- html ignored --><!-- head ignored --><!-- meta ignored -->
<style type="text/css">
@media (min-width: 600px) {
#message-htmlpart1 div.rcmBody .v1body_class_name {
color: red;
}
}
</style>
<div class="v1body_class_name" id="message-htmlpart1">
<p>Broken CSS selector</p>
</div>
</div>
</div>
Issues identified
- Missing
rcmBody wrapper: In the broken case, the <div class="rcmBody"> wrapper is missing, but the CSS selector still references div.rcmBody
- Duplicate IDs: Both the outer container and inner div have
id="message-htmlpart1", which violates HTML standards
- CSS selector mismatch: The generated CSS selector
#message-htmlpart1 div.rcmBody .v1body_class_name cannot match the actual DOM structure <div id="message-htmlpart1"><div class="v1body_class_name"> because there's no element with class rcmBody
Impact
This bug breaks email styling for HTML emails that apply CSS classes to the <body> element, which is a common pattern in responsive email design and email templates.
What browser(s) are you seeing the problem on?
Chrome
What version of PHP are you using?
v8.4.8
What version of Roundcube are you using?
v1.6.11
JavaScript errors
No response
PHP errors
No response
Prerequisites
Describe the issue
Roundcube's HTML email sanitization process shows inconsistent behavior when rewriting CSS selectors, specifically when the
<body>element has a class attribute. This results in broken styles and malformed HTML structure.Expected behavior
CSS selectors should be consistently rewritten and the HTML structure should remain valid regardless of whether classes are applied to
<p>elements or<body>elements.Actual behavior
When a
<body>element has a class attribute, Roundcube:rcmBodywrapper div that should be present according to the CSS selector rewriting patternid="message-htmlpart1"appears twice in the DOM)Steps to reproduce
Test Case 1 (Working - class on
<p>element):Input HTML:
Output (Working correctly):
Test Case 2 (Broken - class on
<body>element):Input HTML:
Output (Broken):
Issues identified
rcmBodywrapper: In the broken case, the<div class="rcmBody">wrapper is missing, but the CSS selector still referencesdiv.rcmBodyid="message-htmlpart1", which violates HTML standards#message-htmlpart1 div.rcmBody .v1body_class_namecannot match the actual DOM structure<div id="message-htmlpart1"><div class="v1body_class_name">because there's no element with classrcmBodyImpact
This bug breaks email styling for HTML emails that apply CSS classes to the
<body>element, which is a common pattern in responsive email design and email templates.What browser(s) are you seeing the problem on?
Chrome
What version of PHP are you using?
v8.4.8
What version of Roundcube are you using?
v1.6.11
JavaScript errors
No response
PHP errors
No response