TYPO3  7.6
Rfc2231Encoder.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 {
23  private $_charStream;
24 
30  public function __construct(Swift_CharacterStream $charStream)
31  {
32  $this->_charStream = $charStream;
33  }
34 
45  public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
46  {
47  $lines = array();
48  $lineCount = 0;
49  $lines[] = '';
50  $currentLine = &$lines[$lineCount++];
51 
52  if (0 >= $maxLineLength) {
53  $maxLineLength = 75;
54  }
55 
56  $this->_charStream->flushContents();
57  $this->_charStream->importString($string);
58 
59  $thisLineLength = $maxLineLength - $firstLineOffset;
60 
61  while (false !== $char = $this->_charStream->read(4)) {
62  $encodedChar = rawurlencode($char);
63  if (0 != strlen($currentLine)
64  && strlen($currentLine.$encodedChar) > $thisLineLength) {
65  $lines[] = '';
66  $currentLine = &$lines[$lineCount++];
67  $thisLineLength = $maxLineLength;
68  }
69  $currentLine .= $encodedChar;
70  }
71 
72  return implode("\r\n", $lines);
73  }
74 
80  public function charsetChanged($charset)
81  {
82  $this->_charStream->setCharacterSet($charset);
83  }
84 
88  public function __clone()
89  {
90  $this->_charStream = clone $this->_charStream;
91  }
92 }