Send the MYRIGHTS command (RFC4314)

@param string $mailbox Mailbox name

@return array MYRIGHTS response on success, NULL on error
@since 0.5-beta
187907
public function myRights($mailbox)
    {
        list($code, $response) = $this->execute('MYRIGHTS', array($this->escape($mailbox)), 0, '/^\* MYRIGHTS /i');

        if ($code == self::ERROR_OK && $response) {
            // Parse server response (remove "* MYRIGHTS ")
            $response = substr($response, 11);

            $ret_mbox = $this->tokenizeResponse($response, 1);
            $rights   = $this->tokenizeResponse($response, 1);

            return str_split($rights);
        }
    }
821933
protected function _syncStatus($mailbox)
    {
        $status = $this->status(
            $mailbox,
            Horde_Imap_Client::STATUS_HIGHESTMODSEQ |
            Horde_Imap_Client::STATUS_MESSAGES |
            Horde_Imap_Client::STATUS_UIDNEXT_FORCE |
            Horde_Imap_Client::STATUS_UIDVALIDITY
        );

        $fields = array('uidnext', 'uidvalidity');
        if (empty($status['highestmodseq'])) {
            $fields[] = 'messages';
        } else {
            $fields[] = 'highestmodseq';
        }

        $out = array();
        $sync_map = array_flip(Horde_Imap_Client_Data_Sync::$map);

        foreach ($fields as $val) {
            $out[$sync_map[$val]] = $status[$val];
        }

        return array_filter($out);
    }
843305
def setacl(mailbox, user, rights)
      if rights.nil?
        send_command("SETACL", mailbox, user, "")
      else
        send_command("SETACL", mailbox, user, rights)
      end
    end
255306
protected function _parseMyRights(
        Horde_Imap_Client_Interaction_Pipeline $pipeline,
        Horde_Imap_Client_Tokenize $data
    )
    {
        // Ignore 1st token (mailbox name)
        $data->next();

        $pipeline->data['myrights'] = new Horde_Imap_Client_Data_Acl($data->next());
    }
1271748
function get_thread($mailbox)
    {
        if (empty($this->icache[$mailbox])) {
            $this->icache[$mailbox] = array();
        }

        // Seek in internal cache
        if (array_key_exists('thread', $this->icache[$mailbox])) {
            return $this->icache[$mailbox]['thread']['object'];
        }

        // Get thread from DB (if DB wasn't already queried)
        if (empty($this->icache[$mailbox]['thread_queried'])) {
            $index = $this->get_thread_row($mailbox);

            // set the flag that DB was already queried for thread
            // this way we'll be able to skip one SELECT, when
            // get_thread() is called more than once or after clear()
            $this->icache[$mailbox]['thread_queried'] = true;
        }

        // Entry exist, check cache status
        if (!empty($index)) {
            $exists   = true;
            $is_valid = $this->validate($mailbox, $index, $exists);

            if (!$is_valid) {
                $index = null;
            }
        }

        // Index not found or not valid, get index from IMAP server
        if ($index === null) {
            // Get mailbox data (UIDVALIDITY, counters, etc.) for status check
            $mbox_data = $this->imap->folder_data($mailbox);
            // Get THREADS result
            $index['object'] = $this->get_thread_data($mailbox, $mbox_data);

            // insert/update
            $this->add_thread_row($mailbox, $index['object'], $mbox_data, $exists);
        }

        $this->icache[$mailbox]['thread'] = $index;

        return $index['object'];
    }
928932
protected function _getCid($mailbox)
    {
        return implode(self::CID_SEPARATOR, array(
            'horde_imap_client',
            $this->_params['username'],
            $mailbox,
            $this->_params['hostspec'],
            $this->_params['port']
        ));
    }
134962
public function select($mailbox, $qresync_data = null)
    {
        if (!strlen($mailbox)) {
            return false;
        }

        if ($this->selected === $mailbox) {
            return true;
        }
/*
    Temporary commented out because Courier returns \Noselect for INBOX
    Requires more investigation

        if (is_array($this->data['LIST']) && is_array($opts = $this->data['LIST'][$mailbox])) {
            if (in_array('\\Noselect', $opts)) {
                return false;
            }
        }
*/
        $params = array($this->escape($mailbox));

        // QRESYNC data items
        //    0. the last known UIDVALIDITY,
        //    1. the last known modification sequence,
        //    2. the optional set of known UIDs, and
        //    3. an optional parenthesized list of known sequence ranges and their
        //       corresponding UIDs.
        if (!empty($qresync_data)) {
            if (!empty($qresync_data[2])) {
                $qresync_data[2] = self::compressMessageSet($qresync_data[2]);
            }

            $params[] = array('QRESYNC', $qresync_data);
        }

        list($code, $response) = $this->execute('SELECT', $params);

        if ($code == self::ERROR_OK) {
            $this->clear_mailbox_cache();

            $response = explode("\r\n", $response);
            foreach ($response as $line) {
                if (preg_match('/^\* OK \[/i', $line)) {
                    $pos   = strcspn($line, ' ]', 6);
                    $token = strtoupper(substr($line, 6, $pos));
                    $pos   += 7;

                    switch ($token) {
                    case 'UIDNEXT':
                    case 'UIDVALIDITY':
                    case 'UNSEEN':
                        if ($len = strspn($line, '0123456789', $pos)) {
                            $this->data[$token] = (int) substr($line, $pos, $len);
                        }
                        break;

                    case 'HIGHESTMODSEQ':
                        if ($len = strspn($line, '0123456789', $pos)) {
                            $this->data[$token] = (string) substr($line, $pos, $len);
                        }
                        break;

                    case 'NOMODSEQ':
                        $this->data[$token] = true;
                        break;

                    case 'PERMANENTFLAGS':
                        $start = strpos($line, '(', $pos);
                        $end   = strrpos($line, ')');
                        if ($start && $end) {
                            $flags = substr($line, $start + 1, $end - $start - 1);
                            $this->data[$token] = explode(' ', $flags);
                        }
                        break;
                    }
                }
                else if (preg_match('/^\* ([0-9]+) (EXISTS|RECENT|FETCH)/i', $line, $match)) {
                    $token = strtoupper($match[2]);
                    switch ($token) {
                    case 'EXISTS':
                    case 'RECENT':
                        $this->data[$token] = (int) $match[1];
                        break;

                    case 'FETCH':
                        // QRESYNC FETCH response (RFC5162)
                        $line       = substr($line, strlen($match[0]));
                        $fetch_data = $this->tokenizeResponse($line, 1);
                        $data       = array('id' => $match[1]);

                        for ($i=0, $size=count($fetch_data); $i<$size; $i+=2) {
                            $data[strtolower($fetch_data[$i])] = $fetch_data[$i+1];
                        }

                        $this->data['QRESYNC'][$data['uid']] = $data;
                        break;
                    }
                }
                // QRESYNC VANISHED response (RFC5162)
                else if (preg_match('/^\* VANISHED [()EARLIER]*/i', $line, $match)) {
                    $line   = substr($line, strlen($match[0]));
                    $v_data = $this->tokenizeResponse($line, 1);

                    $this->data['VANISHED'] = $v_data;
                }
            }

            $this->data['READ-WRITE'] = $this->resultcode != 'READ-ONLY';
            $this->selected = $mailbox;

            return true;
        }

        return false;
    }
712460
protected function _mailboxOb($mailbox = null)
    {
        $name = is_null($mailbox)
            ? strval($this->_selected)
            : strval($mailbox);

        if (!isset($this->_temp['mailbox_ob'][$name])) {
            $this->_temp['mailbox_ob'][$name] = new Horde_Imap_Client_Base_Mailbox();
        }

        return $this->_temp['mailbox_ob'][$name];
    }
1292525
public function email($sEmail = null)
    {
        if (null === $sEmail) {
            return $this->getEmail();
        }

        return $this->setEmail($sEmail);
    }
1220890
public function my_rights($folder)
    {
        if (!$this->get_capability('ACL')) {
            return null;
        }

        if (!$this->check_connection()) {
            return null;
        }

        return $this->conn->myRights($folder);
    }
537996
public function getQuota($mailbox = null)
    {
        if ($mailbox === null || $mailbox === '') {
            $mailbox = 'INBOX';
        }

        // a0001 GETQUOTAROOT INBOX
        // * QUOTAROOT INBOX user/sample
        // * QUOTA user/sample (STORAGE 654 9765)
        // a0001 OK Completed

        list($code, $response) = $this->execute('GETQUOTAROOT', array($this->escape($mailbox)), 0, '/^\* QUOTA /i');

        $result   = false;
        $min_free = PHP_INT_MAX;
        $all      = array();

        if ($code == self::ERROR_OK) {
            foreach (explode("\n", $response) as $line) {
                list(, , $quota_root) = $this->tokenizeResponse($line, 3);

                $quotas = $this->tokenizeResponse($line, 1);

                if (empty($quotas)) {
                    continue;
                }

                foreach (array_chunk($quotas, 3) as $quota) {
                    list($type, $used, $total) = $quota;
                    $type = strtolower($type);

                    if ($type && $total) {
                        $all[$quota_root][$type]['used']  = intval($used);
                        $all[$quota_root][$type]['total'] = intval($total);
                    }
                }

                if (empty($all[$quota_root]['storage'])) {
                    continue;
                }

                $used  = $all[$quota_root]['storage']['used'];
                $total = $all[$quota_root]['storage']['total'];
                $free  = $total - $used;

                // calculate lowest available space from all storage quotas
                if ($free < $min_free) {
                    $min_free          = $free;
                    $result['used']    = $used;
                    $result['total']   = $total;
                    $result['percent'] = min(100, round(($used/max(1,$total))*100));
                    $result['free']    = 100 - $result['percent'];
                }
            }
        }

        if (!empty($result)) {
            $result['all'] = $all;
        }

        return $result;
    }
1122752
public function deleteMsgs($mailbox, $uids)
    {
        if (empty($uids)) {
            return;
        }

        $mailbox = strval($mailbox);

        $this->_backend->deleteMsgs($mailbox, $uids);

        if ($this->_debug) {
            $this->_debug->info(sprintf(
                'CACHE: Deleted messages [%s; %s]',
                $mailbox,
                $this->_baseob->getIdsOb($uids)->tostring_sort
            ));
        }
    }
12748
public function sendCommand(string $command) : string
    {
        try {
            $this->socket->send(json_encode([
                'action' => 'command',
                'command' => [
                    'name' => $command,
                ]
            ]));
            $result = $this->socket->recv();
            return $result;
        } catch (\ZMQException $e) {
            throw new ClientException($e->getMessage());
        }
    }
516017
private function getAccessLevels($email)
    {
        foreach ($this->hostedDomains as $hostedDomain) {
            if (preg_match('/'.$hostedDomain['domain_name'].'$/', $email)) {
                return $hostedDomain['access_levels'];
            }
        }

        return null;
    }
839685
public function setMailbox($mailbox = 'INBOX')
    {

        if ($mailbox == 'INBOX') {
            $mailbox = "{".$this->settings['server']."}INBOX";
        } else {
            $mailbox = "{".$this->settings['server']."}INBOX.".imap_utf7_encode($mailbox);
        }

        $result = false;

        if ($this->conn) {
            $result = imap_reopen($this->conn, $mailbox);
            $this->mailbox = $mailbox;
        }

        return $result;
    }
1296032
public function getSyncToken($mailbox)
    {
        $out = array();

        foreach ($this->_syncStatus($mailbox) as $key => $val) {
            $out[] = $key . $val;
        }

        return base64_encode(implode(',', $out));
    }
838079
public function mailbox_change_state($mailBoxName = NULL, $oldMessages = NULL, $newMessages = NULL)
        {
            return $this->state($mailBoxName, $oldMessages, $newMessages);
        }