From bd82e9551fd0810ebfddaab2ae0abc80ce37268b Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 24 Aug 2015 04:11:08 -0400
Subject: [PATCH] Fix so css of one html part does not apply to other text parts on message display (#1490505)

---
 CHANGELOG                   |    1 +
 program/steps/mail/func.inc |   20 +++++++++++---------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 368ab44..5511d7d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -41,6 +41,7 @@
 - Disable links list generation on html-to-text conversion of identities or composed message (#1490437)
 - Fix "washing" of style elements wrapped into many lines
 - Fix so input field (e.g. search box) does not loose focus on list load (#1490455)
+- Fix so css of one html part does not apply to other text parts on message display (#1490505)
 
 RELEASE 1.1.2
 -------------
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index d078478..37298f5 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1172,7 +1172,8 @@
         $attrib['id'] = 'rcmailMsgBody';
 
     $safe_mode = $MESSAGE->is_safe || intval($_GET['_safe']);
-    $out = '';
+    $out       = '';
+    $part_no   = 0;
 
     $header_attrib = array();
     foreach ($attrib as $attr => $value) {
@@ -1230,9 +1231,10 @@
                 $body = rcmail_print_body($body, $part, array('safe' => $safe_mode, 'plain' => !$RCMAIL->config->get('prefer_html')));
 
                 if ($part->ctype_secondary == 'html') {
-                    $body     = rcmail_html4inline($body, $attrib['id'], 'rcmBody', $attrs, $safe_mode);
-                    $div_attr = array('class' => 'message-htmlpart');
-                    $style    = array();
+                    $container_id = 'message-htmlpart' . (++$part_no);
+                    $body         = rcmail_html4inline($body, $container_id, 'rcmBody', $attrs, $safe_mode);
+                    $div_attr     = array('class' => 'message-htmlpart', 'id' => $container_id);
+                    $style        = array();
 
                     if (!empty($attrs)) {
                         foreach ($attrs as $a_idx => $a_val)
@@ -1373,10 +1375,10 @@
 /**
  * modify a HTML message that it can be displayed inside a HTML page
  */
-function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null, $allow_remote=false)
+function rcmail_html4inline($body, $container_id, $body_class='', &$attributes=null, $allow_remote=false)
 {
     $last_style_pos = 0;
-    $cont_id        = $container_id.($body_id ? ' div.'.$body_id : '');
+    $cont_id        = $container_id . ($body_class ? ' div.'.$body_class : '');
 
     // find STYLE tags
     while (($pos = stripos($body, '<style', $last_style_pos)) && ($pos2 = stripos($body, '</style>', $pos))) {
@@ -1420,7 +1422,7 @@
             '<!--\\1-->',
             '&lt;?',
             '?&gt;',
-            '<div class="'.$body_id.'"\\1>',
+            '<div class="' . $body_class . '"\\1>',
             '</div>',
         ),
         $body);
@@ -1428,7 +1430,7 @@
     $attributes = array();
 
     // Handle body attributes that doesn't play nicely with div elements
-    $regexp = '/<div class="' . preg_quote($body_id, '/') . '"([^>]*)/';
+    $regexp = '/<div class="' . preg_quote($body_class, '/') . '"([^>]*)/';
     if (preg_match($regexp, $body, $m)) {
         $attrs = $m[0];
 
@@ -1465,7 +1467,7 @@
     // make sure there's 'rcmBody' div, we need it for proper css modification
     // its name is hardcoded in rcmail_message_body() also
     else {
-        $body = '<div class="' . $body_id . '">' . $body . '</div>';
+        $body = '<div class="' . $body_class . '">' . $body . '</div>';
     }
 
     return $body;

--
Gitblit v1.9.1