Changed how replied-to messages are wrapped.
[squirrelmail.git] / functions / abook_ldap_server.php
index dcf189d39419e9e26b1594bb5192286aff5023b3..1b9562b9c2509442caec5f91d7672db9ac92304c 100644 (file)
@@ -15,6 +15,8 @@
    **   ? name      => Name for LDAP server (default "LDAP: hostname")
    **                  Used to tag the result data
    **   ? maxrows   => Maximum # of rows in search result
+   **   ? timeout   => Timeout for LDAP operations (in seconds, default: 30)
+   **                  Might not work for all LDAP libraries or servers.
    **
    **  NOTE. This class should not be used directly. Use the
    **        "AddressBook" class instead.
      var $linkid  = false;        // PHP LDAP link ID
      var $bound   = false;        // True if LDAP server is bound
      var $maxrows = 250;          // Max rows in result
-     
+     var $timeout = 30;           // Timeout for LDAP operations (in seconds)
 
      // Constructor. Connects to database
      function abook_ldap_server($param) {
+       if(!function_exists("ldap_connect")) {
+         $this->set_error("LDAP support missing from PHP");
+         return;
+       }
        if(is_array($param)) {
         $this->server = $param["host"];
         $this->basedn = $param["base"];
@@ -46,6 +52,8 @@
           $this->charset = strtolower($param["charset"]);
         if(isset($param["maxrows"]))
           $this->maxrows = $param["maxrows"];
+        if(isset($param["timeout"]))
+          $this->timeout = $param["timeout"];
         if(empty($param["name"]))
           $this->sname = "LDAP: ".$param["host"];
         else
        if(!$this->open())
         return false;
 
-       // Do the search
-       $sret = @ldap_search($this->linkid, $this->basedn, $expression,
-                           array("dn", "o", "ou", "sn", "givenname", 
-                                 "cn", "mail", "telephonenumber"));
+       // Do the search. Use improved ldap_search() if PHP version is
+       // 4.0.2 or newer.
+       if(sqCheckPHPVersion(4, 0, 2)) {
+         $sret = @ldap_search($this->linkid, $this->basedn, $expression,
+                              array("dn", "o", "ou", "sn", "givenname", 
+                                    "cn", "mail", "telephonenumber"),
+                              0, $this->maxrows, $this->timeout);
+       } else {
+         $sret = @ldap_search($this->linkid, $this->basedn, $expression,
+                              array("dn", "o", "ou", "sn", "givenname", 
+                                    "cn", "mail", "telephonenumber"));
+       }
 
        // Should get error from server using the ldap_error() function,
        // but it only exist in the PHP LDAP documentation.