XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
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 
11 //@require 'Swift/Mime/ContentEncoder.php';
12 //@require 'Swift/Encoder/QpEncoder.php';
13 //@require 'Swift/InputByteStrean.php';
14 //@require 'Swift/OutputByteStream.php';
15 //@require 'Swift/CharacterStream.php';
16 
24  implements Swift_Mime_ContentEncoder
25 {
26 
32  public function __construct(Swift_CharacterStream $charStream,
33  Swift_StreamFilter $filter = null)
34  {
35  parent::__construct($charStream, $filter);
36  }
37 
48  public function encodeByteStream(
49  Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
50  $maxLineLength = 0)
51  {
52  if ($maxLineLength > 76 || $maxLineLength <= 0)
53  {
54  $maxLineLength = 76;
55  }
56 
57  $thisLineLength = $maxLineLength - $firstLineOffset;
58 
59  $this->_charStream->flushContents();
60  $this->_charStream->importByteStream($os);
61 
62  $currentLine = '';
63  $prepend = '';
64  $size=$lineLen=0;
65 
66  while (false !== $bytes = $this->_nextSequence())
67  {
68  //If we're filtering the input
69  if (isset($this->_filter))
70  {
71  //If we can't filter because we need more bytes
72  while ($this->_filter->shouldBuffer($bytes))
73  {
74  //Then collect bytes into the buffer
75  if (false === $moreBytes = $this->_nextSequence(1))
76  {
77  break;
78  }
79 
80  foreach ($moreBytes as $b)
81  {
82  $bytes[] = $b;
83  }
84  }
85  //And filter them
86  $bytes = $this->_filter->filter($bytes);
87  }
88 
89  $enc = $this->_encodeByteSequence($bytes, $size);
90  if ($currentLine && $lineLen+$size >= $thisLineLength)
91  {
92  $is->write($prepend . $this->_standardize($currentLine));
93  $currentLine = '';
94  $prepend = "=\r\n";
95  $thisLineLength = $maxLineLength;
96  $lineLen=0;
97  }
98  $lineLen+=$size;
99  $currentLine .= $enc;
100  }
101  if (strlen($currentLine))
102  {
103  $is->write($prepend . $this->_standardize($currentLine));
104  }
105  }
106 
112  public function getName()
113  {
114  return 'quoted-printable';
115  }
116 
117 }