Awight has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/303601

Change subject: Failmail can unpack multiple "to" addresses
......................................................................

Failmail can unpack multiple "to" addresses

Note that we can't write a test for this at the moment, cos the changed code
is in the PHPMailer glue layer, which the dummy Drupal target won't execute.

Bug: T142420
Change-Id: Ibfe6953f90a94e3860ad5eea0d20d15dce3ce75c
---
M sites/all/modules/large_donation/large_donation.module
M sites/all/modules/wmf_campaigns/wmf_campaigns.module
M sites/all/modules/wmf_common/failmail.php
M sites/all/modules/wmf_communication/Mailer.php
4 files changed, 20 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/01/303601/1

diff --git a/sites/all/modules/large_donation/large_donation.module 
b/sites/all/modules/large_donation/large_donation.module
index 5a7e595..38bb9a6 100644
--- a/sites/all/modules/large_donation/large_donation.module
+++ b/sites/all/modules/large_donation/large_donation.module
@@ -231,7 +231,7 @@
 
     try {
         $email = array(
-            'to' => preg_split( '/\\s*[,\\n]\\s*/', $to, -1, 
PREG_SPLIT_NO_EMPTY ),
+            'to' => $to,
             'from_address' => '[email protected]',
             'from_name' => 'Large Donation Bot',
             'subject' => "WMF - large donation: 
\${$contribution->total_amount}",
diff --git a/sites/all/modules/wmf_campaigns/wmf_campaigns.module 
b/sites/all/modules/wmf_campaigns/wmf_campaigns.module
index 156a901..917a392 100644
--- a/sites/all/modules/wmf_campaigns/wmf_campaigns.module
+++ b/sites/all/modules/wmf_campaigns/wmf_campaigns.module
@@ -306,11 +306,9 @@
             $template = new Templating( __DIR__ . '/templates', 
'notification', 'en', $params, 'html' );
             $letter['html'] = $template->render();
 
-            $addressees = explode( ",", $campaign->getNotificationEmail() );
             $mailer = Mailer::getDefault();
             foreach ( $addressees as $recipient ) {
-                $letter['to_address'] = trim( $recipient );
-                $letter['to_name'] = t( "Dear donor services" );
+                $letter['to'] = $campaign->getNotificationEmail(),
 
                 $mailer->send( $letter );
             }
diff --git a/sites/all/modules/wmf_common/failmail.php 
b/sites/all/modules/wmf_common/failmail.php
index 71ffbe8..aaed052 100644
--- a/sites/all/modules/wmf_common/failmail.php
+++ b/sites/all/modules/wmf_common/failmail.php
@@ -27,8 +27,7 @@
       'html' => wmf_common_get_body($message, $error, $source, $isRemoved),
       'reply_to' => '',
       'subject' => _wmf_common_get_subject($error, $module, $isRemoved),
-      'to_address' => variable_get('wmf_common_failmail', 
'[email protected]'),
-      'to_name' => 'FR-Tech',
+      'to' => variable_get('wmf_common_failmail', '[email protected]'),
     ));
 }
 
diff --git a/sites/all/modules/wmf_communication/Mailer.php 
b/sites/all/modules/wmf_communication/Mailer.php
index 647bfdd..1bc38ad 100644
--- a/sites/all/modules/wmf_communication/Mailer.php
+++ b/sites/all/modules/wmf_communication/Mailer.php
@@ -129,6 +129,15 @@
             throw new WmfException( 'RENDER', "Could not render plaintext" );
         }
     }
+
+       /**
+        * Split a string list of addresses, separated by commas or whitespace, 
into an array.
+        * @param string $to
+        * @return array
+        */
+       protected function splitAddresses( $to ) {
+               return preg_split( '/\\s*[,\\n]\\s*/', $to, -1, 
PREG_SPLIT_NO_EMPTY );
+       }
 }
 
 /**
@@ -136,12 +145,6 @@
  */
 class MailerPHPMailer extends MailerBase implements IMailer {
     function send( $email, $headers = array() ) {
-        watchdog( 'wmf_communication',
-            "Sending an email to :to_address, using PHPMailer",
-            array( ':to_address' => $email['to_address'] ),
-            WATCHDOG_DEBUG
-        );
-
         $mailer = new PHPMailer( true );
 
         $mailer->set( 'CharSet', 'utf-8' );
@@ -151,7 +154,15 @@
         $mailer->SetFrom( $email['from_address'], $email['from_name'] );
         $mailer->set( 'Sender', $email['reply_to'] );
 
+        // Note that this is incredibly funky.  This is the only mailer to 
support
+        // a "to" parameter, and it behaves differently than 
to_address/to_name.
+        // You can pass a list of bare email addresses through "to" and 
they'll all
+        // become to addresses, but without names, so this should only be used 
by
+        // maintenancey things directed at staff.
         if ( isset( $email['to'] ) ) {
+            if ( is_string( $email['to'] ) ) {
+                $email['to'] = $this->splitAddresses( $email['to'] );
+            }
             foreach ( $email['to'] as $to ) {
                 $mailer->AddAddress( $to );
             }

-- 
To view, visit https://gerrit.wikimedia.org/r/303601
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibfe6953f90a94e3860ad5eea0d20d15dce3ce75c
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to