summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-11-27 09:34:52 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-11-27 09:35:45 (GMT)
commit109ad37debe14990b96371a53376fa8a2c6ff5f1 (patch)
treee65daff23b5ca9505ac7e413914a2016c437ca63
parente6f1a694efe87e39606580cdf6235110b6395dbe (diff)
downloadkolab-wap-109ad37debe14990b96371a53376fa8a2c6ff5f1.tar.gz
Fix email address comparissons, so local part is case-sensitive, but domain part is not
-rw-r--r--lib/Auth/LDAP.php26
-rw-r--r--lib/api/kolab_api_service_form_value.php8
-rw-r--r--lib/functions.php18
3 files changed, 47 insertions, 5 deletions
diff --git a/lib/Auth/LDAP.php b/lib/Auth/LDAP.php
index 7de9017..25cb754 100644
--- a/lib/Auth/LDAP.php
+++ b/lib/Auth/LDAP.php
@@ -593,6 +593,10 @@ class LDAP extends Net_LDAP3 {
public function find_recipient($address)
{
+ if (strpos($address, '@') === false) {
+ return false;
+ }
+
$this->bind($_SESSION['user']->user_bind_dn, $_SESSION['user']->user_bind_pw);
$mail_attrs = $this->conf->get_list('mail_attributes') ?: array('mail', 'alias');
@@ -610,10 +614,28 @@ class LDAP extends Net_LDAP3 {
$result = $this->search_entries($this->config_get('root_dn'), '(objectclass=*)', 'sub', null, $search);
if ($result && $result->count() > 0) {
- return $result->entries(TRUE);
+ $result = $result->entries(true);
+
+ // LDAP searches are case-insensitive, post-process result
+ // with correct character case handling
+ foreach ($result as $key => $user) {
+ foreach ($user as $attr => $list) {
+ foreach ((array) $list as $addr) {
+ if (compare_email($address, $addr)) {
+ continue 3;
+ }
+ }
+ }
+
+ unset($result[$key]);
+ }
+
+ reset($result);
+
+ return $result;
}
- return FALSE;
+ return false;
}
public function get_attributes($subject_dn, $attributes)
diff --git a/lib/api/kolab_api_service_form_value.php b/lib/api/kolab_api_service_form_value.php
index 1d47a9c..a8cea72 100644
--- a/lib/api/kolab_api_service_form_value.php
+++ b/lib/api/kolab_api_service_form_value.php
@@ -1090,9 +1090,11 @@ class kolab_api_service_form_value extends kolab_api_service
unset($user[$attr_name]);
foreach ($user as $attr => $list) {
- if (in_array($addr, (array) $list)) {
- $found = true;
- break;
+ foreach ((array) $list as $email) {
+ if (compare_email($addr, $email)) {
+ $found = true;
+ break 2;
+ }
}
}
diff --git a/lib/functions.php b/lib/functions.php
index 98dc949..ce73a13 100644
--- a/lib/functions.php
+++ b/lib/functions.php
@@ -131,3 +131,21 @@ function timer($time = null, $label = '')
}
return $now;
}
+
+/**
+ * Compare two email addresses with correct character-case handling
+ * i.e. local part is case-sensitive, domain part is not
+ */
+function compare_email($email1, $email2)
+{
+ $email1 = explode('@', $email1);
+ $email2 = explode('@', $email2);
+
+ $domain1 = array_pop($email1);
+ $domain2 = array_pop($email2);
+
+ $email1 = implode('@', $email1) . '@' . mb_strtolower($domain1);
+ $email2 = implode('@', $email2) . '@' . mb_strtolower($domain2);
+
+ return $email1 === $email2;
+}