From bb9773940a9f9f8f13922c065f591d1d7379328e Mon Sep 17 00:00:00 2001 From: stekkel Date: Tue, 15 Jun 2004 18:09:57 +0000 Subject: [PATCH] Tweaked wrapping a little more. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@7645 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/strings.php | 81 ++++++++++++++++++++++++------------------- src/compose.php | 3 +- 2 files changed, 47 insertions(+), 37 deletions(-) diff --git a/functions/strings.php b/functions/strings.php index 79b35f3e..924f2f1b 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -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. diff --git a/src/compose.php b/src/compose.php index a28d0782..2cfa3dd9 100644 --- a/src/compose.php +++ b/src/compose.php @@ -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('/

/i','/

<\/div>/i','//i','/<\/?div>/i'), "\n", $bodypart); - + $bodypart = preg_replace(array('/<\/?p>/i','/
<\/div>/i','//i','/<\/?div>/i'), "\n", $bodypart); $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); $bodypart = strip_tags($bodypart); } -- 2.25.1