finally managed to solve the bad Junk after literal output from the
[squirrelmail.git] / functions / strings.php
index df0a7117452152f1ae87e3d0671ede0cd115437c..6b6c4a74eb36f39c2fc52e32c1869cb733018c2d 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,36 @@ 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];
+        }
+        
+        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.