summaryrefslogtreecommitdiff
path: root/roundcubemail/program/steps
diff options
context:
space:
mode:
authoralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2008-09-17 17:43:38 +0000
committeralec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c>2008-09-17 17:43:38 +0000
commit3f8b0cd7c6216249591454cd97704eb4afb833c6 (patch)
treea48804f878a88870b2a0ce07ac2a3c670aae5f38 /roundcubemail/program/steps
parent29f2b641b998bb3d46dc91c3b098955f2430d1a9 (diff)
- code cleanup + fix for malformed html (#1485139)
git-svn-id: https://svn.roundcube.net/trunk@1814 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program/steps')
-rw-r--r--roundcubemail/program/steps/mail/func.inc30
1 files changed, 17 insertions, 13 deletions
diff --git a/roundcubemail/program/steps/mail/func.inc b/roundcubemail/program/steps/mail/func.inc
index 3995bffe3..440de92b9 100644
--- a/roundcubemail/program/steps/mail/func.inc
+++ b/roundcubemail/program/steps/mail/func.inc
@@ -597,31 +597,35 @@ function rcmail_print_body($part, $p = array())
}
// text/html
else if ($part->ctype_secondary == 'html') {
- // charset was converted to UTF-8 in rcube_imap::get_message_part() -> change charset specification in HTML accordingly
- $html = $part->body;
- if (preg_match('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', $html))
- $html = preg_replace('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', '\\1='.RCMAIL_CHARSET, $html);
- else {
- // add <head> for malformed messages, washtml cannot work without that
- if (!preg_match('/<head>(.*)<\\/head>/Uims', $html))
- $html = '<head></head>' . $html;
- $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '</head>')), 0);
- }
-
- // PHP bug #32547 workaround: remove title tag
- $html = preg_replace('/<title>.*<\/title>/', '', $html);
+ $html = $part->body;
// special replacements (not properly handled by washtml class)
$html_search = array(
'/(<\/nobr>)(\s+)(<nobr>)/i', // space(s) between <NOBR>
'/(<[\/]*st1:[^>]+>)/i', // Microsoft's Smart Tags <ST1>
+ '/<title>.*<\/title>/i', // PHP bug #32547 workaround: remove title tag
+ '/<html[^>]*>/im', // malformed html: remove html tags (#1485139)
+ '/<\/html>/i', // malformed html: remove html tags (#1485139)
);
$html_replace = array(
'\\1'.' &nbsp; '.'\\3',
'',
+ '',
+ '',
+ '',
);
$html = preg_replace($html_search, $html_replace, $html);
+ // charset was converted to UTF-8 in rcube_imap::get_message_part() -> change charset specification in HTML accordingly
+ if (preg_match('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', $html))
+ $html = preg_replace('/(\s+content=[\'"]\w+\/\w+;\s*charset)=([a-z0-9-_]+)/i', '\\1='.RCMAIL_CHARSET, $html);
+ else {
+ // add head for malformed messages, washtml cannot work without that
+ if (!preg_match('/<head[^>]*>(.*)<\/head>/Uims', $html))
+ $html = '<head></head>'. $html;
+ $html = substr_replace($html, '<meta http-equiv="Content-Type" content="text/html; charset='.RCMAIL_CHARSET.'" />', intval(stripos($html, '</head>')), 0);
+ }
+
// clean HTML with washhtml by Frederic Motte
$wash_opts = array(
'show_washed' => false,