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_once dirname(__FILE__
) . '/../HeaderEncoder.php';
12 require_once dirname(__FILE__
) . '/../../Encoder/QpEncoder.php';
13 require_once dirname(__FILE__
) . '/../../CharacterStream.php';
16 * Handles Quoted Printable (Q) Header Encoding in Swift Mailer.
19 * @author Chris Corbyn
21 class Swift_Mime_HeaderEncoder_QpHeaderEncoder
extends Swift_Encoder_QpEncoder
22 implements Swift_Mime_HeaderEncoder
25 private static $_headerSafeMap = array();
28 * Creates a new QpHeaderEncoder for the given CharacterStream.
29 * @param Swift_CharacterStream $charStream to use for reading characters
31 public function __construct(Swift_CharacterStream
$charStream)
33 parent
::__construct($charStream);
34 if (empty(self
::$_headerSafeMap))
37 range(0x61, 0x7A), range(0x41, 0x5A),
38 range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
41 self
::$_headerSafeMap[$byte] = chr($byte);
47 * Get the name of this encoding scheme.
48 * Returns the string 'Q'.
51 public function getName()
57 * Takes an unencoded string and produces a Q encoded string from it.
58 * @param string $string to encode
59 * @param int $firstLineOffset, optional
60 * @param int $maxLineLength, optional, 0 indicates the default of 76 chars
63 public function encodeString($string, $firstLineOffset = 0,
66 return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
67 parent
::encodeString($string, $firstLineOffset, $maxLineLength)
71 // -- Overridden points of extension
74 * Encode the given byte array into a verbatim QP form.
79 protected function _encodeByteSequence(array $bytes, &$size)
83 foreach ($bytes as $b)
85 if (isset(self
::$_headerSafeMap[$b]))
87 $ret .= self
::$_headerSafeMap[$b];
92 $ret .= self
::$_qpMap[$b];