From 25687bfd272e57a02765a6bbd64e4131a6835152 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 --- CRM/Admin/Form/Setting/Mail.php | 3 ++- CRM/Contact/Form/Task/Email.php | 6 +----- CRM/Contact/Form/Task/EmailCommon.php | 21 ++++++++++++++++----- CRM/Contact/Task.php | 2 +- settings/Mailing.setting.php | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/CRM/Admin/Form/Setting/Mail.php b/CRM/Admin/Form/Setting/Mail.php index 960ce2abae1..65584658307 100644 --- a/CRM/Admin/Form/Setting/Mail.php +++ b/CRM/Admin/Form/Setting/Mail.php @@ -37,12 +37,13 @@ class CRM_Admin_Form_Setting_Mail extends CRM_Admin_Form_Setting { protected $_settings = array( - 'replyTo' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailerBatchLimit' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailerJobSize' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailerJobsMax' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailThrottleTime' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'verpSeparator' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, + 'replyTo' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, + 'simple_mail_limit' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, ); /** diff --git a/CRM/Contact/Form/Task/Email.php b/CRM/Contact/Form/Task/Email.php index 42259eec6bb..efc5ac5616b 100644 --- a/CRM/Contact/Form/Task/Email.php +++ b/CRM/Contact/Form/Task/Email.php @@ -131,11 +131,7 @@ public function preProcess() { 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 8757cac0d2b..88be4a082bd 100644 --- a/CRM/Contact/Form/Task/EmailCommon.php +++ b/CRM/Contact/Form/Task/EmailCommon.php @@ -409,11 +409,7 @@ public static function formRule($fields, $dontCare, $self) { * @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 @@ protected static function saveMessageTemplate($formValues) { } } + /** + * 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 503c511e994..d5afbac86de 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -109,7 +109,7 @@ public static function initTasks() { '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 056122f764b..ae8a0669bc6 100644 --- a/settings/Mailing.setting.php +++ b/settings/Mailing.setting.php @@ -315,4 +315,22 @@ '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', + '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.', + ), );