Avail feature updated
[ninja.git] / application / vendor / swiftmailer / classes / Swift / Mime / HeaderEncoder / QpHeaderEncoder.php
blobd727da0272f10c6936a30ea6a04bd35c31c7fc1e
1 <?php
3 /*
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.
9 */
11 require_once dirname(__FILE__) . '/../HeaderEncoder.php';
12 require_once dirname(__FILE__) . '/../../Encoder/QpEncoder.php';
13 require_once dirname(__FILE__) . '/../../CharacterStream.php';
15 /**
16 * Handles Quoted Printable (Q) Header Encoding in Swift Mailer.
17 * @package Swift
18 * @subpackage Mime
19 * @author Chris Corbyn
21 class Swift_Mime_HeaderEncoder_QpHeaderEncoder extends Swift_Encoder_QpEncoder
22 implements Swift_Mime_HeaderEncoder
25 private static $_headerSafeMap = array();
27 /**
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))
36 foreach (array_merge(
37 range(0x61, 0x7A), range(0x41, 0x5A),
38 range(0x30, 0x39), array(0x20, 0x21, 0x2A, 0x2B, 0x2D, 0x2F)
39 ) as $byte)
41 self::$_headerSafeMap[$byte] = chr($byte);
46 /**
47 * Get the name of this encoding scheme.
48 * Returns the string 'Q'.
49 * @return string
51 public function getName()
53 return 'Q';
56 /**
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
61 * @return string
63 public function encodeString($string, $firstLineOffset = 0,
64 $maxLineLength = 0)
66 return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
67 parent::encodeString($string, $firstLineOffset, $maxLineLength)
71 // -- Overridden points of extension
73 /**
74 * Encode the given byte array into a verbatim QP form.
75 * @param int[] $bytes
76 * @return string
77 * @access protected
79 protected function _encodeByteSequence(array $bytes, &$size)
81 $ret = '';
82 $size=0;
83 foreach ($bytes as $b)
85 if (isset(self::$_headerSafeMap[$b]))
87 $ret .= self::$_headerSafeMap[$b];
88 ++$size;
90 else
92 $ret .= self::$_qpMap[$b];
93 $size+=3;
96 return $ret;