Skip to content

Commit

Permalink
CRM-20905: Make (max emails kill switch) a configuration instead of h…
Browse files Browse the repository at this point in the history
…ardcoded value
  • Loading branch information
eileenmcnaughton committed Jul 20, 2017
1 parent d171178 commit 25687bf
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CRM/Admin/Form/Setting/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

/**
Expand Down
6 changes: 1 addition & 5 deletions CRM/Contact/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
21 changes: 16 additions & 5 deletions CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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)
));
}
}

}
2 changes: 1 addition & 1 deletion CRM/Contact/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions settings/Mailing.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
),
);

0 comments on commit 25687bf

Please sign in to comment.