Fixed stupid bug causing double lines (the same)
[squirrelmail.git] / functions / strings.php
index 60e20393509cda245f7c4a8b2876e816fc8d3e75..8e1042294b302687cfdc4a995ee4124e3520d991 100644 (file)
@@ -16,7 +16,7 @@
  * SquirrelMail version number -- DO NOT CHANGE
  */
 global $version;
-$version = '1.3.0 [CVS-DEVEL]';
+$version = '1.3.2 [CVS-DEVEL]';
 
 /**
  * Wraps text at $wrap characters
@@ -69,6 +69,38 @@ function sqWordWrap(&$line, $wrap) {
     }
 }
 
+/**
+ * Does the opposite of sqWordWrap()
+ */
+function sqUnWordWrap(&$body) {
+    $lines = explode("\n", $body);
+    $body = '';
+    $PreviousSpaces = '';
+    $cnt = count($lines);
+    for ($i = 0; $i < $cnt; $i ++) {
+        preg_match("/^([\t >]*)([^\t >].*)?$/", $lines[$i], $regs);
+        $CurrentSpaces = $regs[1];
+        if (isset($regs[2])) {
+            $CurrentRest = $regs[2];
+        } else {
+           $CurrentRest = '';
+       }
+        
+        if ($i == 0) {
+            $PreviousSpaces = $CurrentSpaces;
+            $body = $lines[$i];
+        } else if (($PreviousSpaces == $CurrentSpaces) /* Do the beginnings match */
+                   && (strlen($lines[$i - 1]) > 65)    /* Over 65 characters long */
+                   && strlen($CurrentRest)) {          /* and there's a line to continue with */
+            $body .= ' ' . $CurrentRest;
+        } else {
+            $body .= "\n" . $lines[$i];
+            $PreviousSpaces = $CurrentSpaces;
+        }
+    }
+    $body .= "\n";
+}
+
 /**
  * If $haystack is a full mailbox name and $needle is the mailbox
  * separator character, returns the last part of the mailbox name.
@@ -153,7 +185,7 @@ function php_self () {
 function get_location () {
     
     global $PHP_SELF, $SERVER_NAME, $HTTP_HOST, $SERVER_PORT,
-        $HTTP_SERVER_VARS;
+        $HTTP_SERVER_VARS, $imap_server_type;
     
     /* Get the path, handle virtual directories */
     $path = substr(php_self(), 0, strrpos(php_self(), '/'));
@@ -196,6 +228,14 @@ function get_location () {
         }
     }
     
+   /* this is a workaround for the weird macosx caching that
+      causes Apache to return 16080 as the port number, which causes
+      SM to bail */
+      
+   if ($imap_server_type == 'macosx' && $port == ':16080') {
+        $port = '';
+   }
+   
     /* Fallback is to omit the server name and use a relative */
     /* URI, although this is not RFC 2616 compliant.          */
     return ($host ? $proto . $host . $port . $path : $path);