2 commits - lib/api lib/Auth lib/Auth.php

Jeroen van Meeuwen vanmeeuwen at kolabsys.com
Wed Dec 26 14:36:20 CET 2012


 lib/Auth.php                             |    5 ++
 lib/Auth/LDAP.php                        |   29 ++++++++++++++++
 lib/api/kolab_api_service_form_value.php |   53 ++++++++++++++++++++++++++++++-
 3 files changed, 86 insertions(+), 1 deletion(-)

New commits:
commit d54c4e23e2fdf1e32cab5123e9de0889065a7885
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Dec 26 14:35:12 2012 +0100

    Attach generate_secondary_mail() to finding (other) recipients that may already have the recipient address in use.

diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 257c570..2e67adb 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -681,9 +681,60 @@ class kolab_api_service_form_value extends kolab_api_service
                 }
             }
 
-            $secondary_mail_addresses = kolab_recipient_policy::secondary_mail($postdata);
+            $_secondary_mail_addresses = kolab_recipient_policy::secondary_mail($postdata);
 
             // TODO: Check for uniqueness. Not sure what to do if not unique.
+            $secondary_mail_addresses = Array();
+
+            $auth = Auth::get_instance();
+            $conf = Conf::get_instance();
+
+            // Find the authentication mechanism in order to be able to fall back from a
+            // '[$domain]' section setting for the mail attributes list, to an '[$auth_mech]'
+            // section setting
+            $auth_mech = $conf->get($_SESSION['user']->get_domain(), 'auth_mechanism');
+            if (empty($auth_mech)) {
+                $auth_mech = $conf->get('kolab', 'auth_mechanism');
+            }
+            if (empty($auth_mech)) {
+                $auth_mech = 'ldap';
+            }
+
+            $mail_attrs = $conf->get_list($_SESSION['user']->get_domain(), 'mail_attributes');
+            if (empty($mail_attrs)) {
+                $mail_attrs = $conf->get_list($auth_mech, 'mail_attributes');
+            }
+            if (empty($mail_attrs)) {
+                $mail_attrs = array('mail', 'alias');
+            }
+
+            foreach ($_secondary_mail_addresses as $num => $alias) {
+                list($_local, $_domain) = explode("@", $alias);
+                $local = $_local;
+
+                $x = 2;
+                while (($user_found = $auth->find_recipient($local . "@" . $_domain))) {
+                    Log::trace(__FUNCTION__ . ": An entry with address " . $local . "@" . $_domain . " was found.");
+
+                    if (!empty($postdata['id'])) {
+                        $user_found_dn = key($user_found);
+                        $user_found_unique_attr = $auth->get_entry_attribute($user_found_dn, $unique_attr);
+                        if ($user_found_unique_attr == $postdata['id']) {
+                            Log::trace(__FUNCTION__ . ": Entry with address " . $local . "@" . $_domain . " is actually us.");
+                            break;
+                        }
+                    } // empty($postdata['id'])
+
+                    // Otherwise this is a new user and therefore the entry found with
+                    // this address is definitely not us
+
+                    $local = $_local . $x;
+                    $x++;
+                }
+
+                $secondary_mail_addresses[] = $local . "@" . $_domain;
+
+            }
 
             return $secondary_mail_addresses;
         }


commit ac639948dd199355a2b409a9348f88f34792b9b4
Author: Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen at kolabsys.com>
Date:   Wed Dec 26 14:34:17 2012 +0100

    Add a function find_recipient in order to determine whether a specific recipient address is in use already

diff --git a/lib/Auth.php b/lib/Auth.php
index d7a0467..26f1d0b 100644
--- a/lib/Auth.php
+++ b/lib/Auth.php
@@ -234,6 +234,11 @@ class Auth {
         return $this->auth_instance()->domain_info($domaindata);
     }
 
+    public function find_recipient($address)
+    {
+        return $this->auth_instance()->find_recipient($address);
+    }
+
     public function find_user_groups($member_dn)
     {
         return $this->auth_instance()->find_user_groups($member_dn);
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 60a870c..15b3057 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -243,6 +243,35 @@ class LDAP extends Net_LDAP3 {
 
     }
 
+    public function find_recipient($address)
+    {
+        $this->bind($_SESSION['user']->user_bind_dn, $_SESSION['user']->user_bind_pw);
+
+        $mail_attrs = $this->conf->get_list('mail_attributes', array('mail', 'alias'));
+
+        $search = array(
+                'params' => array(
+                        'type' => 'exact'
+                    ),
+                'operator' => "OR"
+            );
+
+        foreach ($mail_attrs as $num => $attr) {
+            $search['params'][$attr] = array(
+                        'type' => 'exact',
+                        'value' => $address,
+                );
+        }
+
+        $result = $this->search_entries($this->config_get('root_dn'), '(objectclass=*)', 'sub', null, $search);
+
+        if ($result->count() > 0) {
+            return $result->entries(TRUE);
+        } else {
+            return FALSE;
+        }
+    }
+
     public function get_attributes($subject_dn, $attributes)
     {
         $this->_log(LOG_DEBUG, "Auth::LDAP::get_attributes() for $subject_dn");





More information about the commits mailing list