| | |
| | | function __construct() |
| | | { |
| | | $this->conn = new rcube_imap_generic(); |
| | | |
| | | // Set namespace and delimiter from session, |
| | | // so some methods would work before connection |
| | | if (isset($_SESSION['imap_namespace'])) |
| | | $this->namespace = $_SESSION['imap_namespace']; |
| | | if (isset($_SESSION['imap_delimiter'])) |
| | | $this->delimiter = $_SESSION['imap_delimiter']; |
| | | } |
| | | |
| | | |
| | |
| | | private function set_env() |
| | | { |
| | | if ($this->delimiter !== null && $this->namespace !== null) { |
| | | return; |
| | | } |
| | | |
| | | if (isset($_SESSION['imap_namespace']) && isset($_SESSION['imap_delimiter'])) { |
| | | $this->namespace = $_SESSION['imap_namespace']; |
| | | $this->delimiter = $_SESSION['imap_delimiter']; |
| | | return; |
| | | } |
| | | |
| | |
| | | // try to subscribe it |
| | | if ($result) { |
| | | // clear cache |
| | | $this->clear_cache('/^mailboxes.*/', true); |
| | | $this->clear_cache('mailboxes', true); |
| | | |
| | | if ($subscribe) |
| | | $this->subscribe($mailbox); |
| | |
| | | |
| | | // clear cache |
| | | $this->clear_message_cache($mailbox.'.msg'); |
| | | $this->clear_cache('/^mailboxes.*/', true); |
| | | $this->clear_cache('mailboxes', true); |
| | | } |
| | | |
| | | return $result; |
| | |
| | | |
| | | // clear mailbox-related cache |
| | | $this->clear_message_cache($mailbox.'.msg'); |
| | | $this->clear_cache('/^mailboxes.*/', true); |
| | | $this->clear_cache('mailboxes', true); |
| | | } |
| | | |
| | | return $result; |
| | |
| | | $opts = $this->conn->data['LIST'][$mailbox]; |
| | | |
| | | return is_array($opts) ? $opts : array(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Returns extended information about the folder |
| | | * |
| | | * @param string $mailbox Folder name |
| | | * |
| | | * @return array Data |
| | | */ |
| | | function mailbox_info($mailbox) |
| | | { |
| | | $acl = $this->get_capability('ACL'); |
| | | $namespace = $this->get_namespace(); |
| | | $options = array(); |
| | | |
| | | // check if the folder is a namespace prefix |
| | | if (!empty($namespace)) { |
| | | $mbox = $mailbox . $this->delimiter; |
| | | foreach ($namespace as $ns) { |
| | | if (!empty($ns)) { |
| | | foreach ($ns as $item) { |
| | | if ($item[0] === $mbox) { |
| | | $options['is_root'] = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | $options['name'] = $mailbox; |
| | | $options['options'] = $this->mailbox_options($mailbox, true); |
| | | $options['namespace'] = $this->mailbox_namespace($mailbox); |
| | | $options['rights'] = $acl && !$options['is_root'] ? (array)$this->my_rights($mailbox) : array(); |
| | | $options['special'] = in_array($mailbox, $this->default_folders); |
| | | |
| | | if (is_array($options['options'])) { |
| | | foreach ($options['options'] as $opt) { |
| | | $opt = strtolower($opt); |
| | | if ($opt == '\noselect' || $opt == '\nonexistent') { |
| | | $options['noselect'] = true; |
| | | } |
| | | } |
| | | } |
| | | else { |
| | | $options['noselect'] = true; |
| | | } |
| | | |
| | | if (!empty($options['rights'])) { |
| | | $options['norename'] = !in_array('x', $options['rights']) && |
| | | (!in_array('c', $options['rights']) || !in_array('d', $options['rights'])); |
| | | if (!$options['noselect']) { |
| | | $options['noselect'] = !in_array('r', $options['rights']); |
| | | } |
| | | } |
| | | |
| | | return $options; |
| | | } |
| | | |
| | | |
| | |
| | | /** |
| | | * Enable or disable indexes caching |
| | | * |
| | | * @param boolean $type Cache type (memcache' or 'db') |
| | | * @param boolean $type Cache type (@see rcmail::get_cache) |
| | | * @access public |
| | | */ |
| | | function set_caching($type) |
| | |
| | | /** |
| | | * Clears the cache. |
| | | * |
| | | * @param string $key Cache key name or pattern |
| | | * @param boolean $pattern_mode Enable it to clear all keys with name |
| | | * matching PREG pattern in $key |
| | | * @param string $key Cache key name or pattern |
| | | * @param boolean $prefix_mode Enable it to clear all keys starting |
| | | * with prefix specified in $key |
| | | * @access public |
| | | */ |
| | | function clear_cache($key=null, $pattern_mode=false) |
| | | function clear_cache($key=null, $prefix_mode=false) |
| | | { |
| | | if ($this->cache) { |
| | | $this->cache->remove($key, $pattern_mode); |
| | | $this->cache->remove($key, $prefix_mode); |
| | | } |
| | | } |
| | | |
| | |
| | | $updated = $this->conn->unsubscribe($mailbox); |
| | | } |
| | | |
| | | // get cached mailbox list |
| | | // clear cached mailbox list(s) |
| | | if ($updated) { |
| | | $a_mailbox_cache = $this->get_cache('mailboxes'); |
| | | if (!is_array($a_mailbox_cache)) |
| | | return $updated; |
| | | |
| | | // modify cached list |
| | | if ($mode == 'subscribe') |
| | | $a_mailbox_cache = array_merge($a_mailbox_cache, $a_mboxes); |
| | | else if ($mode == 'unsubscribe') |
| | | $a_mailbox_cache = array_diff($a_mailbox_cache, $a_mboxes); |
| | | |
| | | // write mailboxlist to cache |
| | | $this->update_cache('mailboxes', $this->_sort_mailbox_list($a_mailbox_cache)); |
| | | $this->clear_cache('mailboxes', true); |
| | | } |
| | | |
| | | return $updated; |