summaryrefslogtreecommitdiff
path: root/program/steps/mail/func.inc
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-08-03 11:46:13 +0000
committeralecpl <alec@alec.pl>2010-08-03 11:46:13 +0000
commitfb995a813afcc53c1c04e3a63af7c72f50901b03 (patch)
treea7ec8c5de3c3554538ec07165ffd945a64f0031a /program/steps/mail/func.inc
parentc321e2fb24c84187d6015525ebaded826cd8f8d4 (diff)
- Improve displaying of html messages with body's background image
Diffstat (limited to 'program/steps/mail/func.inc')
-rw-r--r--program/steps/mail/func.inc35
1 files changed, 26 insertions, 9 deletions
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('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)>/', $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('/<div class="' . preg_quote($body_id, '/') . '" ([^>]+)/', $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('/<div class="' . preg_quote($body_id, '/') . '" [^>]+/', 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