protected function _copy(Horde_Imap_Client_Mailbox $dest, $options)
{
/* Check for MOVE command (RFC 6851). */
$move_cmd = !empty($options['move']) && $this->_capability('MOVE');
$cmd = $this->_pipeline($this->_command(($options['ids']->sequence ? '' : 'UID ') . ($move_cmd ? 'MOVE' : 'COPY'))->add(array(strval($options['ids']), $this->_getMboxFormatOb($dest))));
$cmd->data['copydest'] = $dest;
// COPY returns no untagged information (RFC 3501 [6.4.7])
try {
$resp = $this->_sendCmd($cmd);
} catch (Horde_Imap_Client_Exception $e) {
if (!empty($options['create']) && !empty($e->resp_data['trycreate'])) {
$this->createMailbox($dest);
unset($options['create']);
return $this->_copy($dest, $options);
}
throw $e;
}
// If moving, delete the old messages now. Short-circuit if nothing
// was moved.
if (!$move_cmd && !empty($options['move']) && (isset($resp->data['copyuid']) || !$this->_capability('UIDPLUS'))) {
$this->expunge($this->_selected, array('delete' => true, 'ids' => $options['ids']));
}
return isset($resp->data['copyuid']) ? $resp->data['copyuid'] : true;
}