Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  /**
   3   * Copyright 2012-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 2012-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Imap_Client
  12   */
  13  
  14  /**
  15   * Object representation of an IMAP atom (RFC 3501 [4.1]).
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2012-2017 Horde LLC
  20   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  21   * @package   Imap_Client
  22   */
  23  class Horde_Imap_Client_Data_Format_Atom extends Horde_Imap_Client_Data_Format
  24  {
  25      /**
  26       */
  27      public function escape()
  28      {
  29          return strlen($this->_data)
  30              ? parent::escape()
  31              : '""';
  32      }
  33  
  34      /**
  35       */
  36      public function verify()
  37      {
  38          if (strlen($this->_data) !== strlen($this->stripNonAtomCharacters())) {
  39              throw new Horde_Imap_Client_Data_Format_Exception('Illegal character in IMAP atom.');
  40          }
  41      }
  42  
  43      /**
  44       * Strip out any characters that are not allowed in an IMAP atom.
  45       *
  46       * @return string  The atom data disallowed characters removed.
  47       */
  48      public function stripNonAtomCharacters()
  49      {
  50          return str_replace(
  51              array('(', ')', '{', ' ', '%', '*', '"', '\\', ']'),
  52              '',
  53              preg_replace('/[^\x20-\x7e]/', '', $this->_data)
  54          );
  55      }
  56  
  57  }