Replaced ereg_replace with str_replace on several occasions, should be faster.
[squirrelmail.git] / functions / mime.php
index 0958e871ff7e93b920ed1def9238c7a21413e096..1175f26f4ba2eaee8aa3659463f8a6e9795857d5 100644 (file)
@@ -376,9 +376,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) {
     // that it is the first one.  That is usually the case anyway.
     if (!$ent_id)
         $ent_id = 1;
-    $sid = sqimap_session_id();
-    fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
-    $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+    $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id]", true, $response, $message);
     $topline = array_shift($data);
     while (! ereg('\\* [0-9]+ FETCH ', $topline) && $data)
         $topline = array_shift($data);
@@ -390,8 +388,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) {
             in order to parse html messages. Let's get them here.
         */
         if ( $ret{0} == '<' ) {
-            fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id.MIME]\r\n");
-            $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+            $data = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent_id.MIME]", true, $response, $message);
             $base = '';
             $k = 10;
             foreach( $data as $d ) {
@@ -414,6 +411,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) {
                 $k++;
             }
             if ( $base <> '' )
+                
                 $ret = "<base href=\"$base\">" . $ret;
         }
     } else if (ereg('"([^"]*)"', $topline, $regs)) {
@@ -436,8 +434,7 @@ function mime_fetch_body ($imap_stream, $id, $ent_id ) {
                _("Message:") . " $message<BR>" .
                _("FETCH line:") . " $topline<BR></tt></font></b>";
 
-        fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n");
-        $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
+        $data = sqimap_run_command ($imap_stream, "FETCH $passed_id BODY[]", true, $response, $message);
         array_shift($data);
         $wholemessage = implode('', $data);
 
@@ -456,7 +453,11 @@ function mime_print_body_lines ($imap_stream, $id, $ent_id, $encoding) {
     $sid = sqimap_session_id();
     // Don't kill the connection if the browser is over a dialup
     // and it would take over 30 seconds to download it.
-    set_time_limit(0);
+
+    // donĀ“t call set_time_limit in safe mode.
+    if (!ini_get("safe_mode")) {
+        set_time_limit(0);
+    }
     
     fputs ($imap_stream, "$sid FETCH $id BODY[$ent_id]\r\n");
     $cnt = 0;
@@ -764,10 +765,10 @@ function decodeBody($body, $encoding) {
 function decodeHeader ($string, $utfencode=true) {
   if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=',
             $string, $res)) {
-     if (ucfirst($res[2]) == "B") {
+     if (ucfirst($res[2]) == 'B') {
         $replace = base64_decode($res[3]);
      } else {
-        $replace = ereg_replace("_", " ", $res[3]);
+        $replace = str_replace('_', ' ', $res[3]);
     // Convert lowercase Quoted Printable to uppercase for
     // quoted_printable_decode to understand it.
     while (ereg("(=(([0-9][abcdef])|([abcdef][0-9])|([abcdef][abcdef])))", $replace, $res)) {
@@ -839,8 +840,11 @@ function encodeHeader ($string) {
 */
 function MagicHTML( $body, $id ) {
 
-    global $message, $PHP_SELF, $HTTP_SERVER_VARS;
+    global $message, $HTTP_SERVER_VARS, 
+           $attachment_common_show_images;
 
+    $attachment_common_show_images =
+                     FALSE; // Don't display attached images in HTML mode
     $j = strlen( $body );   // Legnth of the HTML
     $ret = '';              // Returned string
     $bgcolor = '#ffffff';   // Background style color (defaults to white)
@@ -1027,7 +1031,7 @@ function MagicHTML( $body, $id ) {
 return( "\n\n<!-- HTML Output ahead -->\n" .
         $ret .
         "\n<!-- END of HTML Output --><base href=\"".
-        $HTTP_SERVER_VARS["SERVER_NAME"] . substr( $PHP_SELF, 0, strlen( $PHP_SELF ) - 13 ) .
+        get_location() . '/'.
         "\">\n\n" );
 }
 
@@ -1218,4 +1222,4 @@ function find_ent_id( $id, $message ) {
     return( $ret );
 
 }
-?>
\ No newline at end of file
+?>