XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Encoder.php';
12 //@require 'Swift/CharacterStream.php';
13 
21 {
22 
28  private $_charStream;
29 
34  public function __construct(Swift_CharacterStream $charStream)
35  {
36  $this->_charStream = $charStream;
37  }
38 
47  public function encodeString($string, $firstLineOffset = 0,
48  $maxLineLength = 0)
49  {
50  $lines = array(); $lineCount = 0;
51  $lines[] = '';
52  $currentLine =& $lines[$lineCount++];
53 
54  if (0 >= $maxLineLength)
55  {
56  $maxLineLength = 75;
57  }
58 
59  $this->_charStream->flushContents();
60  $this->_charStream->importString($string);
61 
62  $thisLineLength = $maxLineLength - $firstLineOffset;
63 
64  while (false !== $char = $this->_charStream->read(4))
65  {
66  $encodedChar = rawurlencode($char);
67  if (0 != strlen($currentLine)
68  && strlen($currentLine . $encodedChar) > $thisLineLength)
69  {
70  $lines[] = '';
71  $currentLine =& $lines[$lineCount++];
72  $thisLineLength = $maxLineLength;
73  }
74  $currentLine .= $encodedChar;
75  }
76 
77  return implode("\r\n", $lines);
78  }
79 
84  public function charsetChanged($charset)
85  {
86  $this->_charStream->setCharacterSet($charset);
87  }
88 
89 }