From b7c359a6f1ada0847d6e227d5be13e239534cfaf Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Tue, 25 Sep 2018 15:00:01 +0200 Subject: [PATCH] * Mail: implement new preference to configure mail identity label shown as mail folder header --- api/src/Mail/Account.php | 8 +++-- mail/inc/class.mail_hooks.inc.php | 17 +++++++++ mail/inc/class.mail_tree.inc.php | 59 ++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 3 deletions(-) diff --git a/api/src/Mail/Account.php b/api/src/Mail/Account.php index 4ef292f0d3..456248c0d1 100644 --- a/api/src/Mail/Account.php +++ b/api/src/Mail/Account.php @@ -1553,9 +1553,9 @@ class Account implements \ArrayAccess * @param array|Account $account object or values for keys 'ident_(realname|org|email)', 'acc_(id|name|imap_username)' * @param boolean $replace_placeholders =true should placeholders like {{n_fn}} be replaced * @param int $account_id =null account_id of user we are called for - * @return string with htmlencoded angle brackets + * @return string|array with htmlencoded angle brackets, returns account details as array if return_array is true */ - public static function identity_name($account, $replace_placeholders=true, $account_id=null) + public static function identity_name($account, $replace_placeholders=true, $account_id=null, $return_array=false) { if ($replace_placeholders) { @@ -1605,6 +1605,10 @@ class Account implements \ArrayAccess _egw_log_exception($e); } } + if ($return_array) + { + return $account; + } if (strlen(trim($account['ident_realname'].$account['ident_org']))) { $name = $account['ident_realname'].' '.$account['ident_org']; diff --git a/mail/inc/class.mail_hooks.inc.php b/mail/inc/class.mail_hooks.inc.php index 66aef29d9c..421f7d9de6 100644 --- a/mail/inc/class.mail_hooks.inc.php +++ b/mail/inc/class.mail_hooks.inc.php @@ -419,6 +419,23 @@ class mail_hooks 'autocomplete_url' => ' ', 'select_options' => $toggledOnActions ) + ), + 'identLabel' => array( + 'type' => 'select', + 'label' => 'Identity label', + 'help' => 'Defines what to show as identity label on mail folder header', + 'name' => 'identLabel', + 'values' => array( + 7 => lang('Real name Organization Email'), + 3 => lang('Real name Email'), + 14 => lang('Ident name Organization Email'), + 10 => lang('Ident name Email'), + 1 => lang('Real name'), + 2 => lang('Email'), + 4 => lang('Organization'), + 8 => lang('Ident name') + ), + 'default' => 7 ) ); if (!$GLOBALS['egw_info']['apps']['stylite']) unset($settingsArray['attachVCardAtCompose']); diff --git a/mail/inc/class.mail_tree.inc.php b/mail/inc/class.mail_tree.inc.php index c531973746..4e226554df 100644 --- a/mail/inc/class.mail_tree.inc.php +++ b/mail/inc/class.mail_tree.inc.php @@ -29,6 +29,23 @@ class mail_tree */ const DELIMITER = Mail::DELIMITER; + /** + * bit flag: ident_realname + */ + const IDENT_NAME = 1; + /** + * bit flag: ident_email + */ + const IDENT_EMAIL = 2; + /** + * bit flag: ident_org + */ + const IDENT_ORG = 4; + /** + * bit flag: ident_name + */ + const IDENT_NAME_IDENTITY= 8; + /** * Icons used for nodes different states * @@ -460,7 +477,7 @@ class mail_tree foreach(Mail\Account::search(true, false) as $acc_id => $accObj) { if (!$accObj->is_imap()|| $_profileID && $acc_id != $_profileID) continue; - $identity = Mail\Account::identity_name($accObj,true,$GLOBALS['egw_info']['user']['acount_id']); + $identity = self::getIdentityName(Mail\Account::identity_name($accObj,true,$GLOBALS['egw_info']['user']['acount_id'], true)); // Open top level folders for active account $openActiveAccount = $GLOBALS['egw_info']['user']['preferences']['mail']['ActiveProfileID'] == $acc_id?1:0; @@ -516,4 +533,44 @@ class mail_tree } return $tree; } + + /** + * Build folder tree parent identity label + * + * @param array $_account + * @return string + */ + static function getIdentityName ($_account) + { + $identLabel = $GLOBALS['egw_info']['user']['preferences']['mail']['identLabel']; + $name = array(); + + if ($identLabel & self::IDENT_NAME_IDENTITY) + { + $name[] = $_account['ident_name']; + } + + if ($identLabel & self::IDENT_NAME) + { + $name[] = $_account['ident_realname']. ' '; + } + + if ($identLabel & self::IDENT_ORG) + { + $name[] = $_account['ident_org']; + } + + if ($identLabel & self::IDENT_EMAIL || empty($name)) + { + if (strpos($_account['ident_email'], '@') !== false || trim($_account['ident_email']) !='') + { + $name[] = ' <'.$_account['ident_email'].'>'; + } + elseif(strpos($_account['acc_imap_username'], '@') !== false || trim($_account['acc_imap_username']) !='') + { + $name[] = ' <'.$_account['acc_imap_username'].'>'; + } + } + return implode(' ', $name); + } }