XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
Base64ContentEncoder.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/Base64Encoder.php';
13 //@require 'Swift/InputByteStream.php';
14 //@require 'Swift/OutputByteStream.php';
15 
24  implements Swift_Mime_ContentEncoder
25 {
26 
34  public function encodeByteStream(
35  Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
36  $maxLineLength = 0)
37  {
38  if (0 >= $maxLineLength || 76 < $maxLineLength)
39  {
40  $maxLineLength = 76;
41  }
42 
43  $remainder = 0;
44 
45  while (false !== $bytes = $os->read(8190))
46  {
47  $encoded = base64_encode($bytes);
48  $encodedTransformed = '';
49  $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset;
50 
51  while ($thisMaxLineLength < strlen($encoded))
52  {
53  $encodedTransformed .= substr($encoded, 0, $thisMaxLineLength) . "\r\n";
54  $firstLineOffset = 0;
55  $encoded = substr($encoded, $thisMaxLineLength);
56  $thisMaxLineLength = $maxLineLength;
57  $remainder = 0;
58  }
59 
60  if (0 < $remainingLength = strlen($encoded))
61  {
62  $remainder += $remainingLength;
63  $encodedTransformed .= $encoded;
64  $encoded = null;
65  }
66 
67  $is->write($encodedTransformed);
68  }
69  }
70 
76  public function getName()
77  {
78  return 'base64';
79  }
80 
81 }