From 230c5ccbcd302d673c2912a89636be44a17af6c6 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 3 Mar 2021 13:07:05 +0100 Subject: [PATCH] Add contact label preference in order to control displayed info for To/Cc/Bcc addresses when composing an email --- mail/inc/class.mail_compose.inc.php | 11 ++++++---- mail/inc/class.mail_hooks.inc.php | 31 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index cd58edabca..de092666a2 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -3585,6 +3585,9 @@ class mail_compose $contacts_obj = new Api\Contacts(); $results = array(); + $mailPrefs = $GLOBALS['egw_info']['user']['preferences']['mail']; + $contactLabelPref = !is_array($mailPrefs['contactLabel']) && !empty($mailPrefs['contactLabel']) ? + explode(',', $mailPrefs['contactLabel']) : $mailPrefs['contactLabel']; // Add some matching mailing lists, and some groups, limited by config if($include_lists) @@ -3655,10 +3658,10 @@ class mail_compose if (method_exists($contacts_obj,'search')) { $contact['n_fn']=''; - if (!empty($contact['n_prefix'])) $contact['n_fn'] = $contact['n_prefix']; - if (!empty($contact['n_given'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given']; - if (!empty($contact['n_family'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family']; - if (!empty($contact['org_name'])) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')'; + if (!empty($contact['n_prefix']) && (empty($contactLabelPref) || in_array('n_prefix', $contactLabelPref))) $contact['n_fn'] = $contact['n_prefix']; + if (!empty($contact['n_given']) && (empty($contactLabelPref) || in_array('n_given', $contactLabelPref))) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_given']; + if (!empty($contact['n_family']) && (empty($contactLabelPref) || in_array('n_family', $contactLabelPref))) $contact['n_fn'] .= ($contact['n_fn']?' ':'').$contact['n_family']; + if (!empty($contact['org_name']) && (empty($contactLabelPref) || in_array('org_name', $contactLabelPref))) $contact['n_fn'] .= ($contact['n_fn']?' ':'').'('.$contact['org_name'].')'; $contact['n_fn'] = str_replace(array(',','@'),' ',$contact['n_fn']); } else diff --git a/mail/inc/class.mail_hooks.inc.php b/mail/inc/class.mail_hooks.inc.php index f0290e84c9..cb4500a5bd 100644 --- a/mail/inc/class.mail_hooks.inc.php +++ b/mail/inc/class.mail_hooks.inc.php @@ -451,6 +451,37 @@ class mail_hooks 8 => lang('Ident name') ), 'default' => 7 + ), + 'contactLabel' => array( + 'type' => 'taglist', + 'label' => 'Contact label', + 'help' => 'Defines what to show as contact label for added contact into To/Cc/Bcc when composing an email. Default is firstname lastname and empty means include eveything available.', + 'name' => 'contactLabel', + 'values' => '', + 'attributes' => array( + 'allowFreeEntries' => false, + 'editModeEnabled' => false, + 'autocomplete_url' => ' ', + 'select_options' => array ( + 'n_prefix' => array ( + 'id' => 'n_prefix', + 'label' => lang('Prefix'), + ), + 'n_given' => array ( + 'id' => 'n_given', + 'label' => lang('First name') + ), + 'n_family' => array( + 'id' => 'n_family', + 'label' => lang('Last name') + ), + 'org_name' => array( + 'id' => 'org_name', + 'label' => lang('Organisation') + ) + ) + ), + 'default' => ['n_given','n_family'] ) ); if (!$GLOBALS['egw_info']['apps']['stylite']) unset($settingsArray['attachVCardAtCompose']);