| | |
| | | * Folder creation (CREATE) |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param array $types Optional folder types (RFC 6154) |
| | | * |
| | | * @return bool True on success, False on error |
| | | */ |
| | | function createFolder($mailbox) |
| | | function createFolder($mailbox, $types = null) |
| | | { |
| | | $result = $this->execute('CREATE', array($this->escape($mailbox)), |
| | | self::COMMAND_NORESPONSE); |
| | | $args = array($this->escape($mailbox)); |
| | | |
| | | // RFC 6154: CREATE-SPECIAL-USE |
| | | if (!empty($types) && $this->getCapability('CREATE-SPECIAL-USE')) { |
| | | $args[] = '(USE (' . implode(' ', $types) . '))'; |
| | | } |
| | | |
| | | $result = $this->execute('CREATE', $args, self::COMMAND_NORESPONSE); |
| | | |
| | | return ($result == self::ERROR_OK); |
| | | } |
| | |
| | | * @param string $ref Reference name |
| | | * @param string $mailbox Mailbox name |
| | | * @param bool $subscribed Enables returning subscribed mailboxes only |
| | | * @param array $status_opts List of STATUS options (RFC5819: LIST-STATUS) |
| | | * Possible: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN |
| | | * @param array $status_opts List of STATUS options |
| | | * (RFC5819: LIST-STATUS: MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN) |
| | | * or RETURN options (RFC5258: LIST_EXTENDED: SUBSCRIBED, CHILDREN) |
| | | * @param array $select_opts List of selection options (RFC5258: LIST-EXTENDED) |
| | | * Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE |
| | | * Possible: SUBSCRIBED, RECURSIVEMATCH, REMOTE, |
| | | * SPECIAL-USE (RFC6154) |
| | | * |
| | | * @return array List of mailboxes or hash of options if $status_ops argument |
| | | * is non-empty. |
| | |
| | | } |
| | | |
| | | $args = array(); |
| | | $rets = array(); |
| | | |
| | | if (!empty($select_opts) && $this->getCapability('LIST-EXTENDED')) { |
| | | $select_opts = (array) $select_opts; |
| | |
| | | $args[] = $this->escape($ref); |
| | | $args[] = $this->escape($mailbox); |
| | | |
| | | if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) { |
| | | $status_opts = (array) $status_opts; |
| | | $lstatus = true; |
| | | if (!empty($status_opts) && $this->getCapability('LIST-EXTENDED')) { |
| | | $rets = array_intersect($status_opts, array('SUBSCRIBED', 'CHILDREN')); |
| | | } |
| | | |
| | | $args[] = 'RETURN (STATUS (' . implode(' ', $status_opts) . '))'; |
| | | if (!empty($status_opts) && $this->getCapability('LIST-STATUS')) { |
| | | $status_opts = array_intersect($status_opts, array('MESSAGES', 'RECENT', 'UIDNEXT', 'UIDVALIDITY', 'UNSEEN')); |
| | | |
| | | if (!empty($status_opts)) { |
| | | $lstatus = true; |
| | | $rets[] = 'STATUS (' . implode(' ', $status_opts) . ')'; |
| | | } |
| | | } |
| | | |
| | | if (!empty($rets)) { |
| | | $args[] = 'RETURN (' . implode(' ', $rets) . ')'; |
| | | } |
| | | |
| | | list($code, $response) = $this->execute($subscribed ? 'LSUB' : 'LIST', $args); |
| | |
| | | * |
| | | * @param string $mailbox Mailbox name |
| | | * @param string $field Field to sort by (ARRIVAL, CC, DATE, FROM, SIZE, SUBJECT, TO) |
| | | * @param string $add Searching criteria |
| | | * @param string $criteria Searching criteria |
| | | * @param bool $return_uid Enables UID SORT usage |
| | | * @param string $encoding Character set |
| | | * |
| | | * @return rcube_result_index Response data |
| | | */ |
| | | function sort($mailbox, $field, $add='', $return_uid=false, $encoding = 'US-ASCII') |
| | | function sort($mailbox, $field = 'ARRIVAL', $criteria = '', $return_uid = false, $encoding = 'US-ASCII') |
| | | { |
| | | $field = strtoupper($field); |
| | | $old_sel = $this->selected; |
| | | $supported = array('ARRIVAL', 'CC', 'DATE', 'FROM', 'SIZE', 'SUBJECT', 'TO'); |
| | | $field = strtoupper($field); |
| | | |
| | | if ($field == 'INTERNALDATE') { |
| | | $field = 'ARRIVAL'; |
| | | } |
| | | |
| | | $fields = array('ARRIVAL' => 1,'CC' => 1,'DATE' => 1, |
| | | 'FROM' => 1, 'SIZE' => 1, 'SUBJECT' => 1, 'TO' => 1); |
| | | |
| | | if (!$fields[$field]) { |
| | | if (!in_array($field, $supported)) { |
| | | return new rcube_result_index($mailbox); |
| | | } |
| | | |
| | |
| | | return new rcube_result_index($mailbox); |
| | | } |
| | | |
| | | // return empty result when folder is empty and we're just after SELECT |
| | | if ($old_sel != $mailbox && !$this->data['EXISTS']) { |
| | | return new rcube_result_index($mailbox, '* SORT'); |
| | | } |
| | | |
| | | // RFC 5957: SORT=DISPLAY |
| | | if (($field == 'FROM' || $field == 'TO') && $this->getCapability('SORT=DISPLAY')) { |
| | | $field = 'DISPLAY' . $field; |
| | | } |
| | | |
| | | // message IDs |
| | | if (!empty($add)) { |
| | | $add = $this->compressMessageSet($add); |
| | | } |
| | | $encoding = $encoding ? trim($encoding) : 'US-ASCII'; |
| | | $criteria = $criteria ? 'ALL ' . trim($criteria) : 'ALL'; |
| | | |
| | | list($code, $response) = $this->execute($return_uid ? 'UID SORT' : 'SORT', |
| | | array("($field)", $encoding, !empty($add) ? $add : 'ALL')); |
| | | array("($field)", $encoding, $criteria)); |
| | | |
| | | if ($code != self::ERROR_OK) { |
| | | $response = null; |
| | |
| | | |
| | | // return empty result when folder is empty and we're just after SELECT |
| | | if ($old_sel != $mailbox && !$this->data['EXISTS']) { |
| | | return new rcube_result_thread($mailbox); |
| | | return new rcube_result_thread($mailbox, '* THREAD'); |
| | | } |
| | | |
| | | $encoding = $encoding ? trim($encoding) : 'US-ASCII'; |