From 8bed5e0151eb375e2d2dc91e4e6c6d5aa62daa5c Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sun, 19 Jul 2015 05:06:48 -0400
Subject: [PATCH] Fix regression where compose editor mode was set incorrectly

---
 program/lib/Roundcube/rcube_ldap.php |   56 +++++++++++++++++++++-----------------------------------
 1 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index f492111..e8f9a8e 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -1,6 +1,6 @@
 <?php
 
-/*
+/**
  +-----------------------------------------------------------------------+
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2006-2013, The Roundcube Dev Team                       |
@@ -239,10 +239,9 @@
         $this->_connect();
     }
 
-
     /**
-    * Establish a connection to the LDAP server
-    */
+     * Establish a connection to the LDAP server
+     */
     private function _connect()
     {
         $rcube = rcube::get_instance();
@@ -283,12 +282,21 @@
                 }
 
                 // Get the pieces needed for variable replacement.
-                if ($fu = $rcube->get_user_email())
+                if ($fu = $rcube->get_user_email()) {
                     list($u, $d) = explode('@', $fu);
-                else
+                }
+                else {
                     $d = $this->mail_domain;
+                }
 
                 $dc = 'dc='.strtr($d, array('.' => ',dc=')); // hierarchal domain string
+
+                // resolve $dc through LDAP
+                if (!empty($this->prop['domain_filter']) && !empty($this->prop['search_bind_dn']) &&
+                        method_exists($this->ldap, 'domain_root_dn')) {
+                    $this->ldap->bind($this->prop['search_bind_dn'], $this->prop['search_bind_pw']);
+                    $dc = $this->ldap->domain_root_dn($d);
+                }
 
                 $replaces = array('%dn' => '', '%dc' => $dc, '%d' => $d, '%fu' => $fu, '%u' => $u);
 
@@ -430,7 +438,6 @@
         return $this->ready;
     }
 
-
     /**
      * Close connection to LDAP server
      */
@@ -441,7 +448,6 @@
         }
     }
 
-
     /**
      * Returns address book name
      *
@@ -451,7 +457,6 @@
     {
         return $this->prop['name'];
     }
-
 
     /**
      * Set internal list page
@@ -475,7 +480,6 @@
         $this->ldap->set_vlv_page($this->list_page, $this->page_size);
     }
 
-
     /**
      * Set internal sort settings
      *
@@ -488,7 +492,6 @@
             $this->sort_col = $this->coltypes[$sort_col]['attributes'][0];
     }
 
-
     /**
      * Save a search string for future listings
      *
@@ -498,7 +501,6 @@
     {
         $this->filter = $filter;
     }
-
 
     /**
      * Getter for saved search properties
@@ -510,7 +512,6 @@
         return $this->filter;
     }
 
-
     /**
      * Reset all saved results and search parameters
      */
@@ -521,14 +522,13 @@
         $this->filter = '';
     }
 
-
     /**
      * List the current set of contact records
      *
-     * @param  array  List of cols to show
-     * @param  int    Only return this number of records
+     * @param array List of cols to show
+     * @param int   Only return this number of records
      *
-     * @return array  Indexed list of contact records, each a hash array
+     * @return array Indexed list of contact records, each a hash array
      */
     function list_records($cols=null, $subset=0)
     {
@@ -727,7 +727,6 @@
         return strcmp($a[$this->sort_col][0], $b[$this->sort_col][0]);
     }
 
-
     /**
      * Search contacts
      *
@@ -834,13 +833,12 @@
             }
             else {
                 // map address book fields into ldap attributes
-                $me         = $this;
                 $attributes = array();
-                array_walk($fields, function($field) use ($me, &$attributes) {
-                    if ($me->coltypes[$field] && ($attrs = (array)$me->coltypes[$field]['attributes'])) {
-                        $attributes = array_merge($attributes, $attrs);
+                foreach ((array) $fields as $field) {
+                    if ($this->coltypes[$field] && ($attrs = $this->coltypes[$field]['attributes'])) {
+                        $attributes = array_merge($attributes, (array) $attrs);
                     }
-                });
+                }
             }
 
             // compose a full-text-like search filter
@@ -883,7 +881,6 @@
         return $this->result;
     }
 
-
     /**
      * Count number of available contacts in database
      *
@@ -911,7 +908,6 @@
 
         return new rcube_result_set($count, ($this->list_page-1) * $this->page_size);
     }
-
 
     /**
      * Return the last result set
@@ -980,7 +976,6 @@
 
         return $err;
     }
-
 
     /**
      * Check the given data before saving.
@@ -1053,7 +1048,6 @@
         return true;
     }
 
-
     /**
      * Create a new contact record
      *
@@ -1122,7 +1116,6 @@
 
         return $dn;
     }
-
 
     /**
      * Update a specific contact record
@@ -1305,7 +1298,6 @@
         return $newdn ? $newdn : true;
     }
 
-
     /**
      * Mark one or more contact records as deleted
      *
@@ -1354,7 +1346,6 @@
 
         return count($ids);
     }
-
 
     /**
      * Remove all contact records
@@ -1424,7 +1415,6 @@
         }
     }
 
-
     /**
      * Converts LDAP entry into an array
      */
@@ -1483,7 +1473,6 @@
         return $out;
     }
 
-
     /**
      * Return LDAP attribute(s) for the given field
      */
@@ -1491,7 +1480,6 @@
     {
         return (array)$this->coltypes[$field]['attributes'];
     }
-
 
     /**
      * Convert a record data set into LDAP field attributes
@@ -2034,7 +2022,6 @@
         return $default;
     }
 
-
     /**
      * HTML-safe DN string encoding
      *
@@ -2061,5 +2048,4 @@
         $str = str_pad(strtr($str, '-_', '+/'), strlen($str) % 4, '=', STR_PAD_RIGHT);
         return base64_decode($str);
     }
-
 }

--
Gitblit v1.9.1