Index: /trunk/roundcubemail/program/steps/mail/func.inc
===================================================================
--- /trunk/roundcubemail/program/steps/mail/func.inc	(revision 438)
+++ /trunk/roundcubemail/program/steps/mail/func.inc	(revision 439)
@@ -1194,5 +1194,6 @@
     $styles = rcmail_mod_css_styles(substr($body, $pos, $pos2-$pos), $container_id);
 
-    $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);    
+    $body = substr($body, 0, $pos) . $styles . substr($body, $pos2);
+    $body_lc = strtolower($body);
     $last_style_pos = $pos2;
     }
@@ -1204,5 +1205,5 @@
     while (($pos = strpos($body_lc, '<'.$tag)) && ($pos2 = strpos($body_lc, '</'.$tag.'>', $pos)))
       {
-      $pos2 += 8;
+      $pos2 += strlen('</'.$tag.'>');
       $body = substr($body, 0, $pos) . substr($body, $pos2, strlen($body)-$pos2);
       $body_lc = strtolower($body);
