From 26824323e571a20f6a8c7ae114d9a90dea50f988 Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 12 Sep 2022 14:50:52 +0200 Subject: [PATCH] got mailing lists working again in mail compose using includeLists=true attribute using "$list_name <$list_id@lists.egroupware.org>" instead of just integer ids for the list, thought et2-select-mail is NOT displaying the mailing-list icon, after a mailing-list is selected --- api/js/etemplate/Et2Select/Et2SelectEmail.ts | 9 +++++-- api/js/etemplate/Validators/IsEmail.ts | 2 +- api/src/Etemplate/Widget/Taglist.php | 5 ++-- mail/inc/class.mail_compose.inc.php | 27 +++++++------------- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/api/js/etemplate/Et2Select/Et2SelectEmail.ts b/api/js/etemplate/Et2Select/Et2SelectEmail.ts index 3f144b68b7..4b6423d45b 100644 --- a/api/js/etemplate/Et2Select/Et2SelectEmail.ts +++ b/api/js/etemplate/Et2Select/Et2SelectEmail.ts @@ -50,6 +50,11 @@ export class Et2SelectEmail extends Et2Select */ allowDragAndDrop: {type: Boolean}, + /** + * Include mailing lists: returns them with their integer list_id + */ + includeLists: {type: Boolean}, + /** * Show the full, original value email address under all circumstances, rather than the contact name for known contacts */ @@ -65,6 +70,7 @@ export class Et2SelectEmail extends Et2Select this.allowFreeEntries = true; this.editModeEnabled = true; this.allowDragAndDrop = false; + this.includeLists = false; this.multiple = true; this.fullEmail = false; this.defaultValidators.push(new IsEmail()); @@ -75,7 +81,6 @@ export class Et2SelectEmail extends Et2Select super.connectedCallback(); } - protected _bindListeners() { super._bindListeners(); @@ -119,7 +124,7 @@ export class Et2SelectEmail extends Et2Select */ protected remoteQuery(search : string, options : object) { - return this.egw().json(this.searchUrl, [search]).sendRequest().then((result) => + return this.egw().request(this.searchUrl, [search, {includeLists: this.includeLists}]).then((result) => { this.processRemoteResults(result); }); diff --git a/api/js/etemplate/Validators/IsEmail.ts b/api/js/etemplate/Validators/IsEmail.ts index 949c74dae3..cb557a47cb 100644 --- a/api/js/etemplate/Validators/IsEmail.ts +++ b/api/js/etemplate/Validators/IsEmail.ts @@ -25,7 +25,7 @@ export class IsEmail extends Pattern * eg. in Safari 11.0 or node.js 4.8.3 and therefore grunt uglify! * Server-side will fail in that case because it uses the full regexp. */ - static EMAIL_PREG : RegExp = new RegExp(/^(([^\042',<][^,<]+|\042[^\042]+\042|\'[^\']+\'|"(?:[^"\\]|\\.)*")\s?<)?[^\x00-\x20()\xe2\x80\x8b<>@,;:\042\[\]\x80-\xff]+@([a-z0-9ÄÖÜäöüß](|[a-z0-9ÄÖÜäöüß_-]*[a-z0-9ÄÖÜäöüß])\.)+[a-z]{2,}>?$/i); + static EMAIL_PREG : RegExp = /^(([^\042',<][^,<]+|\042[^\042]+\042|\'[^\']+\'|"(?:[^"\\]|\\.)*")\s?<)?[^\x00-\x20()\xe2\x80\x8b<>@,;:\042\[\]\x80-\xff]+@([a-z0-9ÄÖÜäöüß](|[a-z0-9ÄÖÜäöüß_-]*[a-z0-9ÄÖÜäöüß])\.)+[a-z]{2,}>?$/i; constructor() { diff --git a/api/src/Etemplate/Widget/Taglist.php b/api/src/Etemplate/Widget/Taglist.php index 39b42a675f..8ac0bcaade 100644 --- a/api/src/Etemplate/Widget/Taglist.php +++ b/api/src/Etemplate/Widget/Taglist.php @@ -106,17 +106,18 @@ class Taglist extends Etemplate\Widget * * Uses the mail application if available, or addressbook */ - public static function ajax_email($search) + public static function ajax_email($search=null, array $options=null) { $_REQUEST['query'] = $_REQUEST['query'] ?: $search; // If no mail app access, use link system -> addressbook - if(!$GLOBALS['egw_info']['apps']['mail']) + if(empty($GLOBALS['egw_info']['apps']['mail'])) { $_REQUEST['app'] = 'addressbook-email'; return self::ajax_search(); } // TODO: this should go to a BO, not a UI object + $_REQUEST['include_lists'] = $options['includeLists'] ?? false; return mail_compose::ajax_searchAddress(); } diff --git a/mail/inc/class.mail_compose.inc.php b/mail/inc/class.mail_compose.inc.php index d164288b16..3522543eb2 100644 --- a/mail/inc/class.mail_compose.inc.php +++ b/mail/inc/class.mail_compose.inc.php @@ -2832,31 +2832,24 @@ class mail_compose */ static function resolveEmailAddressList($_emailAddressList) { - $contacts_obs = null; + static $contacts_obs = null; $addrFromList=array(); foreach((array)$_emailAddressList as $ak => $address) { - if(is_int($address)) + if(is_numeric($address) && $address > 0 || preg_match('/ <(\\d+)@lists.egroupware.org>$/', $address, $matches)) { if (!isset($contacts_obs)) $contacts_obj = new Api\Contacts(); // List was selected, expand to addresses unset($_emailAddressList[$ak]); - $list = $contacts_obj->search('',array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'),'','','',False,'AND',false,array('list' =>(int)$address)); - // Just add email addresses, they'll be checked below - foreach($list as $email) + foreach($contacts_obj->search('',array('n_fn','n_prefix','n_given','n_family','org_name','email','email_home'), + '','','',False,'AND',false, + ['list' => (int)($matches[1] ?? $address)]) as $email) { - $addrFromList[] = $email['email'] ? $email['email'] : $email['email_home']; + $addrFromList[] = $email['email'] ?: $email['email_home']; } } } - if (!empty($addrFromList)) - { - foreach ($addrFromList as $addr) - { - if (!empty($addr)) $_emailAddressList[]=$addr; - } - } - return is_array($_emailAddressList) ? array_values($_emailAddressList) : (array)$_emailAddressList; + return array_values(array_merge($_emailAddressList, $addrFromList)); } /** @@ -3766,12 +3759,10 @@ class mail_compose { $type = $key > 0 ? 'manual' : 'group'; $list = array( - 'id' => $key, - 'name' => $list_name, + 'value' => $list_name.' <'.$key.'@lists.egroupware.org>', 'label' => $list_name, - 'class' => 'mailinglist ' . "{$type}_list", 'title' => lang('Mailinglist'), - 'data' => $key + 'icon' => Api\Image::find('api', 'email'), ); ${"${type}_lists"}[] = $list; }