Jelajahi Sumber

moved sqUnwordWrap from compose to this file

stekkel 23 tahun lalu
induk
melakukan
e8c96a4b3e
1 mengubah file dengan 30 tambahan dan 0 penghapusan
  1. 30 0
      functions/strings.php

+ 30 - 0
functions/strings.php

@@ -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.