| | |
| | | * Executes STATUS comand |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param array $items Requested item names |
| | | * @param array $items Additional requested item names. By default |
| | | * MESSAGES and UNSEEN are requested. Other defined |
| | | * in RFC3501: UIDNEXT, UIDVALIDITY, RECENT |
| | | * |
| | | * @return array Status item-value hash |
| | | * @access public |
| | | * @since 0.5-beta |
| | | */ |
| | | function status($mailbox, $items) |
| | | function status($mailbox, $items=array()) |
| | | { |
| | | if (empty($mailbox) || empty($items)) { |
| | | if (empty($mailbox)) { |
| | | return false; |
| | | } |
| | | |
| | | if (!in_array('MESSAGES', $items)) { |
| | | $items[] = 'MESSAGES'; |
| | | } |
| | | if (!in_array('UNSEEN', $items)) { |
| | | $items[] = 'UNSEEN'; |
| | | } |
| | | |
| | | list($code, $response) = $this->execute('STATUS', array($this->escape($mailbox), |
| | |
| | | for ($i=0, $len=count($items); $i<$len; $i += 2) { |
| | | $result[$items[$i]] = (int) $items[$i+1]; |
| | | } |
| | | |
| | | $this->data['STATUS:'.$mailbox] = $result; |
| | | |
| | | return $result; |
| | | } |
| | |
| | | return $this->data['EXISTS']; |
| | | } |
| | | |
| | | // Try STATUS, should be faster |
| | | $counts = $this->status($mailbox, array('MESSAGES')); |
| | | // Check internal cache |
| | | $cache = $this->data['STATUS:'.$mailbox]; |
| | | if (!empty($cache) && isset($cache['MESSAGES'])) { |
| | | return (int) $cache['MESSAGES']; |
| | | } |
| | | |
| | | // Try STATUS (should be faster than SELECT) |
| | | $counts = $this->status($mailbox); |
| | | if (is_array($counts)) { |
| | | return (int) $counts['MESSAGES']; |
| | | } |
| | |
| | | */ |
| | | function countUnseen($mailbox) |
| | | { |
| | | // Try STATUS, should be faster |
| | | $counts = $this->status($mailbox, array('UNSEEN')); |
| | | // Check internal cache |
| | | $cache = $this->data['STATUS:'.$mailbox]; |
| | | if (!empty($cache) && isset($cache['UNSEEN'])) { |
| | | return (int) $cache['UNSEEN']; |
| | | } |
| | | |
| | | // Try STATUS (should be faster than SELECT+SEARCH) |
| | | $counts = $this->status($mailbox); |
| | | if (is_array($counts)) { |
| | | return (int) $counts['UNSEEN']; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$mailbox]); |
| | | |
| | | $result = $this->execute($messages ? 'UID EXPUNGE' : 'EXPUNGE', |
| | | array($messages), self::COMMAND_NORESPONSE); |
| | | |
| | |
| | | |
| | | if (!$this->select($mailbox)) { |
| | | return false; |
| | | } |
| | | |
| | | // Clear internal status cache |
| | | if ($flag == 'SEEN') { |
| | | unset($this->data['STATUS:'.$mailbox]['UNSEEN']); |
| | | } |
| | | |
| | | $flag = $this->flags[strtoupper($flag)]; |
| | |
| | | return false; |
| | | } |
| | | |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$to]); |
| | | |
| | | $result = $this->execute('UID COPY', array( |
| | | $this->compressMessageSet($messages), $this->escape($to)), |
| | | self::COMMAND_NORESPONSE); |
| | |
| | | $r = $this->copy($messages, $from, $to); |
| | | |
| | | if ($r) { |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$from]); |
| | | |
| | | return $this->delete($from, $messages); |
| | | } |
| | | return $r; |
| | |
| | | $line = $this->readLine(); |
| | | } while (!$this->startsWith($line, $key, true, true)); |
| | | |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$folder]); |
| | | |
| | | return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK); |
| | | } |
| | | else { |
| | |
| | | $line = $this->readLine(); |
| | | } while (!$this->startsWith($line, $key, true, true)); |
| | | |
| | | // Clear internal status cache |
| | | unset($this->data['STATUS:'.$folder]); |
| | | |
| | | return ($this->parseResult($line, 'APPEND: ') == self::ERROR_OK); |
| | | } |