From eb523ccdb84435f01f8febc550c940a550b032db Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 20 Jul 2017 13:21:42 +1200 Subject: [PATCH] CRM-20905: Make (max emails kill switch) a configuration instead of hardcoded value Change-Id: Id03a77924121aec8fd83168d009202ca2aab06f7 --- CRM/Contact/Form/Task/Email.php | 6 +----- CRM/Contact/Form/Task/EmailCommon.php | 21 ++++++++++++++++----- CRM/Contact/Task.php | 2 +- settings/Mailing.setting.php | 18 ++++++++++++++++++ 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/CRM/Contact/Form/Task/Email.php b/CRM/Contact/Form/Task/Email.php index 42259eec6b..efc5ac5616 100644 --- a/CRM/Contact/Form/Task/Email.php +++ b/CRM/Contact/Form/Task/Email.php @@ -131,11 +131,7 @@ class CRM_Contact_Form_Task_Email extends CRM_Contact_Form_Task { if (!$cid && $this->_context != 'standalone') { parent::preProcess(); } - - //early prevent, CRM-6209 - if (count($this->_contactIds) > CRM_Contact_Form_Task_EmailCommon::MAX_EMAILS_KILL_SWITCH) { - CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => CRM_Contact_Form_Task_EmailCommon::MAX_EMAILS_KILL_SWITCH))); - } + CRM_Contact_Form_Task_EmailCommon::bounceIfSimpleMailLimitExceeded(count($this->_contactIds)); $this->assign('single', $this->_single); if (CRM_Core_Permission::check('administer CiviCRM')) { diff --git a/CRM/Contact/Form/Task/EmailCommon.php b/CRM/Contact/Form/Task/EmailCommon.php index 8757cac0d2..88be4a082b 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -409,11 +409,7 @@ class CRM_Contact_Form_Task_EmailCommon { * @param CRM_Core_Form $form */ public static function postProcess(&$form) { - if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) { - CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', - array(1 => self::MAX_EMAILS_KILL_SWITCH) - )); - } + self::bounceIfSimpleMailLimitExceeded(count($form->_contactIds)); // check and ensure that $formValues = $form->controller->exportValues($form->getName()); @@ -626,4 +622,19 @@ class CRM_Contact_Form_Task_EmailCommon { } } + /** + * Bounce if there are more emails than permitted. + * + * @param int $count + * The number of emails the user is attempting to send + */ + public static function bounceIfSimpleMailLimitExceeded($count) { + $limit = Civi::settings()->get('simple_mail_limit'); + if ($count > $limit) { + CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). Many countries have legal requirements when sending bulk emails and the CiviMail framework has opt out functionality and domain tokens to help meet these.', + array(1 => $limit) + )); + } + } + } diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index 503c511e99..d5afbac86d 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -109,7 +109,7 @@ class CRM_Contact_Task { 'result' => FALSE, ), self::EMAIL_CONTACTS => array( - 'title' => ts('Email - send now (to 50 or less)'), + 'title' => ts('Email - send now (to %1 or less)', array(1 => Civi::settings()->get('simple_mail_limit'))), 'class' => 'CRM_Contact_Form_Task_Email', 'result' => TRUE, 'url' => 'civicrm/task/send-email', diff --git a/settings/Mailing.setting.php b/settings/Mailing.setting.php index 056122f764..1969df133a 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -315,4 +315,22 @@ return array( 'description' => NULL, 'help_text' => NULL, ), + 'simple_mail_limit' => array( + 'group_name' => 'Mailing Preferences', + 'group' => 'mailing', + 'name' => 'simple_mail_limit', + 'type' => 'Integer', + 'quick_form_type' => 'Element', + 'html_type' => 'text', + 'html_attributes' => array( + 'size' => 4, + 'maxlength' => 8, + ), + 'default' => 50, + 'title' => 'Simple mail limit', + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => 'The number of emails sendable via simple mail. Make sure you understand the implications for your spam reputation and legal requirements for bulk emails before editing. As there is some risk both to your spam reputation and the products if this is misused it is a hidden setting', + 'help_text' => 'CiviCRM forces users sending more than this number of mails to use CiviMails. CiviMails have additional precautions: not sending to contacts who do not want bulk mail, adding domain name and opt out links. You should familiarise yourself with the law relevant to you on bulk mailings if changing this setting. For the US https://en.wikipedia.org/wiki/CAN-SPAM_Act_of_2003 is a good place to start.', + ), ); -- 2.25.1