Example #1
0
 /**
  * Private method for mailbox listing (LSUB)
  *
  * @param   string  $root   Optional root folder
  * @param   string  $name   Optional name pattern
  * @param   mixed   $filter Optional filter
  * @param   string  $rights Optional ACL requirements
  *
  * @return  array   List of subscribed folders
  * @see     rcube_imap::list_mailboxes()
  * @access  private
  */
 private function _list_mailboxes($root = '', $name = '*', $filter = null, $rights = null)
 {
     $a_defaults = $a_out = array();
     // Give plugins a chance to provide a list of mailboxes
     $data = rcmail::get_instance()->plugins->exec_hook('mailboxes_list', array('root' => $root, 'name' => $name, 'filter' => $filter, 'mode' => 'LSUB'));
     if (isset($data['folders'])) {
         $a_folders = $data['folders'];
     } else {
         if (!$this->conn->connected()) {
             return null;
         } else {
             // Server supports LIST-EXTENDED, we can use selection options
             $config = rcmail::get_instance()->config;
             // #1486225: Some dovecot versions returns wrong result using LIST-EXTENDED
             if (!$config->get('imap_force_lsub') && $this->get_capability('LIST-EXTENDED')) {
                 // This will also set mailbox options, LSUB doesn't do that
                 $a_folders = $this->conn->listMailboxes($root, $name, NULL, array('SUBSCRIBED'));
                 // unsubscribe non-existent folders, remove from the list
                 // we can do this only when LIST response is available
                 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)) {
                             $this->conn->unsubscribe($folder);
                             unset($a_folders[$idx]);
                         }
                     }
                 }
             } else {
                 $a_folders = $this->conn->listSubscribed($root, $name);
                 // unsubscribe non-existent folders, remove them from the list,
                 // we can do this only when LIST response is available
                 if (is_array($a_folders) && $name == '*' && !empty($this->conn->data['LIST'])) {
                     foreach ($a_folders as $idx => $folder) {
                         if (!isset($this->conn->data['LIST'][$folder]) || in_array('\\Noselect', $this->conn->data['LIST'][$folder])) {
                             // Some servers returns \Noselect for existing folders
                             if (!$this->mailbox_exists($folder)) {
                                 $this->conn->unsubscribe($folder);
                                 unset($a_folders[$idx]);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!is_array($a_folders) || !sizeof($a_folders)) {
         $a_folders = array();
     }
     return $a_folders;
 }
Example #2
0
 /**
  * Checks IMAP connection.
  *
  * @return boolean  TRUE on success, FALSE on failure
  */
 public function is_connected()
 {
     return $this->conn->connected();
 }
Example #3
0
 /**
  * Sets delimiter and namespaces
  *
  * @access private
  */
 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;
     }
     $config = rcmail::get_instance()->config;
     $imap_personal = $config->get('imap_ns_personal');
     $imap_other = $config->get('imap_ns_other');
     $imap_shared = $config->get('imap_ns_shared');
     $imap_delimiter = $config->get('imap_delimiter');
     if (!$this->conn->connected()) {
         return;
     }
     $ns = $this->conn->getNamespace();
     // Set namespaces (NAMESPACE supported)
     if (is_array($ns)) {
         $this->namespace = $ns;
     } else {
         $this->namespace = array('personal' => NULL, 'other' => NULL, 'shared' => NULL);
     }
     if ($imap_delimiter) {
         $this->delimiter = $imap_delimiter;
     }
     if (empty($this->delimiter)) {
         $this->delimiter = $this->namespace['personal'][0][1];
     }
     if (empty($this->delimiter)) {
         $this->delimiter = $this->conn->getHierarchyDelimiter();
     }
     if (empty($this->delimiter)) {
         $this->delimiter = '/';
     }
     // Overwrite namespaces
     if ($imap_personal !== null) {
         $this->namespace['personal'] = NULL;
         foreach ((array) $imap_personal as $dir) {
             $this->namespace['personal'][] = array($dir, $this->delimiter);
         }
     }
     if ($imap_other !== null) {
         $this->namespace['other'] = NULL;
         foreach ((array) $imap_other as $dir) {
             if ($dir) {
                 $this->namespace['other'][] = array($dir, $this->delimiter);
             }
         }
     }
     if ($imap_shared !== null) {
         $this->namespace['shared'] = NULL;
         foreach ((array) $imap_shared as $dir) {
             if ($dir) {
                 $this->namespace['shared'][] = array($dir, $this->delimiter);
             }
         }
     }
     $_SESSION['imap_namespace'] = $this->namespace;
     $_SESSION['imap_delimiter'] = $this->delimiter;
 }