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   * Class containing deprecated Horde_Imap_Client_Base methods that will be
  16   * removed in version 3.0.
  17   *
  18   * NOTE: This class is NOT intended to be accessed outside of a Base object.
  19   * There is NO guarantees that the API of this class will not change across
  20   * versions.
  21   *
  22   * @author    Michael Slusarz <slusarz@horde.org>
  23   * @category  Horde
  24   * @copyright 2012-2017 Horde LLC
  25   * @internal
  26   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  27   * @package   Imap_Client
  28   */
  29  class Horde_Imap_Client_Base_Deprecated
  30  {
  31      /**
  32       * Returns a unique identifier for the current mailbox status.
  33       *
  34       * @param Horde_Imap_Client_Base $base_ob  The base driver object.
  35       * @param mixed $mailbox                   A mailbox. Either a
  36       *                                         Horde_Imap_Client_Mailbox
  37       *                                         object or a string (UTF-8).
  38       * @param boolean $condstore               Is CONDSTORE enabled?
  39       * @param array $addl                      Additional cache info to add to
  40       *                                         the cache ID string.
  41       *
  42       * @return string  The cache ID string, which will change when the
  43       *                 composition of the mailbox changes. The uidvalidity
  44       *                 will always be the first element, and will be delimited
  45       *                 by the '|' character.
  46       *
  47       * @throws Horde_Imap_Client_Exception
  48       */
  49      public static function getCacheId($base_ob, $mailbox, $condstore,
  50                                        array $addl = array())
  51      {
  52          $query = Horde_Imap_Client::STATUS_UIDVALIDITY | Horde_Imap_Client::STATUS_MESSAGES | Horde_Imap_Client::STATUS_UIDNEXT;
  53  
  54          /* Use MODSEQ as cache ID if CONDSTORE extension is available. */
  55          if ($condstore) {
  56              $query |= Horde_Imap_Client::STATUS_HIGHESTMODSEQ;
  57          } else {
  58              $query |= Horde_Imap_Client::STATUS_UIDNEXT_FORCE;
  59          }
  60  
  61          $status = $base_ob->status($mailbox, $query);
  62  
  63          if (empty($status['highestmodseq'])) {
  64              $parts = array(
  65                  'V' . $status['uidvalidity'],
  66                  'U' . $status['uidnext'],
  67                  'M' . $status['messages']
  68              );
  69          } else {
  70              $parts = array(
  71                  'V' . $status['uidvalidity'],
  72                  'H' . $status['highestmodseq']
  73              );
  74          }
  75  
  76          return implode('|', array_merge($parts, $addl));
  77      }
  78  
  79      /**
  80       * Parses a cacheID created by getCacheId().
  81       *
  82       * @param string $id  The cache ID.
  83       *
  84       * @return array  An array with the following information:
  85       *   - highestmodseq: (integer)
  86       *   - messages: (integer)
  87       *   - uidnext: (integer)
  88       *   - uidvalidity: (integer) Always present
  89       */
  90      public static function parseCacheId($id)
  91      {
  92          $data = array(
  93              'H' => 'highestmodseq',
  94              'M' => 'messages',
  95              'U' => 'uidnext',
  96              'V' => 'uidvalidity'
  97          );
  98          $info = array();
  99  
 100          foreach (explode('|', $id) as $part) {
 101              if (isset($data[$part[0]])) {
 102                  $info[$data[$part[0]]] = intval(substr($part, 1));
 103              }
 104          }
 105  
 106          return $info;
 107      }
 108  
 109  }