IMP_Indices::add PHP Method

add() public method

Input format:
1 argument:
-----------
+ Array
  Either:
    KEYS: Mailbox names
    VALUES: UIDs -or- Horde_Imap_Client_Ids object
 -or-
    VALUES: IMAP sequence strings
+ IMP_Compose object
+ IMP_Contents object
+ IMP_Indices object
+ String
  Format: IMAP sequence string

2 arguments:
------------
1st argument: Mailbox name -or- IMP_Mailbox object
2nd argument: Either a single UID, array of UIDs, or a
              Horde_Imap_Client_Ids object.
public add ( )
    public function add()
    {
        $data = func_get_arg(0);
        $indices = array();
        switch (func_num_args()) {
            case 1:
                if (is_array($data)) {
                    foreach ($data as $key => $val) {
                        if (is_array($val)) {
                            $indices[$key] = array_keys(array_flip($val));
                        } elseif ($val instanceof Horde_Imap_Client_Ids) {
                            $this->add($key, $val);
                        } else {
                            $this->add($val);
                        }
                    }
                } elseif (is_string($data)) {
                    $indices = $this->_fromSequenceString($data);
                } elseif ($data instanceof IMP_Compose) {
                    $indices = $data->getMetadata('indices')->indices();
                } elseif ($data instanceof IMP_Contents) {
                    $indices = array(strval($data->getMailbox()) => array($data->getUid()));
                } elseif ($data instanceof IMP_Indices) {
                    $indices = $data->indices();
                }
                break;
            case 2:
                $secondarg = func_get_arg(1);
                if (is_array($secondarg)) {
                    $secondarg = array_keys(array_flip($secondarg));
                } elseif ($secondarg instanceof Horde_Imap_Client_Ids) {
                    $secondarg = $secondarg->ids;
                } else {
                    $secondarg = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->getIdsOb($secondarg)->ids;
                }
                if (!empty($secondarg)) {
                    $indices = array(strval(func_get_arg(0)) => $secondarg);
                }
                break;
        }
        if (!empty($indices)) {
            if (empty($this->_indices)) {
                $this->_indices = $indices;
            } else {
                /* Can't use array_merge_recursive() here because keys may
                 * be numeric mailbox names (e.g. 123), and these keys are
                 * treated as numeric (not strings) when merging. */
                foreach (array_keys($indices) as $key) {
                    $this->_indices[$key] = isset($this->_indices[$key]) ? array_keys(array_flip(array_merge($this->_indices[$key], $indices[$key]))) : $indices[$key];
                }
            }
        }
    }

Usage Example

Example #1
0
 /**
  */
 public function getIndicesOb()
 {
     $this->_buildMailbox();
     $ob = new IMP_Indices();
     reset($this->_sorted);
     while (list($k, $v) = each($this->_sorted)) {
         $ob->add($this->_sortedMbox[$k], $v);
     }
     return $ob;
 }
All Usage Examples Of IMP_Indices::add