Aleksander Machniak
2015-09-02 5eb9c70b605cc442c4f49366b6eb765a867b4638
Added method to determine IMAP server vendor, for future use
3 files modified
62 ■■■■■ changed files
config/defaults.inc.php 5 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_imap.php 50 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_imap_generic.php 7 ●●●●● patch | view | raw | blame | history
config/defaults.inc.php
@@ -165,6 +165,11 @@
// Otherwise it will be determined automatically
$config['imap_delimiter'] = null;
// If you know your imap's folder vendor, you can specify it here.
// Otherwise it will be determined automatically. Use lower-case
// identifiers, e.g. 'dovecot', 'cyrus', 'gmail', 'hmail', 'uw-imap'.
$config['imap_vendor'] = null;
// If IMAP server doesn't support NAMESPACE extension, but you're
// using shared folders or personal root folder is non-empty, you'll need to
// set these options. All can be strings or arrays of strings.
program/lib/Roundcube/rcube_imap.php
@@ -81,7 +81,7 @@
     */
    public function __construct()
    {
        $this->conn = new rcube_imap_generic();
        $this->conn    = new rcube_imap_generic();
        $this->plugins = rcube::get_instance()->plugins;
        // Set namespace and delimiter from session,
@@ -469,7 +469,7 @@
            return;
        }
        $config = rcube::get_instance()->config;
        $config         = rcube::get_instance()->config;
        $imap_personal  = $config->get('imap_ns_personal');
        $imap_other     = $config->get('imap_ns_other');
        $imap_shared    = $config->get('imap_ns_shared');
@@ -541,6 +541,52 @@
    }
    /**
     * Returns IMAP server vendor name
     *
     * @return string Vendor name
     * @since 1.2
     */
    public function get_vendor()
    {
        if ($_SESSION['imap_vendor'] !== null) {
            return $_SESSION['imap_vendor'];
        }
        $config      = rcube::get_instance()->config;
        $imap_vendor = $config->get('imap_vendor');
        if ($imap_vendor) {
            return $imap_vendor;
        }
        if (!$this->check_connection()) {
            return;
        }
        if (($ident = $this->conn->data['ID']) === null) {
            $ident = $this->conn->id(array(
                    'name'    => 'Roundcube',
                    'version' => RCUBE_VERSION,
                    'php'     => PHP_VERSION,
                    'os'      => PHP_OS,
            ));
        }
        $vendor  = (string) (!empty($ident) ? $ident['name'] : '');
        $ident   = strtolower($vendor . ' ' . $this->conn->data['GREETING']);
        $vendors = array('cyrus', 'dovecot', 'uw-imap', 'gmail', 'hmail');
        foreach ($vendors as $v) {
            if (strpos($ident, $v) !== false) {
                $vendor = $v;
                break;
            }
        }
        return $_SESSION['imap_vendor'] = $vendor;
    }
    /**
     * Get message count for a specific folder
     *
     * @param  string  $folder  Folder name
program/lib/Roundcube/rcube_imap_generic.php
@@ -819,7 +819,7 @@
        // Send ID info
        if (!empty($this->prefs['ident']) && $this->getCapability('ID')) {
            $this->id($this->prefs['ident']);
            $this->data['ID'] = $this->id($this->prefs['ident']);
        }
        $auth_method  = $this->prefs['auth_type'];
@@ -967,6 +967,8 @@
            $this->closeConnection();
            return false;
        }
        $this->data['GREETING'] = trim(preg_replace('/\[[^\]]+\]\s*/', '', $line));
        // RFC3501 [7.1] optional CAPABILITY response
        if (preg_match('/\[CAPABILITY ([^]]+)\]/i', $line, $matches)) {
@@ -1621,7 +1623,7 @@
     * @return array Server identification information key/value hash
     * @since 0.6
     */
    function id($items=array())
    function id($items = array())
    {
        if (is_array($items) && !empty($items)) {
            foreach ($items as $key => $value) {
@@ -1633,7 +1635,6 @@
        list($code, $response) = $this->execute('ID', array(
            !empty($args) ? '(' . implode(' ', (array) $args) . ')' : $this->escape(null)
        ));
        if ($code == self::ERROR_OK && preg_match('/\* ID /i', $response)) {
            $response = substr($response, 5); // remove prefix "* ID "