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: * Handles Base 64 Encoding in Swift Mailer.
13: * @package Swift
14: * @subpackage Encoder
15: * @author Chris Corbyn
16: */
17: class Swift_Encoder_Base64Encoder implements Swift_Encoder
18: {
19: /**
20: * Takes an unencoded string and produces a Base64 encoded string from it.
21: * Base64 encoded strings have a maximum line length of 76 characters.
22: * If the first line needs to be shorter, indicate the difference with
23: * $firstLineOffset.
24: * @param string $string to encode
25: * @param int $firstLineOffset
26: * @param int $maxLineLength, optional, 0 indicates the default of 76 bytes
27: * @return string
28: */
29: public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
30: {
31: if (0 >= $maxLineLength || 76 < $maxLineLength) {
32: $maxLineLength = 76;
33: }
34:
35: $encodedString = base64_encode($string);
36: $firstLine = '';
37:
38: if (0 != $firstLineOffset) {
39: $firstLine = substr(
40: $encodedString, 0, $maxLineLength - $firstLineOffset
41: ) . "\r\n";
42: $encodedString = substr(
43: $encodedString, $maxLineLength - $firstLineOffset
44: );
45: }
46:
47: return $firstLine . trim(chunk_split($encodedString, $maxLineLength, "\r\n"));
48: }
49:
50: /**
51: * Does nothing.
52: */
53: public function charsetChanged($charset)
54: {
55: }
56: }
57: