From a059628f58c7d2cf6278a326ec19799c9c6fc490 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Fri, 1 Feb 2019 11:13:43 +0100 Subject: [PATCH] * Mail: take user's cutomfields type of email into account when searching for contacts in Compose -> TO field. --- api/src/Storage/Customfields.php | 22 ++++++++++++++++++++++ mail/inc/class.mail_compose.inc.php | 4 +++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/api/src/Storage/Customfields.php b/api/src/Storage/Customfields.php index bda119b3d2..460de329dd 100755 --- a/api/src/Storage/Customfields.php +++ b/api/src/Storage/Customfields.php @@ -502,6 +502,28 @@ class Customfields implements \IteratorAggregate return $types; } + /** + * Return names of custom fields containing url-email + * + * @param string $app + * @return array of url-email fields + */ + public static function get_email_cfs($app) + { + $fields = array(); + if (($cfs = self::get($app, true))) + { + foreach($cfs as $name => $data) + { + if ($data['type'] == 'url-email') + { + $fields[] = $name; + } + } + } + return $fields; + } + /** * Initialise our db * diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index a296408fd8..bcdd0bad9a 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -3592,6 +3592,7 @@ class mail_compose $filter['cols_to_search'] = array('n_prefix','n_given','n_family','org_name','email','email_home', 'contact_id', 'etag'); $cols = array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home', 'contact_id', 'etag'); $contacts = $contacts_obj->search($search_str, $cols, 'n_fn', '', '%', false, 'OR', array(0,100), $filter); + $cfs_type_email = Api\Storage\Customfields::get_email_cfs('addressbook'); // additionally search the accounts, if the contact storage is not the account storage if ($showAccounts && $contacts_obj->so_accounts) { @@ -3616,7 +3617,8 @@ class mail_compose if(is_array($contacts)) { foreach($contacts as $contact) { - foreach(array($contact['email'],$contact['email_home']) as $email) { + $cf_emails = (array)array_values(array_values($contacts_obj->read_customfields($contact['id'], $cfs_type_email))[0]); + foreach(array_merge(array($contact['email'],$contact['email_home']), $cf_emails) as $email) { // avoid wrong addresses, if an rfc822 encoded address is in addressbook //$email = preg_replace("/(^.*<)([a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-\.]+)(.*)/",'$2',$email); $rfcAddr = Mail::parseAddressList($email);