Optimization:
[squirrelmail.git] / functions / strings.php
index 722cedeca8bae5ddf2dac4cf28ee1cb3db17b2d4..0b146f008beabfe8488225fa5909c1dcb7950ecd 100644 (file)
  * SquirrelMail version number -- DO NOT CHANGE
  */
 global $version;
-$version = '1.2.5 [cvs]';
+$version = '1.2.6 [cvs]';
 
 /**
  * If $haystack is a full mailbox name and $needle is the mailbox
  * separator character, returns the last part of the mailbox name.
  */
 function readShortMailboxName($haystack, $needle) {
+
     if ($needle == '') {
-        return $haystack;
-    }
-    $parts = explode($needle, $haystack);
-    $elem = array_pop($parts);
-    while ($elem == '' && count($parts)) {
-        $elem = array_pop($parts);
+        $elem = $haystack;
+    } else {
+           $parts = explode($needle, $haystack);
+           $elem = array_pop($parts);
+           while ($elem == '' && count($parts)) {
+               $elem = array_pop($parts);
+           }
     }
-    return $elem;
+    return( $elem );
 }
 
-/**
- * If $haystack is a full mailbox name, and $needle is the mailbox
- * separator character, returns the second last part of the full
- * mailbox name (i.e. the mailbox's parent mailbox)
- */
-function readMailboxParent($haystack, $needle) {
-    if ($needle == '') return '';
-    $parts = explode($needle, $haystack);
-    $elem = array_pop($parts);
-    while ($elem == '' && count($parts)) {
-        $elem = array_pop($parts);
-    }
-    return join($needle, $parts);
-}
+
 
 /**
  * Returns the index of the first chunk of string $haystack that
@@ -192,9 +181,9 @@ function getLineOfAddrs($array) {
 function translateText(&$body, $wrap_at, $charset) {
     global $where, $what; /* from searching */
     global $color; /* color theme */
-    
+
     require_once('../functions/url_parser.php');
-    
+
     $body_ary = explode("\n", $body);
     $PriorQuotes = 0;
     for ($i=0; $i < count($body_ary); $i++) {
@@ -209,7 +198,7 @@ function translateText(&$body, $wrap_at, $charset) {
 
         $Quotes = 0;
         $pos = 0;
-       $j = strlen( $line );
+        $j = strlen( $line );
 
         while ( $pos < $j ) {
             if ($line[$pos] == ' ') {
@@ -539,14 +528,15 @@ function GenerateRandomString($size, $chars, $flags = 0) {
     if (($size < 1) || (strlen($chars) < 1)) {
         return '';
     }
-    
+
     sq_mt_randomize(); /* Initialize the random number generator */
-    
+
     $String = '';
+    $j = strlen( $chars ) - 1;
     while (strlen($String) < $size) {
-        $String .= $chars[mt_rand(0, strlen($chars))];
+        $String .= $chars{mt_rand(0, $j)};
     }
-    
+
     return $String;
 }
 
@@ -595,4 +585,4 @@ function RemoveSlashes(&$array) {
 
 $PHP_SELF = php_self();
 
-?>
+?>
\ No newline at end of file