QP encoded strings have a maximum line length of 76 characters.
If the first line needs to be shorter, indicate the difference with
$firstLineOffset.
public encodeByteStream ( Swift_OutputByteStream $os, Swift_InputByteStream $is, integer $firstLineOffset, integer $maxLineLength ) | ||
$os | Swift_OutputByteStream | output stream |
$is | Swift_InputByteStream | input stream |
$firstLineOffset | integer | |
$maxLineLength | integer |
public function testEncodingAndDecodingSamples() { $sampleFp = opendir($this->_samplesDir); while (false !== ($encodingDir = readdir($sampleFp))) { if (substr($encodingDir, 0, 1) == '.') { continue; } $encoding = $encodingDir; $charStream = new Swift_CharacterStream_NgCharacterStream($this->_factory, $encoding); $encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream); $sampleDir = $this->_samplesDir . '/' . $encodingDir; if (is_dir($sampleDir)) { $fileFp = opendir($sampleDir); while (false !== ($sampleFile = readdir($fileFp))) { if (substr($sampleFile, 0, 1) == '.') { continue; } $text = file_get_contents($sampleDir . '/' . $sampleFile); $os = new Swift_ByteStream_ArrayByteStream(); $os->write($text); $is = new Swift_ByteStream_ArrayByteStream(); $encoder->encodeByteStream($os, $is); $encoded = ''; while (false !== ($bytes = $is->read(8192))) { $encoded .= $bytes; } $this->assertEquals(quoted_printable_decode($encoded), $text, '%s: Encoded string should decode back to original string for sample ' . $sampleDir . '/' . $sampleFile); } closedir($fileFp); } } closedir($sampleFp); }
public function testFirstLineLengthCanBeDifferent() { $os = $this->_createOutputByteStream(true); $charStream = $this->_createCharacterStream(); $is = $this->_createInputByteStream(); $collection = new Swift_StreamCollector(); $is->shouldReceive('write')->zeroOrMoreTimes()->andReturnUsing($collection); $charStream->shouldReceive('flushContents')->once(); $charStream->shouldReceive('importByteStream')->once()->with($os); for ($seq = 0; $seq <= 140; ++$seq) { $charStream->shouldReceive('readBytes')->once()->andReturn(array(ord('a'))); } $charStream->shouldReceive('readBytes')->zeroOrMoreTimes()->andReturn(false); $encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream); $encoder->encodeByteStream($os, $is, 22); $this->assertEquals(str_repeat('a', 53) . "=\r\n" . str_repeat('a', 75) . "=\r\n" . str_repeat('a', 13), $collection->content); }
public function testFirstLineLengthCanBeDifferent() { $os = $this->_createOutputByteStream(true); $charStream = $this->_createCharacterStream(); $is = $this->_createInputByteStream(); $collection = new Swift_StreamCollector(); $this->_checking(Expectations::create()->one($charStream)->flushContents()->one($charStream)->importByteStream($os)->allowing($is)->write(any(), optional())->will($collection)->ignoring($is)->ignoring($os)); for ($seq = 0; $seq <= 140; ++$seq) { $this->_checking(Expectations::create()->one($charStream)->readBytes(any())->returns(array(ord('a')))); } $this->_checking(Expectations::create()->one($charStream)->readBytes(any())->returns(false)); $encoder = new Swift_Mime_ContentEncoder_QpContentEncoder($charStream); $encoder->encodeByteStream($os, $is, 22); $this->assertEqual(str_repeat('a', 53) . "=\r\n" . str_repeat('a', 75) . "=\r\n" . str_repeat('a', 13), $collection->content); }