summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-09-11 13:21:34 +0000
committeralecpl <alec@alec.pl>2010-09-11 13:21:34 +0000
commitcb3dfdfedef18381a30fd9b80c9f7120af1031a4 (patch)
treea5f3dd0c856bea2bfb8a44f3b518b5ce040f44dd /program
parent618cb0d8dde52c2c8a181334e7a3c33fbc26c236 (diff)
- Fix messages background image handling in some cases (#1486990)
Diffstat (limited to 'program')
-rw-r--r--program/include/main.inc8
-rw-r--r--program/steps/mail/func.inc51
2 files changed, 36 insertions, 23 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 501a80fa7..e3004d048 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -845,7 +845,7 @@ function rcmail_mod_css_styles($source, $container_id)
{
$last_pos = 0;
$replacements = new rcube_string_replacer;
-
+
// ignore the whole block if evil styles are detected
$stripped = preg_replace('/[^a-z\(:]/', '', rcmail_xss_entity_decode($source));
if (preg_match('/expression|behavior|url\(|import/', $stripped))
@@ -868,15 +868,15 @@ function rcmail_mod_css_styles($source, $container_id)
array(
'/(^\s*<!--)|(-->\s*$)/',
'/(^\s*|,\s*|\}\s*)([a-z0-9\._#\*][a-z0-9\.\-_]*)/im',
- "/$container_id\s+body/i",
+ '/'.preg_quote($container_id, '/').'\s+body/i',
),
array(
'',
"\\1#$container_id \\2",
- "$container_id div.rcmBody",
+ $container_id,
),
$source);
-
+
// put block contents back in
$styles = $replacements->resolve($styles);
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 73d675a60..68b790cd9 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -994,12 +994,12 @@ function rcmail_message_body($attrib)
$div_attr = array('class' => 'message-htmlpart');
$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);
+ if (!empty($attrs)) {
+ foreach ($attrs as $a_idx => $a_val)
+ $style[] = $a_idx . ': ' . $a_val;
+ if (!empty($style))
+ $div_attr['style'] = implode('; ', $style);
+ }
$out .= html::div($div_attr, $plugin['prefix'] . $body);
}
@@ -1071,30 +1071,31 @@ 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='', &$attributes=null)
- {
+{
$last_style_pos = 0;
$body_lc = strtolower($body);
+ $cont_id = $container_id.($body_id ? ' div.'.$body_id : '');
// find STYLE tags
while (($pos = strpos($body_lc, '<style', $last_style_pos)) && ($pos2 = strpos($body_lc, '</style>', $pos)))
- {
+ {
$pos = strpos($body_lc, '>', $pos)+1;
// replace all css definitions with #container [def]
- $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos),
- $container_id.($body_id ? ' div.'.$body_id : ''));
+ $styles = rcmail_mod_css_styles(
+ substr($body, $pos, $pos2-$pos), $cont_id);
$body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
$body_lc = strtolower($body);
$last_style_pos = $pos2;
- }
+ }
// modify HTML links to open a new window if clicked
$GLOBALS['rcmail_html_container_id'] = $container_id;
$body = preg_replace_callback('/<(a|link)\s+([^>]+)>/Ui', 'rcmail_alter_html_link', $body);
unset($GLOBALS['rcmail_html_container_id']);
- $out = preg_replace(array(
+ $body = preg_replace(array(
// add comments arround html and other tags
'/(<!DOCTYPE[^>]*>)/i',
'/(<\?xml[^>]*>)/i',
@@ -1126,28 +1127,40 @@ function rcmail_html4inline($body, $container_id, $body_id='', &$attributes=null
$attributes = array();
// 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];
// 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];
+ $attributes['background-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];
+ $attributes['background-image'] = 'url('.$mb[1].')';
$attrs = preg_replace('/background=["\']*([^"\'>\s]+)["\']*/', '', $attrs);
}
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
// its name is hardcoded in rcmail_message_body() also
else
- $out = '<div class="' . $body_id . '">' . $out . '</div>';
+ $body = '<div class="' . $body_id . '">' . $body . '</div>';
- return $out;
- }
+ return $body;
+}
/**