diff --git a/modules/Emails/EmailsControllerActionGetFromFields.php b/modules/Emails/EmailsControllerActionGetFromFields.php index 442a13d49f8..cf2a35465ba 100644 --- a/modules/Emails/EmailsControllerActionGetFromFields.php +++ b/modules/Emails/EmailsControllerActionGetFromFields.php @@ -89,10 +89,10 @@ public function handleActionGetFromFields(Email $email, InboundEmail $ie) $ie->email = $email; $ieAccounts = $ie->retrieveAllByGroupIdWithGroupAccounts($this->currentUser->id); $accountSignatures = $this->currentUser->getPreference('account_signatures', 'Emails'); - $showFolders = sugar_unserialize(base64_decode($this->currentUser->getPreference('showFolders', 'Emails'))); + $showFolders = sugar_unserialize(base64_decode($this->currentUser->getPreference('showFolders', 'Emails'))) ?: []; $emailSignatures = $this->getEmailSignatures($accountSignatures); $defaultEmailSignature = $this->getDefaultSignatures(); - $prependSignature = $this->currentUser->getPreference('signature_prepend'); + $prependSignature = $this->currentUser->getPreference('signature_prepend') ?? false; $dataAddresses = $this->collector->collectDataAddressesFromIEAccounts( $ieAccounts, $showFolders, @@ -103,7 +103,7 @@ public function handleActionGetFromFields(Email $email, InboundEmail $ie) $dataAddresses = $dataAddresses ?? []; - $this->addOutboundEmailAccounts($dataAddresses); + $this->addOutboundEmailAccounts($dataAddresses, $prependSignature, $defaultEmailSignature); $dataEncoded = json_encode(array('data' => $dataAddresses), JSON_UNESCAPED_UNICODE); $results = mb_convert_encoding($dataEncoded, 'ISO-8859-1'); @@ -178,7 +178,7 @@ protected function getDefaultSignatures() * @param array $dataAddresses * @return void */ - protected function addOutboundEmailAccounts(array &$dataAddresses): void + protected function addOutboundEmailAccounts(array &$dataAddresses, bool $prependSignature = false, array $defaultEmailSignature = []): void { /** @var OutboundEmailAccounts $outboundAccount */ $outboundAccount = BeanFactory::newBean('OutboundEmailAccounts'); @@ -195,7 +195,7 @@ protected function addOutboundEmailAccounts(array &$dataAddresses): void $replyToAddress = $userOutboundAccount->getReplyToAddress(); $replyToName = $userOutboundAccount->getReplyToName(); $type = $userOutboundAccount->type ?? ''; - $signature = $userOutboundAccount->signature ?? ''; + $signature = $defaultEmailSignature['signature_html'] ?? $userOutboundAccount->signature ?? ''; $isPersonal = $type === 'user'; $isGroup = $type === 'group'; $entry = [ @@ -209,7 +209,7 @@ protected function addOutboundEmailAccounts(array &$dataAddresses): void 'reply_to' => $replyToAddress, 'reply_to_name' => $replyToName ], - 'prepend' => false, + 'prepend' => $prependSignature, 'isPersonalEmailAccount' => $isPersonal, 'isGroupEmailAccount' => $isGroup, 'emailSignatures' => [ diff --git a/modules/Emails/EmailsDataAddressCollector.php b/modules/Emails/EmailsDataAddressCollector.php index 4ca945eb239..62c8b3bca8c 100644 --- a/modules/Emails/EmailsDataAddressCollector.php +++ b/modules/Emails/EmailsDataAddressCollector.php @@ -493,7 +493,8 @@ protected function fillDataAddress($dataAddresses, $defaultEmailSignature, $prep ); $dataAddressesWithUserAddressesAndSystem = $this->fillDataAddressWithSystemMailerSettings( $dataAddressesWithUserAddresses, - $defaultEmailSignature + $defaultEmailSignature, + $prependSignature ); return @@ -661,9 +662,10 @@ protected function getCollectDataAddressArrayFromUserAddresses( * * @param array $dataAddresses * @param array $defaultEmailSignature + * @param boolean $prependSignature * @return array */ - protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defaultEmailSignature) + protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defaultEmailSignature, $prependSignature) { $this->setOe(new OutboundEmail()); if ($this->getOe()->isAllowUserAccessToSystemDefaultOutbound()) { @@ -674,7 +676,8 @@ protected function fillDataAddressWithSystemMailerSettings($dataAddresses, $defa $system->smtp_from_name, $system->smtp_from_addr, $system->mail_smtpuser, - $defaultEmailSignature + $defaultEmailSignature, + $prependSignature ); } @@ -744,6 +747,7 @@ protected function getOe() * @param string $fromAddr * @param string $mailUser * @param array $defaultEmailSignature + * @param boolean $prependSignature * @return array */ protected function getFillDataAddressArray( @@ -752,7 +756,8 @@ protected function getFillDataAddressArray( $fromName, $fromAddr, $mailUser, - $defaultEmailSignature + $defaultEmailSignature, + bool $prependSignature ) { $dataAddress = new EmailsDataAddress(); @@ -763,7 +768,7 @@ protected function getFillDataAddressArray( $fromAddr, $fromName, false, - false, + $prependSignature, true, $id, $name, diff --git a/modules/Emails/include/ComposeView/EmailsComposeView.js b/modules/Emails/include/ComposeView/EmailsComposeView.js index 549afbe90f5..fec45a32a02 100644 --- a/modules/Emails/include/ComposeView/EmailsComposeView.js +++ b/modules/Emails/include/ComposeView/EmailsComposeView.js @@ -59,6 +59,12 @@ */ self.prependSignature = false; + /** + * Determines if a Signature has already been added to the message + * @type {boolean} + */ + self.signatureAdded = false; + /** * Defines the buttons that are displayed when the user focuses in on a to, cc and bcc field. * @@ -347,7 +353,19 @@ return false; }; - + + /** + * Remove any existing signature element class in the email thread + * @type {self.removeExistingSignatureClass} + */ + + $.fn.EmailsComposeView.removeExistingSignatureClass = self.removeExistingSignatureClass = function() { + let body = tinymce.activeEditor.getContent(); + let $body = $('