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 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 mailbox string (RFC 3501 [9]).
  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_Mailbox
  24  extends Horde_Imap_Client_Data_Format_Astring
  25  {
  26      /**
  27       * Mailbox encoding.
  28       *
  29       * @var string
  30       */
  31      protected $_encoding = 'utf7imap';
  32  
  33      /**
  34       * Mailbox object.
  35       *
  36       * @var Horde_Imap_Client_Mailbox
  37       */
  38      protected $_mailbox;
  39  
  40      /**
  41       * @param mixed $data  Either a mailbox object or a UTF-8 mailbox name.
  42       */
  43      public function __construct($data)
  44      {
  45          $this->_mailbox = Horde_Imap_Client_Mailbox::get($data);
  46  
  47          parent::__construct($this->_mailbox->{$this->_encoding});
  48      }
  49  
  50      /**
  51       */
  52      public function __toString()
  53      {
  54          return strval($this->_mailbox);
  55      }
  56  
  57      /**
  58       */
  59      public function getData()
  60      {
  61          return $this->_mailbox;
  62      }
  63  
  64      /**
  65       * @throws Horde_Imap_Client_Exception
  66       */
  67      public function binary()
  68      {
  69          if (parent::binary()) {
  70              // Mailbox data can NEVER be sent as binary.
  71              /* @todo: Disable until Horde_Imap_Client 3.0 */
  72              // throw new Horde_Imap_Client_Exception(
  73              //     'Client error: can not send mailbox to IMAP server as binary data.'
  74              // );
  75  
  76              // Temporary fix: send a blank mailbox string.
  77              $this->_mailbox = Horde_Imap_Client_Mailbox::get('');
  78          }
  79  
  80          return false;
  81      }
  82  
  83      /**
  84       */
  85      public function length()
  86      {
  87          return strlen($this->_mailbox->{$this->_encoding});
  88      }
  89  
  90      /**
  91       */
  92      public function getStream()
  93      {
  94          $stream = new Horde_Stream_Temp();
  95          $stream->add($this->_mailbox->{$this->_encoding});
  96          return $stream;
  97      }
  98  
  99  }