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