From fb995a813afcc53c1c04e3a63af7c72f50901b03 Mon Sep 17 00:00:00 2001 From: alecpl Date: Tue, 3 Aug 2010 11:46:13 +0000 Subject: - Improve displaying of html messages with body's background image --- program/steps/mail/func.inc | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'program') diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 55ca8eb46..db2a5241c 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -987,10 +987,16 @@ function rcmail_message_body($attrib) $body = rcmail_print_body($part, array('safe' => $safe_mode, 'plain' => !$CONFIG['prefer_html'])); if ($part->ctype_secondary == 'html') { - $body = rcmail_html4inline($body, $attrib['id'], 'rcmBody', $color); + $body = rcmail_html4inline($body, $attrib['id'], 'rcmBody', $attrs); $div_attr = array('class' => 'message-htmlpart'); - if ($color) - $div_attr['style'] = 'background-color: '.$color; + $style = array(); + + if (!empty($attrs['color'])) + $style[] = 'background-color: '.$attrs['color']; + if (!empty($attrs['image'])) + $style[] = 'background-image: url('.$attrs['image'].')'; + if (!empty($style)) + $div_attr['style'] = implode('; ', $style); $out .= html::div($div_attr, $body); } @@ -1052,7 +1058,7 @@ function rcmail_resolve_base($body) /** * modify a HTML message that it can be displayed inside a HTML page */ -function rcmail_html4inline($body, $container_id, $body_id='', &$body_color='') +function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null) { $last_style_pos = 0; $body_lc = strtolower($body); @@ -1105,12 +1111,23 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$body_color='') ), $body); - // Get rcmBody's bgcolor attribute, we'll set the color to the body container - // as background-color, bgcolor doesn't work with a div - if (preg_match('/
]+)>/', $out, $m)) { - if (preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $m[0], $mb)) { - $body_color = $mb[1]; + $attributes = array(); + + // Handle body attributes that doesn't play nicely with div elements + if (preg_match('/
]+)/', $out, $m)) { + $attrs = $m[0]; + // Get bgcolor, we'll set it as background-color of the message container + if (preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $attrs, $mb)) { + $attributes['color'] = $mb[1]; + $attrs = preg_replace('/bgcolor=["\']*([a-z0-9#]+)["\']*/', '', $attrs); + } + // Get background, we'll set it as background-image of the message container + if (preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) { + $attributes['image'] = $mb[1]; + $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs); } + if (!empty($attributes)) + $out = preg_replace('/
]+/', rtrim($attrs), $out, 1); } // make sure there's 'rcmBody' div, we need it for proper css modification // its name is hardcoded in rcmail_message_body() also -- cgit v1.2.3