XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
QpHeaderEncoder.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of SwiftMailer.
5  * (c) 2004-2009 Chris Corbyn
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10 
11 require_once dirname(__FILE__) . '/../HeaderEncoder.php';
12 require_once dirname(__FILE__) . '/../../Encoder/QpEncoder.php';
13 require_once dirname(__FILE__) . '/../../CharacterStream.php';
14 
22  implements Swift_Mime_HeaderEncoder
23 {
24 
25  private static $_headerSafeMap = array();
26 
31  public function __construct(Swift_CharacterStream $charStream)
32  {
33  parent::__construct($charStream);
34  if (empty(self::$_headerSafeMap))
35  {
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)
40  {
41  self::$_headerSafeMap[$byte] = chr($byte);
42  }
43  }
44  }
45 
51  public function getName()
52  {
53  return 'Q';
54  }
55 
63  public function encodeString($string, $firstLineOffset = 0,
64  $maxLineLength = 0)
65  {
66  return str_replace(array(' ', '=20', "=\r\n"), array('_', '_', "\r\n"),
67  parent::encodeString($string, $firstLineOffset, $maxLineLength)
68  );
69  }
70 
71  // -- Overridden points of extension
72 
79  protected function _encodeByteSequence(array $bytes, &$size)
80  {
81  $ret = '';
82  $size=0;
83  foreach ($bytes as $b)
84  {
85  if (isset(self::$_headerSafeMap[$b]))
86  {
87  $ret .= self::$_headerSafeMap[$b];
88  ++$size;
89  }
90  else
91  {
92  $ret .= self::$_qpMap[$b];
93  $size+=3;
94  }
95  }
96  return $ret;
97  }
98 
99 }