|
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 |
|
12 /** |
|
13 * Handles Base 64 Transfer Encoding in Swift Mailer. |
|
14 * @package Swift |
|
15 * @subpackage Mime |
|
16 * @author Chris Corbyn |
|
17 */ |
|
18 class Swift_Mime_ContentEncoder_Base64ContentEncoder |
|
19 extends Swift_Encoder_Base64Encoder |
|
20 implements Swift_Mime_ContentEncoder |
|
21 { |
|
22 |
|
23 /** |
|
24 * Encode stream $in to stream $out. |
|
25 * @param Swift_OutputByteStream $in |
|
26 * @param Swift_InputByteStream $out |
|
27 * @param int $firstLineOffset |
|
28 * @param int $maxLineLength, optional, 0 indicates the default of 76 bytes |
|
29 */ |
|
30 public function encodeByteStream( |
|
31 Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, |
|
32 $maxLineLength = 0) |
|
33 { |
|
34 if (0 >= $maxLineLength || 76 < $maxLineLength) |
|
35 { |
|
36 $maxLineLength = 76; |
|
37 } |
|
38 |
|
39 $remainder = 0; |
|
40 |
|
41 while (false !== $bytes = $os->read(8190)) |
|
42 { |
|
43 $encoded = base64_encode($bytes); |
|
44 $encodedTransformed = ''; |
|
45 $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset; |
|
46 |
|
47 while ($thisMaxLineLength < strlen($encoded)) |
|
48 { |
|
49 $encodedTransformed .= substr($encoded, 0, $thisMaxLineLength) . "\r\n"; |
|
50 $firstLineOffset = 0; |
|
51 $encoded = substr($encoded, $thisMaxLineLength); |
|
52 $thisMaxLineLength = $maxLineLength; |
|
53 $remainder = 0; |
|
54 } |
|
55 |
|
56 if (0 < $remainingLength = strlen($encoded)) |
|
57 { |
|
58 $remainder += $remainingLength; |
|
59 $encodedTransformed .= $encoded; |
|
60 $encoded = null; |
|
61 } |
|
62 |
|
63 $is->write($encodedTransformed); |
|
64 } |
|
65 } |
|
66 |
|
67 /** |
|
68 * Get the name of this encoding scheme. |
|
69 * Returns the string 'base64'. |
|
70 * @return string |
|
71 */ |
|
72 public function getName() |
|
73 { |
|
74 return 'base64'; |
|
75 } |
|
76 |
|
77 } |