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];
}
}
}
}