Browse Source

Functions now pass message body by reference to save on memory.

Tyler Akins 25 years ago
parent
commit
75ec65addd
5 changed files with 49 additions and 33 deletions
  1. 2 1
      ChangeLog
  2. 1 1
      functions/mime.php
  3. 31 18
      functions/strings.php
  4. 11 9
      functions/url_parser.php
  5. 4 4
      src/download.php

+ 2 - 1
ChangeLog

@@ -1,11 +1,12 @@
 Version 0.6pre1 -- DEVELOPMENT
 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
 - Added file and message size in many locations
 - Made message index order customizable (from, subject, date) can be (date, from, subject)
 - Made message index order customizable (from, subject, date) can be (date, from, subject)
 - Fixed some security problems with uploading attachments
 - Fixed some security problems with uploading attachments
 - Added Catalan translation from Josep Sanz <jsanz@fa.upc.es>
 - Added Catalan translation from Josep Sanz <jsanz@fa.upc.es>
 - When reading, attachments look better and have a better plugin interface
 - 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 
 Version 0.5 -- September 25, 2000 

+ 1 - 1
functions/mime.php

@@ -453,7 +453,7 @@
          // If there are other types that shouldn't be formatted, add
          // If there are other types that shouldn't be formatted, add
          // them here 
          // them here 
          if ($message->header->type1 != "html") {   
          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>";
          $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>";

+ 31 - 18
functions/strings.php

@@ -45,20 +45,20 @@
    }
    }
 
 
    // Wraps text at $wrap characters
    // 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];
       $beginning_spaces = $regs[0];
 
 
-      $words = explode(" ", $passed);
+      $words = explode(" ", $line);
       $i = -1;
       $i = -1;
       $line_len = strlen($words[0])+1;
       $line_len = strlen($words[0])+1;
       $line = "";
       $line = "";
       if (count($words) > 1) {   
       if (count($words) > 1) {   
          while ($i++ < count($words)) {
          while ($i++ < count($words)) {
-            while ($line_len < $wrap) {
+            while ($line_len < $wrap && $i < count($words)) {
                $line = "$line$words[$i] ";
                $line = "$line$words[$i] ";
                $i++;
                $i++;
                $line_len = $line_len + strlen($words[$i]) + 1;
                $line_len = $line_len + strlen($words[$i]) + 1;
@@ -95,7 +95,6 @@
 
 
       $line = str_replace(">", "&gt;", $line);
       $line = str_replace(">", "&gt;", $line);
       $line = str_replace("<", "&lt;", $line);
       $line = str_replace("<", "&lt;", $line);
-      return $line;
    }
    }
 
 
    /** Returns an array of email addresses **/
    /** Returns an array of email addresses **/
@@ -125,7 +124,7 @@
       return $to_line;
       return $to_line;
    }
    }
 
 
-   function translateText($body, $wrap_at, $charset) {
+   function translateText(&$body, $wrap_at, $charset) {
       global $where, $what; // from searching
       global $where, $what; // from searching
 
 
       if (!isset($url_parser_php)) {
       if (!isset($url_parser_php)) {
@@ -137,23 +136,39 @@
          $line = $body_ary[$i];
          $line = $body_ary[$i];
          $line = charset_decode($charset, $line);
          $line = charset_decode($charset, $line);
          $line = str_replace("\t", '        ', $line);
          $line = str_replace("\t", '        ', $line);
+         chop($line);
          
          
          if (strlen($line) - 2 >= $wrap_at) {
          if (strlen($line) - 2 >= $wrap_at) {
-            $line = sqWordWrap($line, $wrap_at);  
+            sqWordWrap($line, $wrap_at);  
          }
          }
          
          
          $line = str_replace(' ', '&nbsp;', $line);
          $line = str_replace(' ', '&nbsp;', $line);
          $line = nl2br($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";
             $line = "<FONT COLOR=FF0000>$line</FONT>\n";
-         } else if (strpos($test_line, '&gt;') === 0) {
+         } else if ($Quotes) {
             $line = "<FONT COLOR=800000>$line</FONT>\n";
             $line = "<FONT COLOR=800000>$line</FONT>\n";
          }
          }
 
 
@@ -165,8 +180,6 @@
          $body_ary[$i] = $line . '<br>';
          $body_ary[$i] = $line . '<br>';
       }
       }
       $body = implode("\n", $body_ary);
       $body = implode("\n", $body_ary);
-            
-      return $body;
    }
    }
 
 
    /* SquirrelMail version number -- DO NOT CHANGE */
    /* SquirrelMail version number -- DO NOT CHANGE */

+ 11 - 9
functions/url_parser.php

@@ -10,8 +10,9 @@
       return $ret;
       return $ret;
    }
    }
 
 
-   function parseEmail ($body) {
+   function parseEmail (&$body) {
       global $color;
       global $color;
+      $Size = strlen($body);
       
       
       // Having this defined in just one spot could help when changes need
       // Having this defined in just one spot could help when changes need
       // to be made to the pattern
       // to be made to the pattern
@@ -43,11 +44,15 @@
       */
       */
       
       
       $body = eregi_replace ($Expression, "<a href=\"../src/compose.php?send_to=\\0\">\\0</a>", $body); 
       $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(
       $url_tokens = array(
          'http://',
          'http://',
@@ -81,12 +86,11 @@
         
         
         // Look for email addresses between $start and $target_pos
         // Look for email addresses between $start and $target_pos
         $check_str = substr($body, $start, $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
         // If there was a token to replace, replace it
@@ -122,8 +126,6 @@
         $start = $target_pos;
         $start = $target_pos;
         $target_pos = strlen($body);
         $target_pos = strlen($body);
       }
       }
-      
-     return $body;
    }
    }
    
    
 ?>
 ?>

+ 4 - 4
src/download.php

@@ -49,10 +49,10 @@
       echo "<TABLE WIDTH=98% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
       echo "<TABLE WIDTH=98% BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER><TR><TD BGCOLOR=\"$color[0]\">";
       echo "<TR><TD BGCOLOR=\"$color[4]\"><TT>";
       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>";
       echo "</TT></TD></TR></TABLE>";
    }
    }