diff --git a/webui/model/search/search.php b/webui/model/search/search.php index 165756ef..dbcf5b5b 100644 --- a/webui/model/search/search.php +++ b/webui/model/search/search.php @@ -489,12 +489,10 @@ class ModelSearchSearch extends Model { if(isset($query->rows)) { foreach($query->rows as $r) { - if(!isset($rcpt[$r['id']]) && !in_array($r['to'], $SUPPRESS_RECIPIENTS)) { - $srcpt[$r['id']] = $r['to']; - $rcpt[$r['id']] = $r['to']; - } - else { - if(Registry::get('auditor_user') == 1) { $rcpt[$r['id']] .= ",\n" . $r['to']; } + if(!isset($rcpt[$r['id']])) { $rcpt[$r['id']] = []; } + + if(Registry::get('auditor_user') == 1 || !in_array($r['to'], $SUPPRESS_RECIPIENTS)) { + array_push($rcpt[$r['id']], $r['to']); } } } @@ -542,8 +540,8 @@ class ModelSearchSearch extends Model { $m['shortfrom'] = make_short_string($m['from'], MAX_CGI_FROM_SUBJ_LEN); $m['from'] = escape_gt_lt_quote_symbols($m['from']); - isset($srcpt[$m['id']]) ? $m['shortto'] = $srcpt[$m['id']] : $m['shortto'] = ''; isset($rcpt[$m['id']]) ? $m['to'] = $rcpt[$m['id']] : $m['to'] = ''; + $m['shortto'] = make_short_string($this->get_preferred_recipient($rcpt[$m['id']]), MAX_CGI_FROM_SUBJ_LEN); $m['to'] = escape_gt_lt_quote_symbols($m['to']); @@ -586,6 +584,26 @@ class ModelSearchSearch extends Model { } + private function get_preferred_recipient($arr = []) { + $result = ''; + + $session = Registry::get('session'); + $group_emails = $session->get('group_emails'); + $user_emails = $session->get('user_emails'); + + if(count($arr) < 2 || (!$group_emails && !$user_emails) ) { return $arr[0]; } + + foreach ($arr as $a) { + if($result == '' && in_array($a, $group_emails)) { $result = $a; } + if(in_array($a, $user_emails)) { $result = $a; } + } + + if($result == '') { $result = $arr[0]; } + + return $result; + } + + public function get_message_addresses_in_my_domain($id = '') { $addr = array(); $domains = array(); diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index b5728051..475634f8 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -234,7 +234,7 @@ class ModelUserAuth extends Model { if($this->check_ldap_membership($ldap_auditor_member_dn, $query->rows) == 1) { $role = 2; } if($this->check_ldap_membership($ldap_admin_member_dn, $query->rows) == 1) { $role = 1; } - $emails = $this->get_email_array_from_ldap_attr($query->rows); + $emails = $this->get_email_array_from_ldap_attr($query->rows, $ldap_distributionlist_objectclass); $extra_emails = $this->model_user_user->get_email_addresses_from_groups($emails); $emails = array_merge($emails, $extra_emails); @@ -292,11 +292,19 @@ class ModelUserAuth extends Model { } - public function get_email_array_from_ldap_attr($e = array()) { + public function get_email_array_from_ldap_attr($e = array(), $group_object_class) { global $mailattrs; $data = []; + $group_emails = []; + $user_emails = []; foreach($e as $a) { + $group_object = 0; + + if($group_object_class && in_array($group_object_class, $a['objectclass'])) { + $group_object = 1; + } + if(LOG_LEVEL >= DEBUG) { syslog(LOG_INFO, "checking ldap entry dn: " . $a['dn'] . ", cn: " . $a['cn']); } foreach ($mailattrs as $mailattr) { @@ -316,7 +324,15 @@ class ModelUserAuth extends Model { } $email = preg_replace("/^([\w]+)\:/i", "", $a[$mailattr][$i]); - if(validemail($email) && !in_array($email, $data)) { array_push($data, $email); } + if(validemail($email)) { + if(!in_array($email, $data)) { array_push($data, $email); } + + if($group_object) { + if(!in_array($email, $group_emails)) { array_push($group_emails, $email); } + } else { + if(!in_array($email, $user_emails)) { array_push($user_emails, $email); } + } + } } } } @@ -324,12 +340,25 @@ class ModelUserAuth extends Model { if(LOG_LEVEL >= DEBUG) { syslog(LOG_INFO, "checking entry #2: " . $a[$mailattr]); } $email = strtolower(preg_replace("/^([\w]+)\:/i", "", $a[$mailattr])); - if(validemail($email) && !in_array($email, $data)) { array_push($data, $email); } + if(validemail($email)) { + if(!in_array($email, $data)) { array_push($data, $email); } + + if($group_object) { + if(!in_array($email, $group_emails)) { array_push($group_emails, $email); } + } else { + if(!in_array($email, $user_emails)) { array_push($user_emails, $email); } + } + } } } } } + $session = Registry::get('session'); + + $session->set("user_emails", $user_emails); + $session->set("group_emails", $group_emails); + return $data; } diff --git a/webui/view/theme/default/templates/search/helper.tpl b/webui/view/theme/default/templates/search/helper.tpl index 92b8a511..0252d44c 100644 --- a/webui/view/theme/default/templates/search/helper.tpl +++ b/webui/view/theme/default/templates/search/helper.tpl @@ -49,7 +49,7 @@