4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 //@require 'Swift/Mime/ContentEncoder.php';
12 //@require 'Swift/Encoder/Base64Encoder.php';
13 //@require 'Swift/InputByteStream.php';
14 //@require 'Swift/OutputByteStream.php';
17 * Handles Base 64 Transfer Encoding in Swift Mailer.
20 * @author Chris Corbyn
22 class Swift_Mime_ContentEncoder_Base64ContentEncoder
23 extends Swift_Encoder_Base64Encoder
24 implements Swift_Mime_ContentEncoder
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
34 public function encodeByteStream(
35 Swift_OutputByteStream
$os, Swift_InputByteStream
$is, $firstLineOffset = 0,
38 if (0 >= $maxLineLength ||
76 < $maxLineLength)
45 while (false !== $bytes = $os->read(8190))
47 $encoded = base64_encode($bytes);
48 $encodedTransformed = '';
49 $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset;
51 while ($thisMaxLineLength < strlen($encoded))
53 $encodedTransformed .= substr($encoded, 0, $thisMaxLineLength) . "\r\n";
55 $encoded = substr($encoded, $thisMaxLineLength);
56 $thisMaxLineLength = $maxLineLength;
60 if (0 < $remainingLength = strlen($encoded))
62 $remainder +
= $remainingLength;
63 $encodedTransformed .= $encoded;
67 $is->write($encodedTransformed);
72 * Get the name of this encoding scheme.
73 * Returns the string 'base64'.
76 public function getName()