| 1 |
lars |
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 |
|
|
|
16 |
/**
|
|
|
17 |
* Handles Base 64 Transfer Encoding in Swift Mailer.
|
|
|
18 |
* @package Swift
|
|
|
19 |
* @subpackage Mime
|
|
|
20 |
* @author Chris Corbyn
|
|
|
21 |
*/
|
|
|
22 |
class Swift_Mime_ContentEncoder_Base64ContentEncoder
|
|
|
23 |
extends Swift_Encoder_Base64Encoder
|
|
|
24 |
implements Swift_Mime_ContentEncoder
|
|
|
25 |
{
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Encode stream $in to stream $out.
|
|
|
29 |
* @param Swift_OutputByteStream $in
|
|
|
30 |
* @param Swift_InputByteStream $out
|
|
|
31 |
* @param int $firstLineOffset
|
|
|
32 |
* @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
|
|
|
33 |
*/
|
|
|
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 |
|
|
|
71 |
/**
|
|
|
72 |
* Get the name of this encoding scheme.
|
|
|
73 |
* Returns the string 'base64'.
|
|
|
74 |
* @return string
|
|
|
75 |
*/
|
|
|
76 |
public function getName()
|
|
|
77 |
{
|
|
|
78 |
return 'base64';
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
}
|