Merge branch 'maint/7.0'
[ninja.git] / application / vendor / swiftmailer / classes / Swift / Mime / ContentEncoder / Base64ContentEncoder.php
blobe89938ef8b1d8371a143eb2b73e57a050fdcc542
1 <?php
3 /*
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.
9 */
11 //@require 'Swift/Mime/ContentEncoder.php';
12 //@require 'Swift/Encoder/Base64Encoder.php';
13 //@require 'Swift/InputByteStream.php';
14 //@require 'Swift/OutputByteStream.php';
16 /**
17 * Handles Base 64 Transfer Encoding in Swift Mailer.
18 * @package Swift
19 * @subpackage Mime
20 * @author Chris Corbyn
22 class Swift_Mime_ContentEncoder_Base64ContentEncoder
23 extends Swift_Encoder_Base64Encoder
24 implements Swift_Mime_ContentEncoder
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
34 public function encodeByteStream(
35 Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0,
36 $maxLineLength = 0)
38 if (0 >= $maxLineLength || 76 < $maxLineLength)
40 $maxLineLength = 76;
43 $remainder = 0;
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";
54 $firstLineOffset = 0;
55 $encoded = substr($encoded, $thisMaxLineLength);
56 $thisMaxLineLength = $maxLineLength;
57 $remainder = 0;
60 if (0 < $remainingLength = strlen($encoded))
62 $remainder += $remainingLength;
63 $encodedTransformed .= $encoded;
64 $encoded = null;
67 $is->write($encodedTransformed);
71 /**
72 * Get the name of this encoding scheme.
73 * Returns the string 'base64'.
74 * @return string
76 public function getName()
78 return 'base64';