4
* This file is part of SwiftMailer.
5
* (c) 2004-2009 Chris Corbyn
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
11
//@require 'Swift/Mime/ContentEncoder.php';
12
//@require 'Swift/Encoder/QpEncoder.php';
13
//@require 'Swift/InputByteStrean.php';
14
//@require 'Swift/OutputByteStream.php';
15
//@require 'Swift/CharacterStream.php';
18
* Handles Quoted Printable (QP) Transfer Encoding in Swift Mailer.
21
* @author Chris Corbyn
23
class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder
24
implements Swift_Mime_ContentEncoder
28
* Creates a new QpContentEncoder for the given CharacterStream.
29
* @param Swift_CharacterStream $charStream to use for reading characters
30
* @param Swift_StreamFilter $filter if canonicalization should occur
32
public function __construct(Swift_CharacterStream $charStream,
33
Swift_StreamFilter $filter = null)
35
parent::__construct($charStream, $filter);
39
* Encode stream $in to stream $out.
40
* QP encoded strings have a maximum line length of 76 characters.
41
* If the first line needs to be shorter, indicate the difference with
43
* @param Swift_OutputByteStream $os output stream
44
* @param Swift_InputByteStream $is input stream
45
* @param int $firstLineOffset
46
* @param int $maxLineLength
48
public function encodeByteStream(
49
Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
52
if ($maxLineLength > 76 || $maxLineLength <= 0)
57
$thisLineLength = $maxLineLength - $firstLineOffset;
59
$this->_charStream->flushContents();
60
$this->_charStream->importByteStream($os);
66
while (false !== $bytes = $this->_nextSequence())
68
//If we're filtering the input
69
if (isset($this->_filter))
71
//If we can't filter because we need more bytes
72
while ($this->_filter->shouldBuffer($bytes))
74
//Then collect bytes into the buffer
75
if (false === $moreBytes = $this->_nextSequence(1))
80
foreach ($moreBytes as $b)
86
$bytes = $this->_filter->filter($bytes);
89
$enc = $this->_encodeByteSequence($bytes, $size);
90
if ($currentLine && $lineLen+$size >= $thisLineLength)
92
$is->write($prepend . $this->_standardize($currentLine));
95
$thisLineLength = $maxLineLength;
101
if (strlen($currentLine))
103
$is->write($prepend . $this->_standardize($currentLine));
108
* Get the name of this encoding scheme.
109
* Returns the string 'quoted-printable'.
112
public function getName()
114
return 'quoted-printable';