|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This file is part of SwiftMailer. 00005 * (c) 2004-2009 Chris Corbyn 00006 * 00007 * For the full copyright and license information, please view the LICENSE 00008 * file that was distributed with this source code. 00009 */ 00010 00011 //@require 'Swift/Mime/ContentEncoder.php'; 00012 //@require 'Swift/Encoder/Base64Encoder.php'; 00013 //@require 'Swift/InputByteStream.php'; 00014 //@require 'Swift/OutputByteStream.php'; 00015 00016 /** 00017 * Handles Base 64 Transfer Encoding in Swift Mailer. 00018 * @package Swift 00019 * @subpackage Mime 00020 * @author Chris Corbyn 00021 */ 00022 class Swift_Mime_ContentEncoder_Base64ContentEncoder 00023 extends Swift_Encoder_Base64Encoder 00024 implements Swift_Mime_ContentEncoder 00025 { 00026 00027 /** 00028 * Encode stream $in to stream $out. 00029 * @param Swift_OutputByteStream $in 00030 * @param Swift_InputByteStream $out 00031 * @param int $firstLineOffset 00032 * @param int $maxLineLength, optional, 0 indicates the default of 76 bytes 00033 */ 00034 public function encodeByteStream( 00035 Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, 00036 $maxLineLength = 0) 00037 { 00038 if (0 >= $maxLineLength || 76 < $maxLineLength) 00039 { 00040 $maxLineLength = 76; 00041 } 00042 00043 $remainder = 0; 00044 00045 while (false !== $bytes = $os->read(8190)) 00046 { 00047 $encoded = base64_encode($bytes); 00048 $encodedTransformed = ''; 00049 $thisMaxLineLength = $maxLineLength - $remainder - $firstLineOffset; 00050 00051 while ($thisMaxLineLength < strlen($encoded)) 00052 { 00053 $encodedTransformed .= substr($encoded, 0, $thisMaxLineLength) . "\r\n"; 00054 $firstLineOffset = 0; 00055 $encoded = substr($encoded, $thisMaxLineLength); 00056 $thisMaxLineLength = $maxLineLength; 00057 $remainder = 0; 00058 } 00059 00060 if (0 < $remainingLength = strlen($encoded)) 00061 { 00062 $remainder += $remainingLength; 00063 $encodedTransformed .= $encoded; 00064 $encoded = null; 00065 } 00066 00067 $is->write($encodedTransformed); 00068 } 00069 } 00070 00071 /** 00072 * Get the name of this encoding scheme. 00073 * Returns the string 'base64'. 00074 * @return string 00075 */ 00076 public function getName() 00077 { 00078 return 'base64'; 00079 } 00080 00081 }
1.8.0