Skip to content

Commit

Permalink
group email account exclude from reply
Browse files Browse the repository at this point in the history
  • Loading branch information
yurikuzn committed May 13, 2024
1 parent 316a865 commit e99fca0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
4 changes: 3 additions & 1 deletion application/Espo/Resources/i18n/en_US/InboundEmail.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"storeSentEmails": "Store Sent Emails",
"keepFetchedEmailsUnread": "Keep Fetched Emails Unread",
"connectedAt": "Connected At",
"excludeFromReply": "Exclude from Reply",
"useImap": "Fetch Emails",
"useSmtp": "Use SMTP",
"smtpHost": "SMTP Host",
Expand Down Expand Up @@ -56,7 +57,8 @@
"smtpIsShared": "If checked then users will be able to send emails using this SMTP. Availability is controlled by Roles through the Group Email Account permission.",
"smtpIsForMassEmail": "If checked then SMTP will be available for Mass Email.",
"storeSentEmails": "Sent emails will be stored on the IMAP server.",
"groupEmailFolder": "Put incoming emails in a group folder."
"groupEmailFolder": "Put incoming emails in a group folder.",
"excludeFromReply": "When replying on emails sent to this account's email address, its email address won't be added to CC.\n\nNote that by enabling this parameter, the email address of this account will be exposed to users who have access to send Emails."
},
"links": {
"filters": "Filters",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
[
{"name":"addAllTeamUsers"},
false
{"name": "excludeFromReply"}
]
],
"tabBreak": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
"type": "datetime",
"readOnly": true
},
"excludeFromReply": {
"type": "bool",
"tooltip": true
},
"useImap": {
"type": "bool",
"default": true
Expand Down
33 changes: 33 additions & 0 deletions application/Espo/Tools/App/AppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Espo\Core\Authentication\Util\MethodProvider as AuthenticationMethodProvider;
use Espo\Core\Utils\SystemUser;
use Espo\Entities\DashboardTemplate;
use Espo\Entities\Email;
use Espo\Entities\EmailAccount as EmailAccountEntity;
use Espo\Entities\EmailAddress;
use Espo\Entities\InboundEmail as InboundEmailEntity;
Expand Down Expand Up @@ -190,6 +191,7 @@ private function getUserDataForFrontend(): stdClass

$data->emailAddressList = $emailAddressData['emailAddressList'];
$data->userEmailAddressList = $emailAddressData['userEmailAddressList'];
$data->excludeFromReplyEmailAddressList = $emailAddressData['excludeFromReplyEmailAddressList'];

unset($data->authTokenId);
unset($data->password);
Expand Down Expand Up @@ -246,6 +248,7 @@ private function getAclDataForFrontend(): stdClass
* @return array{
* emailAddressList: string[],
* userEmailAddressList: string[],
* excludeFromReplyEmailAddressList: string[],
* }
*/
private function getEmailAddressData(): array
Expand Down Expand Up @@ -300,6 +303,7 @@ private function getEmailAddressData(): array
return [
'emailAddressList' => $emailAddressList,
'userEmailAddressList' => $userEmailAddressList,
'excludeFromReplyEmailAddressList' => $this->getExcludeFromReplyAddressList(),
];
}

Expand Down Expand Up @@ -455,4 +459,33 @@ private function filterPreferencesData(stdClass $data): void
unset($data->$field);
}
}

/**
* @return string[]
*/
private function getExcludeFromReplyAddressList(): array
{
if (!$this->acl->checkScope(Email::ENTITY_TYPE, Acl\Table::ACTION_CREATE)) {
return [];
}

/** @var iterable<InboundEmailEntity> $accounts */
$accounts = $this->entityManager
->getRDBRepositoryByClass(InboundEmailEntity::class)
->select('emailAddress')
->where(['excludeFromReply' => true])
->find();

$list = [];

foreach ($accounts as $account) {
if (!$account->getEmailAddress()) {
continue;
}

$list[] = $account->getEmailAddress();
}

return $list;
}
}
20 changes: 11 additions & 9 deletions client/modules/crm/src/views/record/panels/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class HistoryPanelView extends ActivitiesPanelView {
}

getArchiveEmailAttributes(scope, data, callback) {
let attributes = {
const attributes = {
dateSent: this.getDateTime().getNow(15),
status: 'Archived',
from: this.model.get('emailAddress'),
Expand Down Expand Up @@ -130,7 +130,7 @@ class HistoryPanelView extends ActivitiesPanelView {

// noinspection JSUnusedGlobalSymbols
actionArchiveEmail(data) {
let scope = 'Email';
const scope = 'Email';

let relate = null;

Expand All @@ -143,7 +143,7 @@ class HistoryPanelView extends ActivitiesPanelView {

Espo.Ui.notify(' ... ');

let viewName = this.getMetadata().get('clientDefs.' + scope + '.modalViews.edit') ||
const viewName = this.getMetadata().get(`clientDefs.${scope}.modalViews.edit`) ||
'views/modals/edit';

this.getArchiveEmailAttributes(scope, data, attributes => {
Expand All @@ -165,13 +165,13 @@ class HistoryPanelView extends ActivitiesPanelView {

// noinspection JSUnusedGlobalSymbols
actionReply(data) {
let id = data.id;
const id = data.id;

if (!id) {
return;
}

let emailHelper = new EmailHelper(
const emailHelper = new EmailHelper(
this.getLanguage(),
this.getUser(),
this.getDateTime(),
Expand All @@ -186,11 +186,13 @@ class HistoryPanelView extends ActivitiesPanelView {

model.fetch()
.then(() => {
let attributes = emailHelper
.getReplyAttributes(model, data,
this.getPreferences().get('emailReplyToAllByDefault'));
const attributes = emailHelper.getReplyAttributes(
model,
data,
this.getPreferences().get('emailReplyToAllByDefault')
);

let viewName = this.getMetadata().get('clientDefs.Email.modalViews.compose') ||
const viewName = this.getMetadata().get('clientDefs.Email.modalViews.compose') ||
'views/modals/compose-email';

return this.createView('quickCreate', viewName, {
Expand Down
7 changes: 7 additions & 0 deletions client/src/email-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,20 @@ class EmailHelper {
if (cc) {
attributes.cc = model.get('cc') || '';

/** @type {string[]} */
const excludeFromReplyEmailAddressList = this.getUser().get('excludeFromReplyEmailAddressList') || [];

(model.get('to') || '').split(';').forEach(item => {
item = item.trim();

if (item === this.getUser().get('emailAddress')) {
return;
}

if (excludeFromReplyEmailAddressList.includes(item)) {
return;
}

if (isReplyOnSent) {
if (attributes.to) {
attributes.to += ';';
Expand Down
4 changes: 3 additions & 1 deletion client/src/views/email/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ class EmailDetailView extends DetailView {
this.getLanguage(),
this.getUser(),
this.getDateTime(),
this.getAcl()
this.getAcl(),
);

this.getHelper().getAppParam()

const attributes = emailHelper.getReplyAttributes(this.model, data, cc);

Espo.Ui.notify(' ... ');
Expand Down

0 comments on commit e99fca0

Please sign in to comment.