[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/horde/framework/Horde/Mail/Rfc822/ -> Group.php (source)

   1  <?php
   2  /**
   3   * Copyright 2012-2014 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file COPYING for license information (BSD). If you
   6   * did not receive this file, see http://www.horde.org/licenses/bsd.
   7   *
   8   * @category  Horde
   9   * @copyright 2012-2014 Horde LLC
  10   * @license   http://www.horde.org/licenses/bsd New BSD License
  11   * @package   Mail
  12   */
  13  
  14  /**
  15   * Object representation of a RFC 822 e-mail address.
  16   *
  17   * @author    Michael Slusarz <slusarz@horde.org>
  18   * @category  Horde
  19   * @copyright 2012-2014 Horde LLC
  20   * @license   http://www.horde.org/licenses/bsd New BSD License
  21   * @package   Mail
  22   *
  23   * @property string $groupname  Groupname (UTF-8).
  24   * @property-read string $groupname_encoded  MIME encoded groupname (UTF-8).
  25   * @property-read string $label  The shorthand label for this group.
  26   * @property-read boolean $valid  Returns true if there is enough information
  27   *                                in object to create a valid address.
  28   */
  29  class Horde_Mail_Rfc822_Group extends Horde_Mail_Rfc822_Object implements Countable
  30  {
  31      /**
  32       * List of group e-mail address objects.
  33       *
  34       * @var Horde_Mail_Rfc822_GroupList
  35       */
  36      public $addresses;
  37  
  38      /**
  39       * Group name (MIME decoded).
  40       *
  41       * @var string
  42       */
  43      protected $_groupname = 'Group';
  44  
  45      /**
  46       * Constructor.
  47       *
  48       * @param string $groupname  If set, used as the group name.
  49       * @param mixed $addresses   If a GroupList object, used as the address
  50       *                           list. Any other non-null value is parsed and
  51       *                           used as the address list (addresses not
  52       *                           verified; sub-groups are ignored).
  53       */
  54      public function __construct($groupname = null, $addresses = null)
  55      {
  56          if (!is_null($groupname)) {
  57              $this->groupname = $groupname;
  58          }
  59  
  60          if (is_null($addresses)) {
  61              $this->addresses = new Horde_Mail_Rfc822_GroupList();
  62          } elseif ($addresses instanceof Horde_Mail_Rfc822_GroupList) {
  63              $this->addresses = clone $addresses;
  64          } else {
  65              $rfc822 = new Horde_Mail_Rfc822();
  66              $this->addresses = $rfc822->parseAddressList($addresses, array(
  67                  'group' => true
  68              ));
  69          }
  70      }
  71  
  72      /**
  73       */
  74      public function __set($name, $value)
  75      {
  76          switch ($name) {
  77          case 'groupname':
  78              $this->_groupname = Horde_Mime::decode($value);
  79              break;
  80          }
  81      }
  82  
  83      /**
  84       */
  85      public function __get($name)
  86      {
  87          switch ($name) {
  88          case 'groupname':
  89          case 'label':
  90              return $this->_groupname;
  91  
  92          case 'groupname_encoded':
  93              return Horde_Mime::encode($this->_groupname);
  94  
  95          case 'valid':
  96              return (bool)strlen($this->_groupname);
  97  
  98          default:
  99              return null;
 100          }
 101      }
 102  
 103      /**
 104       */
 105      protected function _writeAddress($opts)
 106      {
 107          $addr = $this->addresses->writeAddress($opts);
 108          $groupname = $this->groupname;
 109          if (!empty($opts['encode'])) {
 110              $groupname = Horde_Mime::encode($groupname, $opts['encode']);
 111          }
 112  
 113          $rfc822 = new Horde_Mail_Rfc822();
 114  
 115          return $rfc822->encode($groupname, 'personal') . ':' .
 116              (strlen($addr) ? (' ' . $addr) : '') . ';';
 117      }
 118  
 119      /**
 120       */
 121      public function match($ob)
 122      {
 123          return $this->addresses->match($ob);
 124      }
 125  
 126      /* Countable methods. */
 127  
 128      /**
 129       * Address count.
 130       *
 131       * @return integer  The number of addresses.
 132       */
 133      public function count()
 134      {
 135          return count($this->addresses);
 136      }
 137  
 138  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1