Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  /**
   3   * Copyright 2015-2017 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file LICENSE for license information (LGPL). If you
   6   * did not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @category  Horde
   9   * @copyright 2015-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Mime
  12   */
  13  
  14  /**
  15   * This class represents the Content-Transfer-Encoding header value (RFC 2045
  16   * [6]).
  17   *
  18   * @author    Michael Slusarz <slusarz@horde.org>
  19   * @category  Horde
  20   * @copyright 2015-2017 Horde LLC
  21   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  22   * @package   Mime
  23   * @since     2.8.0
  24   */
  25  class Horde_Mime_Headers_ContentTransferEncoding
  26  extends Horde_Mime_Headers_Element_Single
  27  implements Horde_Mime_Headers_Extension_Mime
  28  {
  29      /** Default encoding (RFC 2045 [6.1]). */
  30      const DEFAULT_ENCODING = '7bit';
  31  
  32      /** Unknown encoding specifier. */
  33      const UNKNOWN_ENCODING = 'x-unknown';
  34  
  35      /**
  36       */
  37      public function __construct($name, $value)
  38      {
  39          if (!strlen($value)) {
  40              $value = self::DEFAULT_ENCODING;
  41          }
  42  
  43          parent::__construct('Content-Transfer-Encoding', $value);
  44      }
  45  
  46      /**
  47       */
  48      protected function _setValue($value)
  49      {
  50          parent::_setValue(trim($value));
  51  
  52          $val = $this->value;
  53          $encoding = Horde_String::lower($val);
  54  
  55          switch ($encoding) {
  56          case '7bit':
  57          case '8bit':
  58          case 'base64':
  59          case 'binary':
  60          case 'quoted-printable':
  61              // Valid encodings
  62              break;
  63  
  64          default:
  65              /* RFC 2045 [6.3] - Valid non-standardized encodings must begin
  66               * with 'x-'. */
  67              if (substr($encoding, 0, 2) !== 'x-') {
  68                  $encoding = self::UNKNOWN_ENCODING;
  69              }
  70              break;
  71          }
  72  
  73          if ($encoding !== $val) {
  74              parent::_setValue($encoding);
  75          }
  76      }
  77  
  78      /**
  79       */
  80      public function isDefault()
  81      {
  82          return ($this->value === self::DEFAULT_ENCODING);
  83      }
  84  
  85      /**
  86       */
  87      public static function getHandles()
  88      {
  89          return array(
  90              // MIME: RFC 2045
  91              'content-transfer-encoding'
  92          );
  93      }
  94  
  95  }