TYPO3  7.6
QpContentEncoder.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 
17 {
18  protected $_dotEscape;
19 
27  public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null, $dotEscape = false)
28  {
29  $this->_dotEscape = $dotEscape;
30  parent::__construct($charStream, $filter);
31  }
32 
33  public function __sleep()
34  {
35  return array('_charStream', '_filter', '_dotEscape');
36  }
37 
38  protected function getSafeMapShareId()
39  {
40  return get_class($this).($this->_dotEscape ? '.dotEscape' : '');
41  }
42 
43  protected function initSafeMap()
44  {
45  parent::initSafeMap();
46  if ($this->_dotEscape) {
47  /* Encode . as =2e for buggy remote servers */
48  unset($this->_safeMap[0x2e]);
49  }
50  }
51 
64  public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
65  {
66  if ($maxLineLength > 76 || $maxLineLength <= 0) {
67  $maxLineLength = 76;
68  }
69 
70  $thisLineLength = $maxLineLength - $firstLineOffset;
71 
72  $this->_charStream->flushContents();
73  $this->_charStream->importByteStream($os);
74 
75  $currentLine = '';
76  $prepend = '';
77  $size = $lineLen = 0;
78 
79  while (false !== $bytes = $this->_nextSequence()) {
80  // If we're filtering the input
81  if (isset($this->_filter)) {
82  // If we can't filter because we need more bytes
83  while ($this->_filter->shouldBuffer($bytes)) {
84  // Then collect bytes into the buffer
85  if (false === $moreBytes = $this->_nextSequence(1)) {
86  break;
87  }
88 
89  foreach ($moreBytes as $b) {
90  $bytes[] = $b;
91  }
92  }
93  // And filter them
94  $bytes = $this->_filter->filter($bytes);
95  }
96 
97  $enc = $this->_encodeByteSequence($bytes, $size);
98  if ($currentLine && $lineLen + $size >= $thisLineLength) {
99  $is->write($prepend.$this->_standardize($currentLine));
100  $currentLine = '';
101  $prepend = "=\r\n";
102  $thisLineLength = $maxLineLength;
103  $lineLen = 0;
104  }
105  $lineLen += $size;
106  $currentLine .= $enc;
107  }
108  if (strlen($currentLine)) {
109  $is->write($prepend.$this->_standardize($currentLine));
110  }
111  }
112 
119  public function getName()
120  {
121  return 'quoted-printable';
122  }
123 }