From 9eea179c055de6dcddf7b326818a9b522bdf96e6 Mon Sep 17 00:00:00 2001 From: fidian Date: Tue, 10 Oct 2000 15:08:41 +0000 Subject: [PATCH] Functions now pass message body by reference to save on memory. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@784 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 3 ++- functions/mime.php | 2 +- functions/strings.php | 49 +++++++++++++++++++++++++--------------- functions/url_parser.php | 20 ++++++++-------- src/download.php | 8 +++---- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index aa5bc575..dad842bc 100644 --- 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 - 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 diff --git a/functions/mime.php b/functions/mime.php index 652b5b90..ff5bf65b 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -453,7 +453,7 @@ // 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 .= "
". _("Download this as a file") ."

"; diff --git a/functions/strings.php b/functions/strings.php index 33d01527..02e5fc3a 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -45,20 +45,20 @@ } // Wraps text at $wrap characters - function sqWordWrap($passed, $wrap) { - $passed = str_replace("<", "<", $passed); - $passed = str_replace(">", ">", $passed); + function sqWordWrap(&$line, $wrap) { + $line = str_replace("<", "<", $line); + $line = str_replace(">", ">", $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(">", ">", $line); $line = str_replace("<", "<", $line); - return $line; } /** Returns an array of email addresses **/ @@ -125,7 +124,7 @@ 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)) { @@ -137,23 +136,39 @@ $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(' ', ' ', $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(' ', '', $line); - if (strpos($test_line, '>>') === 0) { + $Quotes = 0; + $pos = 0; + while (1) + { + if (strpos($line, ' ', $pos) === $pos) + { + $pos += 6; + } + else if (strpos($line, '>', $pos) === $pos) + { + $pos += 4; + $Quotes ++; + } + else + { + break; + } + } + + if ($Quotes > 1) { $line = "$line\n"; - } else if (strpos($test_line, '>') === 0) { + } else if ($Quotes) { $line = "$line\n"; } @@ -165,8 +180,6 @@ $body_ary[$i] = $line . '
'; } $body = implode("\n", $body_ary); - - return $body; } /* SquirrelMail version number -- DO NOT CHANGE */ diff --git a/functions/url_parser.php b/functions/url_parser.php index d9105b8c..53c18a24 100644 --- a/functions/url_parser.php +++ b/functions/url_parser.php @@ -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 @@ -43,11 +44,15 @@ */ $body = eregi_replace ($Expression, "\\0", $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://', @@ -81,12 +86,11 @@ // 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 @@ -122,8 +126,6 @@ $start = $target_pos; $target_pos = strlen($body); } - - return $body; } ?> diff --git a/src/download.php b/src/download.php index 91f90cc4..0ae0bc04 100644 --- a/src/download.php +++ b/src/download.php @@ -49,10 +49,10 @@ echo "
"; echo "
"; - if ($type1 == "html") - echo $body; - else - echo translateText($body, $wrap_at, $charset); + if ($type1 != "html") + translateText($body, $wrap_at, $charset); + + echo $body; echo "
"; } -- 2.25.1