From: Michael M Slusarz Date: Thu, 30 Sep 2010 22:24:39 +0000 (-0600) Subject: Add option to not wrap unquoted lines when converting to flowed X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=84c52c533e1acee6757573a54ad8dfd80611b081;p=horde.git Add option to not wrap unquoted lines when converting to flowed --- diff --git a/framework/Text_Flowed/lib/Horde/Text/Flowed.php b/framework/Text_Flowed/lib/Horde/Text/Flowed.php index 2ba93ba42..a099283e7 100644 --- a/framework/Text_Flowed/lib/Horde/Text/Flowed.php +++ b/framework/Text_Flowed/lib/Horde/Text/Flowed.php @@ -159,14 +159,19 @@ class Horde_Text_Flowed * text as described in RFC 2646. * * @param boolean $quote Add level of quoting to each line? + * @param array $opts Additional options: + *
+     * 'nowrap' - (boolean) If true, does not wrap unquoted lines.
+     *            DEFAULT: false
+     * 
* * @return string The text converted to RFC 2646 'flowed' format. */ - public function toFlowed($quote = false) + public function toFlowed($quote = false, array $opts = array()) { $txt = ''; - $this->_reformat(true, $quote); + $this->_reformat(true, $quote, empty($opts['nowrap'])); reset($this->_output); while (list(,$line) = each($this->_output)) { $txt .= $line['text'] . "\n"; @@ -181,8 +186,9 @@ class Horde_Text_Flowed * * @param boolean $toflowed Convert to flowed? * @param boolean $quote Add level of quoting to each line? + * @param boolean $wrap Wrap unquoted lines? */ - protected function _reformat($toflowed, $quote) + protected function _reformat($toflowed, $quote, $wrap = true) { $format_type = implode('|', array($toflowed, $quote)); if ($format_type == $this->_formattype) { @@ -262,7 +268,9 @@ class Horde_Text_Flowed if (empty($line)) { /* Line is empty. */ $this->_output[] = array('text' => $quotestr, 'level' => $num_quotes); - } elseif (empty($this->_maxlength) || ((Horde_String::length($line, $this->_charset) + $num_quotes) <= $this->_maxlength)) { + } elseif ((!$wrap && !$num_quotes) || + empty($this->_maxlength) || + ((Horde_String::length($line, $this->_charset) + $num_quotes) <= $this->_maxlength)) { /* Line does not require rewrapping. */ $this->_output[] = array('text' => $quotestr . $this->_stuff($line, $num_quotes, $toflowed), 'level' => $num_quotes); } else { diff --git a/framework/Text_Flowed/test/Horde/Text/Flowed/FlowedTest.php b/framework/Text_Flowed/test/Horde/Text/Flowed/FlowedTest.php index d4e3e41d6..20eb0986c 100644 --- a/framework/Text_Flowed/test/Horde/Text/Flowed/FlowedTest.php +++ b/framework/Text_Flowed/test/Horde/Text/Flowed/FlowedTest.php @@ -45,6 +45,28 @@ class Horde_Text_Flowed_FlowedTest extends PHPUnit_Framework_TestCase ); } + public function testFlowedWrap() + { + $text = <<this is a long line this is a long line this is a long line this is a long line this is a long line this is a long line +this is a long line this is a long line this is a long line this is a long line this is a long line this is a long line +EOT; + $expected = << this is a long line this is a long line this is a long line this is a +> long line this is a long line this is a long line +this is a long line this is a long line this is a long line this is a long line this is a long line this is a long line + +EOT; + + $flowed = new Horde_Text_Flowed($text); + $flowed->setMaxLength(70); + $this->assertEquals( + $expected, + $flowed->toFlowed(false, array('nowrap' => true)) + ); + + } + public function testFlowedToFixed() { $flowed = new Horde_Text_Flowed(">line 1 \n>line 2 \n>line 3");