Index: /trunk/expressoMail1_2/inc/class.imap_functions.inc.php
===================================================================
--- /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5420)
+++ /trunk/expressoMail1_2/inc/class.imap_functions.inc.php	(revision 5435)
@@ -1126,5 +1126,5 @@
 				else
 				{
-					if ($tmp->host != 'unspecified-domain')
+					if (isset($tmp->host) && $tmp->host != 'unspecified-domain')
 						$return['toaddress2'] .= $tmp->mailbox . "@" . $tmp->host;
 					else
@@ -1855,41 +1855,39 @@
 
             $regs_found = array();
-            $tags_found = preg_match_all("@<style[^>]*>.*?</style[^>]*>@s", $body, $regs_found);
+            $tags_found = preg_match_all("@<style[^>]*>.*?</style[^>]*>@si", $body, $regs_found);
             $wrapper_class = 'ExpressoCssWrapper' . time();
                         
-            foreach ($regs_found as $block_found) {
-                if(!isset($block_found[0])) continue;
-                
-                $n_start = strpos($block_found[0], '>') + 1;
-                $n_length = strrpos($block_found[0], '<') - $n_start;
-                $bf_innerHTML = substr($block_found[0], $n_start, $n_length);
-                              
-                $bf_innerHTML = mb_ereg_replace('<!--', '', $bf_innerHTML);
-                $bf_innerHTML = mb_ereg_replace('-->', '', $bf_innerHTML);
-              
-                $css->parse($bf_innerHTML);
-
-                $prefix = ".$wrapper_class ";
-                if (isset($css->css[41]) && count($css->css[41] > 0))
-                    foreach ($css->css[41] as $key => $value) {
-                        //explode multiple selectors per block 
-                        $selectors = explode(',', $key);
-
-                        foreach ($selectors as $selector) {
-                            if (ereg('\*', $key)) {
-                                //skip selecto '*' 
-                                continue;
+            foreach ($regs_found as $k => &$v) {
+                foreach ($v as $kk => $vv) {
+                    $n_start = strpos($vv, '>') + 1;
+                    $n_length = strrpos($vv, '<') - $n_start;
+                    $bf_innerHTML = substr($vv, $n_start, $n_length);
+                    $bf_innerHTML = mb_ereg_replace('<!--', '', $bf_innerHTML);
+                    $bf_innerHTML = mb_ereg_replace('-->', '', $bf_innerHTML);
+                    
+                    $css->parse($bf_innerHTML);
+
+                    $prefix = ".$wrapper_class ";
+                    if (isset($css->css[41]) && count($css->css[41] > 0))
+                        foreach ($css->css[41] as $key => $value) {
+                            //explode multiple selectors per block 
+                            $selectors = explode(',', $key);
+
+                            foreach ($selectors as $selector) {
+                                if (ereg('\*', $key)) {
+                                    //skip selecto '*' 
+                                    continue;
+                                }
+
+                                $selector = eregi_replace('[^#\.]*body.*', '', $selector);
+                                $css->css[41][$prefix . trim($selector)] = $value;
                             }
-
-                            $selector = eregi_replace('[^#\.]*body.*', '', $selector);
-                            $css->css[41][$prefix . trim($selector)] = $value;
+                            unset($css->css[41][$key]);
                         }
-                        unset($css->css[41][$key]);
-                    }
-                                              
-                $body = str_replace($block_found, '<style>' . $css->print->plain() . '</style>', $body);
-        }
-
-
+
+                    $body = str_replace($vv, '<style>' . $css->print->plain() . '</style>', $body);
+                }
+            }
+            
         // Malicious Code Remove
         $dirtyCodePattern = "/(<([\w]+[\w0-9]*)(.*)on(mouse(move|over|down|up)|load|blur|change|error|click|dblclick|focus|key(down|up|press)|select)([\n\ ]*)=([\n\ ]*)[\"'][^>\"']*[\"']([^>]*)>)(.*)(<\/\\2>)?/misU";
