From 343df3f97c8b15e7eb2c40e7e6a08feabdd2ec40 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 19 May 2021 16:08:38 +0300 Subject: [PATCH] auto reply changes --- .../Espo/Resources/defaults/config.php | 3 ++- .../Espo/Resources/defaults/systemConfig.php | 1 + application/Espo/Services/InboundEmail.php | 27 ++++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/application/Espo/Resources/defaults/config.php b/application/Espo/Resources/defaults/config.php index ab4c2c4556..a5f3b76c7d 100644 --- a/application/Espo/Resources/defaults/config.php +++ b/application/Espo/Resources/defaults/config.php @@ -134,7 +134,8 @@ return [ 'activitiesEntityList' => ['Meeting', 'Call'], 'historyEntityList' => ['Meeting', 'Call', 'Email'], 'busyRangesEntityList' => ['Meeting', 'Call'], - 'emailAutoReplySuppressPeriod' => '3 hours', + 'emailAutoReplySuppressPeriod' => '2 hours', + 'emailAutoReplyLimit' => 5, 'cleanupJobPeriod' => '1 month', 'cleanupActionHistoryPeriod' => '15 days', 'cleanupAuthTokenPeriod' => '1 month', diff --git a/application/Espo/Resources/defaults/systemConfig.php b/application/Espo/Resources/defaults/systemConfig.php index ecd8364632..4df73ce78a 100644 --- a/application/Espo/Resources/defaults/systemConfig.php +++ b/application/Espo/Resources/defaults/systemConfig.php @@ -182,6 +182,7 @@ return [ 'ldapPortalUserRolesNames', 'cleanupJobPeriod', 'emailAutoReplySuppressPeriod', + 'emailAutoReplyLimit', 'cleanupActionHistoryPeriod', 'adminNotifications', 'adminNotificationsNewVersion', diff --git a/application/Espo/Services/InboundEmail.php b/application/Espo/Services/InboundEmail.php index c2bc62698b..8d8e0e36bc 100644 --- a/application/Espo/Services/InboundEmail.php +++ b/application/Espo/Services/InboundEmail.php @@ -81,9 +81,11 @@ class InboundEmail extends RecordService implements protected $parserClassName = MailMimeParser::class; - protected $emailAutoReplySuppressPeriod = '3 hours'; + private const DEFAULT_AUTOREPLY_SUPPRESS_PERIOD = '2 hours'; - const PORTION_LIMIT = 20; + private const DEFAULT_AUTOREPLY_LIMIT = 5; + + protected const PORTION_LIMIT = 20; protected function getCrypt() { @@ -814,12 +816,16 @@ class InboundEmail extends RecordService implements protected function autoReply($inboundEmail, $email, $case = null, $user = null) { if (!$email->get('from')) { - return false; + return null; } + $limit = $this->config->get('emailAutoReplyLimit', self::DEFAULT_AUTOREPLY_LIMIT); + $d = new DateTime(); - $d->modify('-' . $this->config->get('emailAutoReplySuppressPeriod', $this->emailAutoReplySuppressPeriod)); + $period = $this->config->get('emailAutoReplySuppressPeriod', self::DEFAULT_AUTOREPLY_SUPPRESS_PERIOD); + + $d->modify('-' . $period); $threshold = $d->format('Y-m-d H:i:s'); @@ -827,18 +833,19 @@ class InboundEmail extends RecordService implements ->getRepository('EmailAddress') ->getByAddress($email->get('from')); - $sent = $this->getEntityManager() - ->getRepository('Email') + $sentCount = $this->getEntityManager() + ->getRDBRepository('Email') ->where([ - 'toEmailAddresses.id' => $emailAddress->id, + 'toEmailAddresses.id' => $emailAddress->getId(), 'dateSent>' => $threshold, 'status' => 'Sent', + 'createdById' => 'system', ]) ->join('toEmailAddresses') - ->findOne(); + ->count(); - if ($sent) { - return false; + if ($sentCount >= $limit) { + return null; } $message = new Message();