From 8a8de3094932244cfc4f431edc69c89d547189ef Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 20 Feb 2025 16:08:54 +0200 Subject: [PATCH] ref --- application/Espo/Repositories/Email.php | 42 ++++++++++++++++--------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 86d3378612..8299f2e626 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -75,31 +75,43 @@ class Email extends Database implements self::ADDRESS_REPLY_TO, ]; - protected function prepareAddresses(EmailEntity $entity, string $type, bool $addAssignedUser = false): void - { + private function prepareAddresses( + EmailEntity $entity, + string $type, + bool $addAssignedUser = false, + bool $skipUsers = false, + ): void { + if (!$entity->has($type)) { return; } + $link = $type . 'EmailAddresses'; + $addressValue = $entity->get($type); - $idList = []; - if ($addressValue) { - $addressList = $this->explodeAndPrepareAddressList($addressValue); + if (!$addressValue) { + $entity->setLinkMultipleIdList($link, []); - $idList = $this->getEmailAddressRepository()->getIdListFormAddressList($addressList); - - if ($type !== self::ADDRESS_REPLY_TO) { - foreach ($idList as $id) { - $this->addUserByEmailAddressId($entity, $id, $addAssignedUser); - } - } + return; } - $entity->setLinkMultipleIdList($type . 'EmailAddresses', $idList); + $addressList = $this->explodeAndPrepareAddressList($addressValue); + + $ids = $this->getEmailAddressRepository()->getIdListFormAddressList($addressList); + + $entity->setLinkMultipleIdList($link, $ids); + + if ($skipUsers) { + return; + } + + foreach ($ids as $id) { + $this->addUserByEmailAddressId($entity, $id, $addAssignedUser); + } } - protected function addUserByEmailAddressId( + private function addUserByEmailAddressId( EmailEntity $entity, string $emailAddressId, bool $addAssignedUser = false @@ -491,7 +503,7 @@ class Email extends Database implements } if ($entity->has(self::ADDRESS_REPLY_TO)) { - $this->prepareAddresses($entity, self::ADDRESS_REPLY_TO); + $this->prepareAddresses($entity, self::ADDRESS_REPLY_TO, false, true); } }