Tweaked wrapping a little more.
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 15 Jun 2004 18:09:57 +0000 (18:09 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 15 Jun 2004 18:09:57 +0000 (18:09 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7645 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/strings.php
src/compose.php

index 79b35f3..924f2f1 100644 (file)
@@ -116,7 +116,6 @@ function sm_ctype_space($string) {
  * @return string the wrapped text
  */
 function &sqBodyWrap (&$body, $wrap) {
-    //sm_print_r($body);
     //check for ctype support, and fake it if it doesn't exist
     if (!function_exists('ctype_space')) {
         function ctype_space ($string) {
@@ -146,9 +145,9 @@ function &sqBodyWrap (&$body, $wrap) {
 
            // skip over any spaces interleaved among the cite markers
            while (($pos < $length) && ($body{$pos} == ' ')) {
-              
+
                $pos++;
-               
+
            }
            if ($pos >= $length) {
                break;
@@ -210,6 +209,10 @@ function &sqBodyWrap (&$body, $wrap) {
            $pos = $nextNewline + 1;
            continue;
        }
+       /**
+        * Set this to false to stop appending short strings to previous lines
+        */
+       $smartwrap = true;
 
        // inner loop, (obviously) handles wrapping up to
        // the next newline
@@ -219,6 +222,7 @@ function &sqBodyWrap (&$body, $wrap) {
                $pos++;
            }
 
+
            // if this is a short line then just append it and continue outer loop
            if (($outStringCol + $nextNewline - $pos) <= ($wrap - $citeLevel - 1) ) {
                // if this is the final line in the input string then include
@@ -228,53 +232,60 @@ function &sqBodyWrap (&$body, $wrap) {
                    $nextNewline++;
                }
 
-               if (($nextNewline < $length && $body{$nextNewline} == "\n") && 
-                     isset($lastRealChar)) {
+               // trim trailing spaces
+               $lastRealChar = $nextNewline;
+               while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
+                   $lastRealChar--;
+               }
 
-                     // trim trailing spaces
-                     $lastRealChar = $nextNewline;
-                     while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
-                         $lastRealChar--;
-                     }
+               // decide if appending the short string is what we want
+               if (($nextNewline < $length && $body{$nextNewline} == "\n") &&
+                     isset($lastRealChar)) {
 
                      //check the first word:
-                     $mypos = $nextNewline+1;
-                     while (($mypos < $length) && ($body{$mypos} == '>')) {
-                        $mypos++;
-
-                        // skip over any spaces interleaved among the cite markers
-                        while (($mypos < $length) && ($body{$mypos} == ' ')) {
-              
+                   $mypos = $nextNewline+1;
+                   while (($mypos < $length) && ($body{$mypos} == '>')) {
+                       $mypos++;
+                       // skip over any spaces interleaved among the cite markers
+                       while (($mypos < $length) && ($body{$mypos} == ' ')) {
                            $mypos++;
-               
+                       }
+                   }
+/*
+                     $ldnspacecnt = 0;
+                     if ($mypos == $nextNewline+1) {
+                        while (($mypos < $length) && ($body{$mypos} == ' ')) {
+                         $ldnspacecnt++;
                         }
-                     }   
-                     $firstword = substr($body,$mypos,strpos($body,' ',$mypos) - $mypos);
-                     if ($firstword && ($firstword{0} == '-' ||
+                     }
+*/
+
+                   $firstword = substr($body,$mypos,strpos($body,' ',$mypos) - $mypos);
+
+                   //if ($dowrap || $ldnspacecnt > 1 || ($firstword && (
+                   if (!$smartwrap || $firstword && (
+                                        $firstword{0} == '-' ||
                                         $firstword{0} == '+' ||
                                         $firstword{0} == '*' ||
+                                        $firstword{0} == strtoupper($firstword{0}) ||
                                         strpos($firstword,':'))) {
-                         $outString .= substr($body,$pos,($lastRealChar - $pos+1));
-                         $outStringCol += ($lastRealChar - $pos);
-                         sqMakeNewLine($outString,$citeLevel,$outStringCol);
-                         $nextNewline++;
-                         $pos = $nextNewline;
-                         $outStringCol--;
-                         continue; //break 2; 
-                     }
-               }
-
+                        $outString .= substr($body,$pos,($lastRealChar - $pos+1));
+                        $outStringCol += ($lastRealChar - $pos);
+                        sqMakeNewLine($outString,$citeLevel,$outStringCol);
+                        $nextNewline++;
+                        $pos = $nextNewline;
+                        $outStringCol--;
+                        continue;
+                   }
 
-               // trim trailing spaces
-               $lastRealChar = $nextNewline;
-               while (($lastRealChar > $pos && $lastRealChar < $length) && (ctype_space ($body{$lastRealChar}))) {
-                   $lastRealChar--;
                }
+
                $outString .= substr ($body, $pos, ($lastRealChar - $pos + 1));
                $outStringCol += ($lastRealChar - $pos);
                $pos = $nextNewline + 1;
                continue;
            }
+
            $eol = $pos + $wrap - $citeLevel - $outStringCol;
            // eol is the tentative end of line.
            // look backwards for there for a whitespace to break at.
index a28d078..2cfa3dd 100644 (file)
@@ -626,8 +626,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
             $body_part_entity->header->encoding);
             if ($type1 == 'html') {
                 $bodypart = str_replace("\n", ' ', $bodypart);
-                $bodypart = preg_replace(array('/<p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
-                
+                $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart);
                 $bodypart = str_replace(array('&nbsp;','&gt;','&lt;'),array(' ','>','<'),$bodypart);
                 $bodypart = strip_tags($bodypart);
             }