| | |
| | | * @param array $return_opts (see self::_listMailboxes) |
| | | * @param array $select_opts (see self::_listMailboxes) |
| | | * |
| | | * @return array List of mailboxes or hash of options if $return_opts argument |
| | | * is non-empty. |
| | | * @return array|bool List of mailboxes or hash of options if STATUS/MYROGHTS response |
| | | * is requested, False on error. |
| | | */ |
| | | function listMailboxes($ref, $mailbox, $return_opts=array(), $select_opts=array()) |
| | | { |
| | |
| | | * @param string $mailbox Mailbox name |
| | | * @param array $return_opts (see self::_listMailboxes) |
| | | * |
| | | * @return array List of mailboxes or hash of options if $return_opts argument |
| | | * is non-empty. |
| | | * @return array|bool List of mailboxes or hash of options if STATUS/MYROGHTS response |
| | | * is requested, False on error. |
| | | */ |
| | | function listSubscribed($ref, $mailbox, $return_opts=array()) |
| | | { |
| | |
| | | * Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE, |
| | | * SPECIAL-USE (RFC6154) |
| | | * |
| | | * @return array List of mailboxes or hash of options if $status_ops argument |
| | | * is non-empty. |
| | | * @return array|bool List of mailboxes or hash of options if STATUS/MYROGHTS response |
| | | * is requested, False on error. |
| | | */ |
| | | protected function _listMailboxes($ref, $mailbox, $subscribed=false, |
| | | $return_opts=array(), $select_opts=array()) |
| | |
| | | $args[] = $this->escape($mailbox); |
| | | |
| | | if (!empty($return_opts) && $this->getCapability('LIST-EXTENDED')) { |
| | | $rets = array_intersect($return_opts, array('SUBSCRIBED', 'CHILDREN')); |
| | | $ext_opts = array('SUBSCRIBED', 'CHILDREN'); |
| | | $rets = array_intersect($return_opts, $ext_opts); |
| | | $return_opts = array_diff($return_opts, $rets); |
| | | } |
| | | |
| | | if (!empty($return_opts) && $this->getCapability('LIST-STATUS')) { |
| | |
| | | $result[$id] = ''; |
| | | } |
| | | } else if ($mode == 2) { |
| | | if (preg_match('/(UID|RFC822\.SIZE) ([0-9]+)/', $line, $matches)) { |
| | | $result[$id] = trim($matches[2]); |
| | | if (preg_match('/' . $index_field . ' ([0-9]+)/', $line, $matches)) { |
| | | $result[$id] = trim($matches[1]); |
| | | } else { |
| | | $result[$id] = 0; |
| | | } |
| | |
| | | */ |
| | | protected function modFlag($mailbox, $messages, $flag, $mod = '+') |
| | | { |
| | | if ($mod != '+' && $mod != '-') { |
| | | $mod = '+'; |
| | | } |
| | | |
| | | if (!$this->select($mailbox)) { |
| | | return false; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | if ($this->flags[strtoupper($flag)]) { |
| | | $flag = $this->flags[strtoupper($flag)]; |
| | | } |
| | | |
| | | if (!$flag || (!in_array($flag, (array) $this->data['PERMANENTFLAGS']) |
| | | && !in_array('\\*', (array) $this->data['PERMANENTFLAGS'])) |
| | | ) { |
| | | return false; |
| | | } |
| | | |
| | | // Clear internal status cache |
| | | if ($flag == 'SEEN') { |
| | | unset($this->data['STATUS:'.$mailbox]['UNSEEN']); |
| | | } |
| | | |
| | | $flag = $this->flags[strtoupper($flag)]; |
| | | if ($mod != '+' && $mod != '-') { |
| | | $mod = '+'; |
| | | } |
| | | |
| | | $result = $this->execute('UID STORE', array( |
| | | $this->compressMessageSet($messages), $mod . 'FLAGS.SILENT', "($flag)"), |
| | | self::COMMAND_NORESPONSE); |
| | |
| | | /** |
| | | * Returns QUOTA information |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * |
| | | * @return array Quota information |
| | | */ |
| | | function getQuota() |
| | | function getQuota($mailbox = null) |
| | | { |
| | | /* |
| | | * GETQUOTAROOT "INBOX" |
| | | * QUOTAROOT INBOX user/rchijiiwa1 |
| | | * QUOTA user/rchijiiwa1 (STORAGE 654 9765) |
| | | * OK Completed |
| | | */ |
| | | $result = false; |
| | | $quota_lines = array(); |
| | | $key = $this->nextTag(); |
| | | $command = $key . ' GETQUOTAROOT INBOX'; |
| | | |
| | | // get line(s) containing quota info |
| | | if ($this->putLine($command)) { |
| | | do { |
| | | $line = rtrim($this->readLine(5000)); |
| | | if (preg_match('/^\* QUOTA /', $line)) { |
| | | $quota_lines[] = $line; |
| | | } |
| | | } while (!$this->startsWith($line, $key, true, true)); |
| | | } |
| | | else { |
| | | $this->setError(self::ERROR_COMMAND, "Unable to send command: $command"); |
| | | if ($mailbox === null || $mailbox === '') { |
| | | $mailbox = 'INBOX'; |
| | | } |
| | | |
| | | // return false if not found, parse if found |
| | | // 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))); |
| | | |
| | | $result = false; |
| | | $min_free = PHP_INT_MAX; |
| | | foreach ($quota_lines as $key => $quota_line) { |
| | | $quota_line = str_replace(array('(', ')'), '', $quota_line); |
| | | $parts = explode(' ', $quota_line); |
| | | $storage_part = array_search('STORAGE', $parts); |
| | | $all = array(); |
| | | |
| | | if (!$storage_part) { |
| | | continue; |
| | | if ($code == self::ERROR_OK) { |
| | | foreach (explode("\n", $response) as $line) { |
| | | if (preg_match('/^\* QUOTA /', $line)) { |
| | | list(, , $quota_root) = $this->tokenizeResponse($line, 3); |
| | | |
| | | while ($line) { |
| | | list($type, $used, $total) = $this->tokenizeResponse($line, 1); |
| | | $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']; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | $used = intval($parts[$storage_part+1]); |
| | | $total = intval($parts[$storage_part+2]); |
| | | $free = $total - $used; |
| | | |
| | | // return lowest available space from all 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; |