Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
   1  <?php
   2  /**
   3   * Copyright 2014-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 2014-2017 Horde LLC
  10   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  11   * @package   Mime
  12   */
  13  
  14  /**
  15   * This class represents address fields that may appear multiple times in a
  16   * message part (i.e. they are independent of each other) (RFC 5322).
  17   *
  18   * @author    Michael Slusarz <slusarz@horde.org>
  19   * @category  Horde
  20   * @copyright 2014-2017 Horde LLC
  21   * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
  22   * @package   Mime
  23   * @since     2.5.0
  24   */
  25  class Horde_Mime_Headers_AddressesMulti
  26  extends Horde_Mime_Headers_Element_Multiple
  27  implements Horde_Mime_Headers_Element_Address
  28  {
  29      /**
  30       */
  31      public function __clone()
  32      {
  33          $copy = array();
  34          foreach ($this->_values as $val) {
  35              $copy[] = clone $val;
  36          }
  37          $this->_values = $copy;
  38      }
  39  
  40      /**
  41       */
  42      public function __get($name)
  43      {
  44          switch ($name) {
  45          case 'full_value':
  46          case 'value':
  47              return array_map('strval', $this->_values);
  48  
  49          case 'value_single':
  50              return strval(reset($this->_values));
  51          }
  52  
  53          return parent::__get($name);
  54      }
  55  
  56      /**
  57       */
  58      public function getAddressList($first = false)
  59      {
  60          return $first
  61              ? reset($this->_values)
  62              : $this->_values;
  63      }
  64  
  65      /**
  66       */
  67      protected function _setValue($value)
  68      {
  69          /* @todo Implement with traits */
  70          $rfc822 = new Horde_Mail_Rfc822();
  71          $addr_list = $rfc822->parseAddressList($value);
  72  
  73          foreach ($addr_list as $ob) {
  74              if ($ob instanceof Horde_Mail_Rfc822_Group) {
  75                  $ob->groupname = $this->_sanityCheck($ob->groupname);
  76              } else {
  77                  $ob->personal = $this->_sanityCheck($ob->personal);                         }
  78          }
  79  
  80          $this->_values[] = $addr_list;
  81      }
  82  
  83      /**
  84       */
  85      public static function getHandles()
  86      {
  87          return array(
  88              // Mail: RFC 5322 (Address that can appear in multiple headers)
  89              'resent-to',
  90              'resent-cc',
  91              'resent-bcc',
  92              'resent-from'
  93          );
  94      }
  95  
  96      /**
  97       * @param array $opts  See Horde_Mime_Headers_Addresses#doSendEncode().
  98       */
  99      protected function _sendEncode($opts)
 100      {
 101          return Horde_Mime_Headers_Addresses::doSendEncode(
 102              $this->getAddressList(),
 103              $opts
 104          );
 105      }
 106  
 107  }