| | |
| | | */ |
| | | protected $icache = array(); |
| | | |
| | | protected $plugins; |
| | | protected $list_page = 1; |
| | | protected $delimiter; |
| | | protected $namespace; |
| | |
| | | public function __construct() |
| | | { |
| | | $this->conn = new rcube_imap_generic(); |
| | | $this->plugins = rcube::get_instance()->plugins; |
| | | |
| | | // Set namespace and delimiter from session, |
| | | // so some methods would work before connection |
| | |
| | | |
| | | $attempt = 0; |
| | | do { |
| | | $data = rcube::get_instance()->plugins->exec_hook('storage_connect', |
| | | $data = $this->plugins->exec_hook('storage_connect', |
| | | array_merge($this->options, array('host' => $host, 'user' => $user, |
| | | 'attempt' => ++$attempt))); |
| | | |
| | |
| | | $this->connect_done = true; |
| | | |
| | | if ($this->conn->connected()) { |
| | | // check for session identifier |
| | | $session = null; |
| | | if (preg_match('/\s+SESSIONID=([^=\s]+)/', $this->conn->result, $m)) { |
| | | $session = $m[1]; |
| | | } |
| | | |
| | | // get namespace and delimiter |
| | | $this->set_env(); |
| | | |
| | | // trigger post-connect hook |
| | | $this->plugins->exec_hook('storage_connected', array( |
| | | 'host' => $host, 'user' => $user, 'session' => $session |
| | | )); |
| | | |
| | | return true; |
| | | } |
| | | // write error log |
| | |
| | | |
| | | |
| | | /** |
| | | * protected method for getting nr of messages |
| | | * Protected method for getting number of messages |
| | | * |
| | | * @param string $folder Folder name |
| | | * @param string $mode Mode for count [ALL|THREADS|UNSEEN|RECENT|EXISTS] |
| | | * @param boolean $force Force reading from server and update cache |
| | | * @param boolean $status Enables storing folder status info (max UID/count), |
| | | * required for folder_status() |
| | | * @param string $folder Folder name |
| | | * @param string $mode Mode for count [ALL|THREADS|UNSEEN|RECENT|EXISTS] |
| | | * @param boolean $force Force reading from server and update cache |
| | | * @param boolean $status Enables storing folder status info (max UID/count), |
| | | * required for folder_status() |
| | | * @param boolean $no_search Ignore current search result |
| | | * |
| | | * @return int Number of messages |
| | | * @see rcube_imap::count() |
| | | */ |
| | | protected function countmessages($folder, $mode='ALL', $force=false, $status=true) |
| | | protected function countmessages($folder, $mode = 'ALL', $force = false, $status = true, $no_search = false) |
| | | { |
| | | $mode = strtoupper($mode); |
| | | |
| | | // count search set, assume search set is always up-to-date (don't check $force flag) |
| | | if ($this->search_string && $folder == $this->folder && ($mode == 'ALL' || $mode == 'THREADS')) { |
| | | // Count search set, assume search set is always up-to-date (don't check $force flag) |
| | | // @TODO: this could be handled in more reliable way, e.g. a separate method |
| | | // maybe in rcube_imap_search |
| | | if (!$no_search && $this->search_string && $folder == $this->folder) { |
| | | if ($mode == 'ALL') { |
| | | return $this->search_set->count_messages(); |
| | | } |
| | | else { |
| | | else if ($mode == 'THREADS') { |
| | | return $this->search_set->count(); |
| | | } |
| | | } |
| | |
| | | $old = $this->get_folder_stats($folder); |
| | | |
| | | // refresh message count -> will update |
| | | $this->countmessages($folder, 'ALL', true); |
| | | $this->countmessages($folder, 'ALL', true, true, true); |
| | | |
| | | $result = 0; |
| | | |
| | |
| | | public function index_direct($folder, $sort_field = null, $sort_order = null, $search = null) |
| | | { |
| | | if (!empty($search)) { |
| | | $search = $this->search_set->get_compressed(); |
| | | $search = $search->get_compressed(); |
| | | } |
| | | |
| | | // use message index sort as default sorting |
| | |
| | | $folder = $this->folder; |
| | | } |
| | | |
| | | $plugin = rcube::get_instance()->plugins->exec_hook('imap_search_before', array( |
| | | $plugin = $this->plugins->exec_hook('imap_search_before', array( |
| | | 'folder' => $folder, |
| | | 'search' => $search, |
| | | 'charset' => $charset, |
| | |
| | | // increase messagecount of the target folder |
| | | $this->set_messagecount($folder, 'ALL', 1); |
| | | |
| | | rcube::get_instance()->plugins->exec_hook('message_saved', array( |
| | | $this->plugins->exec_hook('message_saved', array( |
| | | 'folder' => $folder, |
| | | 'message' => $message, |
| | | 'headers' => $headers, |
| | |
| | | } |
| | | |
| | | // Give plugins a chance to provide a list of folders |
| | | $data = rcube::get_instance()->plugins->exec_hook('storage_folders', |
| | | $data = $this->plugins->exec_hook('storage_folders', |
| | | array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LSUB')); |
| | | |
| | | if (isset($data['folders'])) { |
| | |
| | | if (is_array($a_folders) && $name == '*' && !empty($this->conn->data['LIST'])) { |
| | | foreach ($a_folders as $idx => $folder) { |
| | | if (($opts = $this->conn->data['LIST'][$folder]) |
| | | && in_array('\\NonExistent', $opts) |
| | | && in_array_nocase('\\NonExistent', $opts) |
| | | ) { |
| | | $this->conn->unsubscribe($folder); |
| | | unset($a_folders[$idx]); |
| | |
| | | } |
| | | |
| | | // Give plugins a chance to provide a list of folders |
| | | $data = rcube::get_instance()->plugins->exec_hook('storage_folders', |
| | | $data = $this->plugins->exec_hook('storage_folders', |
| | | array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LIST')); |
| | | |
| | | if (isset($data['folders'])) { |
| | |
| | | if ($subscription) { |
| | | // It's possible we already called LIST command, check LIST data |
| | | if (!empty($this->conn->data['LIST']) && !empty($this->conn->data['LIST'][$folder]) |
| | | && in_array('\\Subscribed', $this->conn->data['LIST'][$folder]) |
| | | && in_array_nocase('\\Subscribed', $this->conn->data['LIST'][$folder]) |
| | | ) { |
| | | $a_folders = array($folder); |
| | | } |
| | |
| | | |
| | | // @TODO: Honor MAXSIZE and DEPTH options |
| | | foreach ($queries as $attrib => $entry) { |
| | | if ($result = $this->conn->getAnnotation($folder, $entry, $attrib)) { |
| | | $res = array_merge_recursive($res, $result); |
| | | $result = $this->conn->getAnnotation($folder, $entry, $attrib); |
| | | |
| | | // an error, invalidate any previous getAnnotation() results |
| | | if (!is_array($result)) { |
| | | return null; |
| | | } |
| | | else { |
| | | foreach ($result as $fldr => $data) { |
| | | $res[$fldr] = array_merge((array) $res[$fldr], $data); |
| | | } |
| | | } |
| | | } |
| | | } |