[ Index ]

MailPress 7.2

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/composer/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Encoder/ -> Rfc2231Encoder.php (source)

   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 RFC 2231 specified Encoding in Swift Mailer.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Encoder_Rfc2231Encoder implements Swift_Encoder
  17  {
  18      /**
  19       * A character stream to use when reading a string as characters instead of bytes.
  20       *
  21       * @var Swift_CharacterStream
  22       */
  23      private $charStream;
  24  
  25      /**
  26       * Creates a new Rfc2231Encoder using the given character stream instance.
  27       */
  28      public function __construct(Swift_CharacterStream $charStream)
  29      {
  30          $this->charStream = $charStream;
  31      }
  32  
  33      /**
  34       * Takes an unencoded string and produces a string encoded according to
  35       * RFC 2231 from it.
  36       *
  37       * @param string $string
  38       * @param int    $firstLineOffset
  39       * @param int    $maxLineLength   optional, 0 indicates the default of 75 bytes
  40       *
  41       * @return string
  42       */
  43      public function encodeString($string, $firstLineOffset = 0, $maxLineLength = 0)
  44      {
  45          $lines = [];
  46          $lineCount = 0;
  47          $lines[] = '';
  48          $currentLine = &$lines[$lineCount++];
  49  
  50          if (0 >= $maxLineLength) {
  51              $maxLineLength = 75;
  52          }
  53  
  54          $this->charStream->flushContents();
  55          $this->charStream->importString($string);
  56  
  57          $thisLineLength = $maxLineLength - $firstLineOffset;
  58  
  59          while (false !== $char = $this->charStream->read(4)) {
  60              $encodedChar = rawurlencode($char);
  61              if (0 != strlen($currentLine)
  62                  && strlen($currentLine.$encodedChar) > $thisLineLength) {
  63                  $lines[] = '';
  64                  $currentLine = &$lines[$lineCount++];
  65                  $thisLineLength = $maxLineLength;
  66              }
  67              $currentLine .= $encodedChar;
  68          }
  69  
  70          return implode("\r\n", $lines);
  71      }
  72  
  73      /**
  74       * Updates the charset used.
  75       *
  76       * @param string $charset
  77       */
  78      public function charsetChanged($charset)
  79      {
  80          $this->charStream->setCharacterSet($charset);
  81      }
  82  
  83      /**
  84       * Make a deep copy of object.
  85       */
  86      public function __clone()
  87      {
  88          $this->charStream = clone $this->charStream;
  89      }
  90  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1