diff -urN ../z-push-2.6.4+0.orig/src/backend/searchldap/config.php ./src/backend/searchldap/config.php --- ../z-push-2.6.4+0.orig/src/backend/searchldap/config.php 2021-06-25 11:55:30.000000000 +0300 +++ ./src/backend/searchldap/config.php 2023-06-19 17:31:14.319954000 +0300 @@ -56,3 +56,5 @@ // Fallback to displayname if firstname and lastname not set define("LDAP_SEARCH_NAME_FALLBACK", false); + +define("FIX_DOMAIN_SEARCH", true); diff -urN ../z-push-2.6.4+0.orig/src/backend/searchldap/searchldap.php ./src/backend/searchldap/searchldap.php --- ../z-push-2.6.4+0.orig/src/backend/searchldap/searchldap.php 2021-06-25 11:55:30.000000000 +0300 +++ ./src/backend/searchldap/searchldap.php 2023-09-26 19:44:53.253642000 +0300 @@ -149,10 +149,26 @@ } } + if (defined('FIX_DOMAIN_SEARCH') and (FIX_DOMAIN_SEARCH === true) and (isset($items[$rc][SYNC_GAL_EMAILADDRESS]))) { + if (!empty($items[$rc][SYNC_GAL_DISPLAYNAME])) $items[$rc][SYNC_GAL_DISPLAYNAME] = preg_replace('/@(\S+)/', ' ($1)', $items[$rc][SYNC_GAL_DISPLAYNAME]); + if (!empty($items[$rc][SYNC_GAL_FIRSTNAME])) $items[$rc][SYNC_GAL_FIRSTNAME] = preg_replace('/@(\S+)/', ' ($1)', $items[$rc][SYNC_GAL_FIRSTNAME]); + if (!empty($items[$rc][SYNC_GAL_LASTNAME])) $items[$rc][SYNC_GAL_LASTNAME] = preg_replace('/@(\S+)/', ' ($1)', $items[$rc][SYNC_GAL_LASTNAME]); + list($local_part, $domain) = preg_split('/@/', $items[$rc][SYNC_GAL_EMAILADDRESS]); + if ( + (mb_stripos($domain, $searchquery) !== false) + and (mb_stripos($local_part, $searchquery) === false) + and (isset($items[$rc][SYNC_GAL_DISPLAYNAME])) + and (mb_stripos(preg_replace('/@.+$/', '', $items[$rc][SYNC_GAL_DISPLAYNAME]), $searchquery) === false) + ) { + $items[$rc][SYNC_GAL_DISPLAYNAME] .= ' (' . $domain . ')'; + } + } + // fallback to displayname if firstname and lastname not set if (LDAP_SEARCH_NAME_FALLBACK && (!isset($items[$rc][SYNC_GAL_LASTNAME]) && !isset($items[$rc][SYNC_GAL_FIRSTNAME])) && isset($items[$rc][SYNC_GAL_DISPLAYNAME])) { $items[$rc][SYNC_GAL_LASTNAME] = $items[$rc][SYNC_GAL_DISPLAYNAME]; } + $rc++; } }