Functions now pass message body by reference to save on memory.
authorfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 10 Oct 2000 15:08:41 +0000 (15:08 +0000)
committerfidian <fidian@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 10 Oct 2000 15:08:41 +0000 (15:08 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@784 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
functions/mime.php
functions/strings.php
functions/url_parser.php
src/download.php

index aa5bc57581dd80e0619e591d13be2516704c4298..dad842bc88b3915f9ad1e5d62de07bc2932498e8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,12 @@
 Version 0.6pre1 -- DEVELOPMENT
 ------------------------------
-- Updated attachment viewing, added plugin support (see plugins.txt)
+- Updated attachment plugin support and passing values to hooks (see plugins.txt)
 - Added file and message size in many locations
 - Made message index order customizable (from, subject, date) can be (date, from, subject)
 - Fixed some security problems with uploading attachments
 - Added Catalan translation from Josep Sanz <jsanz@fa.upc.es>
 - When reading, attachments look better and have a better plugin interface
+- Some functions now pass values by reference to save on memory
 
 
 Version 0.5 -- September 25, 2000 
index 652b5b90366868b195691422c91b3572c6af77a9..ff5bf65baae0d6ec67251461ee4c9ec61027c258 100644 (file)
          // If there are other types that shouldn't be formatted, add
          // them here 
          if ($message->header->type1 != "html") {   
-            $body = translateText($body, $wrap_at, $body_message->header->charset);
+            translateText($body, $wrap_at, $body_message->header->charset);
          }   
    
          $body .= "<SMALL><CENTER><A HREF=\"../src/download.php?absolute_dl=true&passed_id=$id&passed_ent_id=$ent_num&mailbox=$urlmailbox\">". _("Download this as a file") ."</A></CENTER><BR></SMALL>";
index 33d01527c738d28b1f6a14e2a4abd10293c6b558..02e5fc3ad741096fab8c091ba539bc2f10d387e7 100644 (file)
    }
 
    // Wraps text at $wrap characters
-   function sqWordWrap($passed, $wrap) {
-      $passed = str_replace("&lt;", "<", $passed);
-      $passed = str_replace("&gt;", ">", $passed);
+   function sqWordWrap(&$line, $wrap) {
+      $line = str_replace("&lt;", "<", $line);
+      $line = str_replace("&gt;", ">", $line);
 
-      preg_match("/^(\s|>)+/", $passed, $regs);
+      preg_match("/^(\s|>)+/", $line, $regs);
       $beginning_spaces = $regs[0];
 
-      $words = explode(" ", $passed);
+      $words = explode(" ", $line);
       $i = -1;
       $line_len = strlen($words[0])+1;
       $line = "";
       if (count($words) > 1) {   
          while ($i++ < count($words)) {
-            while ($line_len < $wrap) {
+            while ($line_len < $wrap && $i < count($words)) {
                $line = "$line$words[$i] ";
                $i++;
                $line_len = $line_len + strlen($words[$i]) + 1;
@@ -95,7 +95,6 @@
 
       $line = str_replace(">", "&gt;", $line);
       $line = str_replace("<", "&lt;", $line);
-      return $line;
    }
 
    /** Returns an array of email addresses **/
       return $to_line;
    }
 
-   function translateText($body, $wrap_at, $charset) {
+   function translateText(&$body, $wrap_at, $charset) {
       global $where, $what; // from searching
 
       if (!isset($url_parser_php)) {
          $line = $body_ary[$i];
          $line = charset_decode($charset, $line);
          $line = str_replace("\t", '        ', $line);
+         chop($line);
          
          if (strlen($line) - 2 >= $wrap_at) {
-            $line = sqWordWrap($line, $wrap_at);  
+            sqWordWrap($line, $wrap_at);  
          }
          
          $line = str_replace(' ', '&nbsp;', $line);
          $line = nl2br($line);
 
-         // Removed parseEmail and integrated it into parseUrl
-         // This line is no longer needed.
-         // $line = parseEmail ($line);
-         $line = parseUrl ($line);
+         parseUrl ($line);
          
-         $test_line = str_replace('&nbsp;', '', $line);
-         if (strpos($test_line, '&gt;&gt;') === 0) {
+         $Quotes = 0;
+         $pos = 0;
+         while (1)
+         {
+             if (strpos($line, '&nbsp;', $pos) === $pos)
+             {
+                $pos += 6;
+             }
+             else if (strpos($line, '&gt;', $pos) === $pos)
+             {
+                $pos += 4;
+                $Quotes ++;
+             }
+             else
+             {
+                 break;
+             }
+         }
+         
+         if ($Quotes > 1) {
             $line = "<FONT COLOR=FF0000>$line</FONT>\n";
-         } else if (strpos($test_line, '&gt;') === 0) {
+         } else if ($Quotes) {
             $line = "<FONT COLOR=800000>$line</FONT>\n";
          }
 
          $body_ary[$i] = $line . '<br>';
       }
       $body = implode("\n", $body_ary);
-            
-      return $body;
    }
 
    /* SquirrelMail version number -- DO NOT CHANGE */
index d9105b8ce0ec4491332c94f1c95bbc9c01035246..53c18a24011fd6698164c48a4d9c8eb0879cf23f 100644 (file)
@@ -10,8 +10,9 @@
       return $ret;
    }
 
-   function parseEmail ($body) {
+   function parseEmail (&$body) {
       global $color;
+      $Size = strlen($body);
       
       // Having this defined in just one spot could help when changes need
       // to be made to the pattern
       */
       
       $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body); 
-      return $body;
+      
+      // If there are any changes, it'll just get bigger.
+      if ($Size != strlen($body))
+          return 1;
+      return 0;
    }
 
 
-   function parseUrl ($body)
+   function parseUrl (&$body)
    {
       $url_tokens = array(
          'http://',
         
         // Look for email addresses between $start and $target_pos
         $check_str = substr($body, $start, $target_pos);
-        $new_str = parseEmail($check_str);
        
-        if ($check_str != $new_str)
+        if (parseEmail($check_str))
         {
-          $body = replaceBlock($body, $new_str, $start, $target_pos);
-          $target_pos = strlen($new_str) + $start;
+          $body = replaceBlock($body, $check_str, $start, $target_pos);
+          $target_pos = strlen($check_str) + $start;
         }
 
         // If there was a token to replace, replace it
         $start = $target_pos;
         $target_pos = strlen($body);
       }
-      
-     return $body;
    }
    
 ?>
index 91f90cc4e0410acbb0650779ae4dae5e564a681a..0ae0bc04681eb2bafb7ba95af7bfd449eafee8e0 100644 (file)
       echo "<TABLE WIDTH=98% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
       echo "<TR><TD BGCOLOR=\"$color[4]\"><TT>";
 
-      if ($type1 == "html")
-         echo $body;
-      else
-         echo translateText($body, $wrap_at, $charset);
+      if ($type1 != "html")
+         translateText($body, $wrap_at, $charset);
+      
+      echo $body;
 
       echo "</TT></TD></TR></TABLE>";
    }