- Fix messages background image handling in some cases (#1486990)

release-0.6
alecpl 14 years ago
parent 618cb0d8dd
commit cb3dfdfede

@ -20,6 +20,7 @@ CHANGELOG RoundCube Webmail
- Added fieldsets in Identity form, added 'identity_form' hook - Added fieldsets in Identity form, added 'identity_form' hook
- Re-added 'Close' button in upload form (#1486930, #1486823) - Re-added 'Close' button in upload form (#1486930, #1486823)
- Fix handling of charsets with LATIN-* label - Fix handling of charsets with LATIN-* label
- Fix messages background image handling in some cases (#1486990)
RELEASE 0.4 RELEASE 0.4
----------- -----------

@ -868,12 +868,12 @@ function rcmail_mod_css_styles($source, $container_id)
array( array(
'/(^\s*<!--)|(-->\s*$)/', '/(^\s*<!--)|(-->\s*$)/',
'/(^\s*|,\s*|\}\s*)([a-z0-9\._#\*][a-z0-9\.\-_]*)/im', '/(^\s*|,\s*|\}\s*)([a-z0-9\._#\*][a-z0-9\.\-_]*)/im',
"/$container_id\s+body/i", '/'.preg_quote($container_id, '/').'\s+body/i',
), ),
array( array(
'', '',
"\\1#$container_id \\2", "\\1#$container_id \\2",
"$container_id div.rcmBody", $container_id,
), ),
$source); $source);

@ -994,12 +994,12 @@ function rcmail_message_body($attrib)
$div_attr = array('class' => 'message-htmlpart'); $div_attr = array('class' => 'message-htmlpart');
$style = array(); $style = array();
if (!empty($attrs['color'])) if (!empty($attrs)) {
$style[] = 'background-color: '.$attrs['color']; foreach ($attrs as $a_idx => $a_val)
if (!empty($attrs['image'])) $style[] = $a_idx . ': ' . $a_val;
$style[] = 'background-image: url('.$attrs['image'].')';
if (!empty($style)) if (!empty($style))
$div_attr['style'] = implode('; ', $style); $div_attr['style'] = implode('; ', $style);
}
$out .= html::div($div_attr, $plugin['prefix'] . $body); $out .= html::div($div_attr, $plugin['prefix'] . $body);
} }
@ -1074,6 +1074,7 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null
{ {
$last_style_pos = 0; $last_style_pos = 0;
$body_lc = strtolower($body); $body_lc = strtolower($body);
$cont_id = $container_id.($body_id ? ' div.'.$body_id : '');
// find STYLE tags // find STYLE tags
while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos))) while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
@ -1081,8 +1082,8 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null
$pos = strpos($body_lc, '>', $pos)+1; $pos = strpos($body_lc, '>', $pos)+1;
// replace all css definitions with #container [def] // replace all css definitions with #container [def]
$styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $styles = rcmail_mod_css_styles(
$container_id.($body_id ? ' div.'.$body_id : '')); substr($body, $pos, $pos2-$pos), $cont_id);
$body = substr($body, 0, $pos) . $styles . substr($body, $pos2); $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
$body_lc = strtolower($body); $body_lc = strtolower($body);
@ -1094,7 +1095,7 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null
$body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body); $body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body);
unset($GLOBALS['rcmail_html_container_id']); unset($GLOBALS['rcmail_html_container_id']);
$out = preg_replace(array( $body = preg_replace(array(
// add comments arround html and other tags // add comments arround html and other tags
'/(<!DOCTYPE[^>]*>)/i', '/(<!DOCTYPE[^>]*>)/i',
'/(<\?xml[^>]*>)/i', '/(<\?xml[^>]*>)/i',
@ -1126,27 +1127,39 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null
$attributes = array(); $attributes = array();
// Handle body attributes that doesn't play nicely with div elements // Handle body attributes that doesn't play nicely with div elements
if (preg_match('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)/', $out, $m)) { if (preg_match('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)/', $body, $m)) {
$attrs = $m[0]; $attrs = $m[0];
// Get bgcolor, we'll set it as background-color of the message container // Get bgcolor, we'll set it as background-color of the message container
if (preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $attrs, $mb)) { if (preg_match('/bgcolor=["\']*([a-z0-9#]+)["\']*/', $attrs, $mb)) {
$attributes['color'] = $mb[1]; $attributes['background-color'] = $mb[1];
$attrs = preg_replace('/bgcolor=["\']*([a-z0-9#]+)["\']*/', '', $attrs); $attrs = preg_replace('/bgcolor=["\']*([a-z0-9#]+)["\']*/', '', $attrs);
} }
// Get background, we'll set it as background-image of the message container // Get background, we'll set it as background-image of the message container
if (preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) { if (preg_match('/background=["\']*([^"\'>\s]+)["\']*/', $attrs, $mb)) {
$attributes['image'] = $mb[1]; $attributes['background-image'] = 'url('.$mb[1].')';
$attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs); $attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs);
} }
if (!empty($attributes)) if (!empty($attributes))
$out = preg_replace('/<div class="' . preg_quote($body_id, '/') . '" [^>]+/', rtrim($attrs), $out, 1); $body = preg_replace('/<div class="' . preg_quote($body_id, '/') . '" [^>]+/', rtrim($attrs), $body, 1);
// handle body styles related to background image
if ($attributes['background-image']) {
// get body style
if (preg_match('/#'.preg_quote($cont_id, '/').'\s+\{([^}]+)}/i', $body, $m)) {
// get background related style
if (preg_match_all('/(background-position|background-repeat)\s*:\s*([^;]+);/i', $m[1], $ma, PREG_SET_ORDER)) {
foreach ($ma as $style)
$attributes[$style[1]] = $style[2];
}
}
}
} }
// make sure there's 'rcmBody' div, we need it for proper css modification // make sure there's 'rcmBody' div, we need it for proper css modification
// its name is hardcoded in rcmail_message_body() also // its name is hardcoded in rcmail_message_body() also
else else
$out = '<div class="' . $body_id . '">' . $out . '</div>'; $body = '<div class="' . $body_id . '">' . $body . '</div>';
return $out; return $body;
} }

Loading…
Cancel
Save