I believe everything is compatable with all IMAP servers now
[squirrelmail.git] / functions / strings.php
index c7b6544e76ac9a7e7cddeb35363efc8e157852da..c3cdc3a31091ae13a9c54365a585f380684dc760 100644 (file)
    //    of the $haystack is reached.
    //*************************************************************************
    function readShortMailboxName($haystack, $needle) {
-      $len = strlen($haystack);
-      for ($i = $len - 1; ($i >= 0) && (!$found);$i--) {
-         $char = $haystack[$i];
-         if ($char == $needle)
-            $found = 1;
-         else
-            $data .= $char;
+      if (strpos($haystack, $needle)) {
+         $pos = strrpos($haystack, $needle) + 1;
+         $data = substr($haystack, $pos, strlen($haystack));
+      } else {
+         $data = $haystack;
+      }
+      return $data;
+   }
+
+   // Wraps text at $wrap characters
+   function wordWrap($passed, $wrap) {
+      $words = explode(" ", trim($passed));
+      $i = 0;
+      $line_len = strlen($words[$i])+1;
+      $line = "";
+      while ($i < count($words)) {
+         while ($line_len < $wrap) {
+            $line = "$line$words[$i]&nbsp;";
+            $i++;
+            $line_len = $line_len + strlen($words[$i])+1;
+         }
+         $line_len = strlen($words[$i])+1;
+         if ($line_len < $wrap) {
+            if ($i < count($words)) // don't <BR> the last line
+               $line = "$line<BR>";
+         } else {
+            $endline = $words[$i];
+            while ($line_len >= $wrap) {
+               $bigline = substr($endline, 0, $wrap);
+               $endline = substr($endline, $wrap, strlen($endline));
+               $line_len = strlen($endline);
+               $line = "$line$bigline<BR>";
+            }
+            $line = "$line$endline<BR>";
+            $i++;
+         }
       }
-      return strrev($data);
+      return $line;
    }
 
+   /** Returns an array of email addresses **/
+   function parseAddrs($text) {
+      $text = str_replace(" ", "", $text);
+      $text = str_replace(",", ";", $text);
+      $array = explode(";", $text);
+      return $array;
+   }
+
+   /** Returns a line of comma separated email addresses from an array **/
+   function getLineOfAddrs($array) {
+      $to_line = "";
+      for ($i = 0; $i < count($array); $i++) {
+         if ($to_line)
+            $to_line = "$to_line, $array[$i]";
+         else
+            $to_line = "$array[$i]";
+      }
+      return $to_line;
+   }
 ?>