From 7dfb1fba5001299300736e6b5d95d9400575e3e7 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Thu, 18 Sep 2008 14:59:02 -0400
Subject: [PATCH] Set the right number of arguments for setcookie()

---
 program/steps/mail/func.inc |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 7e9f0fe..440de92 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -597,19 +597,34 @@
   }
   // text/html
   else if ($part->ctype_secondary == '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
-    $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;
+      // 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);
 
     // clean HTML with washhtml by Frederic Motte
     $wash_opts = array(

--
Gitblit v1.9.1