[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/Swiftmailer/classes/Swift/Mime/ContentEncoder/ -> QpContentEncoder.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 Quoted Printable (QP) Transfer Encoding in Swift Mailer.
  13   *
  14   * @author Chris Corbyn
  15   */
  16  class Swift_Mime_ContentEncoder_QpContentEncoder extends Swift_Encoder_QpEncoder implements Swift_Mime_ContentEncoder
  17  {
  18      protected $_dotEscape;
  19  
  20      /**
  21       * Creates a new QpContentEncoder for the given CharacterStream.
  22       *
  23       * @param Swift_CharacterStream $charStream to use for reading characters
  24       * @param Swift_StreamFilter    $filter     if canonicalization should occur
  25       * @param bool                  $dotEscape  if dot stuffing workaround must be enabled
  26       */
  27      public function __construct(Swift_CharacterStream $charStream, Swift_StreamFilter $filter = null, $dotEscape = false)
  28      {
  29          $this->_dotEscape = $dotEscape;
  30          parent::__construct($charStream, $filter);
  31      }
  32  
  33      public function __sleep()
  34      {
  35          return array('_charStream', '_filter', '_dotEscape');
  36      }
  37  
  38      protected function getSafeMapShareId()
  39      {
  40          return get_class($this).($this->_dotEscape ? '.dotEscape' : '');
  41      }
  42  
  43      protected function initSafeMap()
  44      {
  45          parent::initSafeMap();
  46          if ($this->_dotEscape) {
  47              /* Encode . as =2e for buggy remote servers */
  48              unset($this->_safeMap[0x2e]);
  49          }
  50      }
  51  
  52      /**
  53       * Encode stream $in to stream $out.
  54       *
  55       * QP encoded strings have a maximum line length of 76 characters.
  56       * If the first line needs to be shorter, indicate the difference with
  57       * $firstLineOffset.
  58       *
  59       * @param Swift_OutputByteStream $os              output stream
  60       * @param Swift_InputByteStream  $is              input stream
  61       * @param int                    $firstLineOffset
  62       * @param int                    $maxLineLength
  63       */
  64      public function encodeByteStream(Swift_OutputByteStream $os, Swift_InputByteStream $is, $firstLineOffset = 0, $maxLineLength = 0)
  65      {
  66          if ($maxLineLength > 76 || $maxLineLength <= 0) {
  67              $maxLineLength = 76;
  68          }
  69  
  70          $thisLineLength = $maxLineLength - $firstLineOffset;
  71  
  72          $this->_charStream->flushContents();
  73          $this->_charStream->importByteStream($os);
  74  
  75          $currentLine = '';
  76          $prepend = '';
  77          $size = $lineLen = 0;
  78  
  79          while (false !== $bytes = $this->_nextSequence()) {
  80              // If we're filtering the input
  81              if (isset($this->_filter)) {
  82                  // If we can't filter because we need more bytes
  83                  while ($this->_filter->shouldBuffer($bytes)) {
  84                      // Then collect bytes into the buffer
  85                      if (false === $moreBytes = $this->_nextSequence(1)) {
  86                          break;
  87                      }
  88  
  89                      foreach ($moreBytes as $b) {
  90                          $bytes[] = $b;
  91                      }
  92                  }
  93                  // And filter them
  94                  $bytes = $this->_filter->filter($bytes);
  95              }
  96  
  97              $enc = $this->_encodeByteSequence($bytes, $size);
  98              if ($currentLine && $lineLen + $size >= $thisLineLength) {
  99                  $is->write($prepend.$this->_standardize($currentLine));
 100                  $currentLine = '';
 101                  $prepend = "=\r\n";
 102                  $thisLineLength = $maxLineLength;
 103                  $lineLen = 0;
 104              }
 105              $lineLen += $size;
 106              $currentLine .= $enc;
 107          }
 108          if (strlen($currentLine)) {
 109              $is->write($prepend.$this->_standardize($currentLine));
 110          }
 111      }
 112  
 113      /**
 114       * Get the name of this encoding scheme.
 115       * Returns the string 'quoted-printable'.
 116       *
 117       * @return string
 118       */
 119      public function getName()
 120      {
 121          return 'quoted-printable';
 122      }
 123  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1