From 54389bbfe1915b6d4a463d5b94583eb8cc57d5d2 Mon Sep 17 00:00:00 2001
From: Dan Chadwick <dan899@gmail.com>
Date: Thu, 16 Apr 2015 15:30:52 -0400
Subject: [PATCH] Issue #1160400 by DanChadwick: Added multiple email
 recipients, one message configuration option.

---
 includes/webform.admin.inc       |   11 +++++++++++
 includes/webform.submissions.inc |   16 +++++++++++++---
 webform.install                  |    7 +++++++
 webform.module                   |    3 +++
 4 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/includes/webform.admin.inc b/includes/webform.admin.inc
index c20f737..0f80b2f 100644
--- a/includes/webform.admin.inc
+++ b/includes/webform.admin.inc
@@ -169,6 +169,17 @@ function webform_admin_settings() {
     '#description' => t('Most servers support the "long" format which will allow for more friendly From addresses in e-mails sent. However many Windows-based servers are unable to send in the long format. Change this option if experiencing problems sending e-mails with Webform.'),
   );
 
+  $form['advanced']['webform_email_address_individual'] = array(
+    '#type' => 'radios',
+    '#title' => t('E-mailing multiple recipients'),
+    '#options' => array(
+      '0' => t('Send a single e-mail to all recipients'),
+      '1' => t('Send individual e-mails to each recipient'),
+    ),
+    '#default_value' => webform_variable_get('webform_email_address_individual'),
+    '#description' => t('Individual e-mails increases privacy by not revealing the addresses of other recipients. A single e-mail to all recipients lets them use "Reply All" to communicate.'),
+  );
+
   $form['advanced']['webform_export_format'] = array(
     '#type' => 'radios',
     '#title' => t('Default export format'),
diff --git a/includes/webform.submissions.inc b/includes/webform.submissions.inc
index 2a9bf3e..3ca797d 100644
--- a/includes/webform.submissions.inc
+++ b/includes/webform.submissions.inc
@@ -302,14 +302,24 @@ function webform_submission_send_mail($node, $submission, $emails = NULL) {
     // Generate the list of addresses that this e-mail will be sent to.
     $addresses_final = array_filter($addresses, 'webform_valid_email_address');
 
-    // Mail the webform results.
+    // Verify that this submission is not attempting to send any spam hacks.
     foreach ($addresses_final as $address) {
-      // Verify that this submission is not attempting to send any spam hacks.
       if (_webform_submission_spam_check($address, $email['subject'], $email['from'], $email['headers'])) {
         watchdog('webform', 'Possible spam attempt from @remote_addr' . "<br />\n" . nl2br(htmlentities($email['message'])), array('@remote_add' => ip_address()));
         drupal_set_message(t('Illegal information. Data not submitted.'), 'error');
         return FALSE;
       }
+    }
+
+    // Consolidate addressees into one message if permitted by configuration.
+    $send_increment = 1;
+    if (!webform_variable_get('webform_email_address_individual')) {
+      $send_increment = count($addresses_final);
+      $addresses_final = array(implode(', ', $addresses_final));
+    }
+
+    // Mail the webform results.
+    foreach ($addresses_final as $address) {
 
       $language = $user->uid ? user_preferred_language($user) : language_default();
       $mail_params = array(
@@ -354,7 +364,7 @@ function webform_submission_send_mail($node, $submission, $emails = NULL) {
       // Mail the submission.
       $message = drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
       if ($message['result']) {
-        $send_count++;
+        $send_count += $send_increment;
       }
     }
   }
diff --git a/webform.install b/webform.install
index 1acabb0..24e5a6d 100644
--- a/webform.install
+++ b/webform.install
@@ -2138,3 +2138,10 @@ function webform_update_7425() {
 
   return t('Webform e-mails were sucessfully updated to add the option to exclude empty components.');
 }
+
+/**
+ * Add configuration to continue sending individual e-mails to multiple recipients.
+ */
+function webform_update_7426() {
+  variable_set('webform_email_address_individual', 1);
+}
diff --git a/webform.module b/webform.module
index 12a7e47..f053e31 100644
--- a/webform.module
+++ b/webform.module
@@ -3967,6 +3967,9 @@ function webform_variable_get($variable) {
     case 'webform_email_address_format':
       $result = variable_get('webform_email_address_format', 'long');
       break;
+    case 'webform_email_address_individual':
+      $result = variable_get('webform_email_address_individual', 0);
+      break;
     case 'webform_default_from_name':
       $result = variable_get('webform_default_from_name', variable_get('site_name', ''));
       break;
-- 
1.7.8.msysgit.0

