Gergő Tisza has uploaded a new change for review.
https://gerrit.wikimedia.org/r/242791
Change subject: Add UserMailerTransformContent and UserMailerSplitTo hooks
......................................................................
Add UserMailerTransformContent and UserMailerSplitTo hooks
UserMailerTransformContent allows extensions to change the body of
an email sent via UserMailer::send(). This is applied before
low-level transformations such as multipart or content encoding.
UserMailerSplitTo allows extensions to request that a certain
user should always be emailed separately (so when UserMailer::send()
is called with an array of target addresses, that user will be split
out into a separate call). This is intended for content
transformations which need to be different per user, such as
encryption.
Bug: T12453
Change-Id: I4c3a018110173c3b5d52a753fdcbec397b590ced
---
M RELEASE-NOTES-1.27
M docs/hooks.txt
M includes/mail/UserMailer.php
3 files changed, 47 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/91/242791/1
diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27
index bf50a47..bc53e49 100644
--- a/RELEASE-NOTES-1.27
+++ b/RELEASE-NOTES-1.27
@@ -12,6 +12,12 @@
* Removed $wgUseLinkNamespaceDBFields
=== New features in 1.27 ===
+* Added a new hook, 'UserMailerTransformContent', to transform the contents
+ of an email. This is similar to the EmailUser hook but applies to all mail
+ sent via UserMailer.
+* Added a new hook, 'UserMailerSplitTo', to control which users have to be
+ emailed separately (ie. there is a single address in the To: field) so
+ user-specific changes to the email can be applied safely.
==== External libraries ====
diff --git a/docs/hooks.txt b/docs/hooks.txt
index 2d268b8..2840457 100644
--- a/docs/hooks.txt
+++ b/docs/hooks.txt
@@ -3292,6 +3292,17 @@
$to: Array of MailAddress objects for the recipients
&$returnPath: The return address string
+'UserMailerSplitTo': Called in UserMailer::send() to give extensions a chance
+to split up an email with multiple the To: field into separate emails.
+$to: array of MailAddress objects; unset the ones which should be mailed
separately
+
+'UserMailerTransformContent': Called in UserMailer::send() to change email
contents.
+Extensions can block sending the email by returning false and setting $error.
+$to: array of MailAdresses of the targets
+$from: MailAddress of the sender
+&$body: email body, either a string (for plaintext emails) or an array with
'text' and 'html' keys
+&$error: should be set to an error message string
+
'UserRemoveGroup': Called when removing a group; return false to override stock
group removal.
$user: the user object that is to have a group removed
diff --git a/includes/mail/UserMailer.php b/includes/mail/UserMailer.php
index 3c28c5f..fdd32b2 100644
--- a/includes/mail/UserMailer.php
+++ b/includes/mail/UserMailer.php
@@ -178,6 +178,36 @@
return Status::newFatal( 'user-mail-no-addy' );
}
+ // give a chance to UserMailerTransformContents subscribers who
need to deal with each
+ // target differently to split up the address list
+ if ( count( $to ) > 1 ) {
+ $oldTo = $to;
+ Hooks::run( 'UserMailerSplitTo', array( &$to ) );
+ if ( $oldTo != $to ) {
+ $splitTo = array_diff( $oldTo, $to );
+ $to = array_diff( $oldTo, $splitTo ); // ignore
new addresses added in the hook
+ // first send to non-split address list, then
to split addresses one by one
+ $status = Status::newGood();
+ if ( $to ) {
+ $status->merge( UserMailer::send( $to,
$from, $subject, $body, $options ) );
+ }
+ foreach ( $splitTo as $newTo ) {
+ $status->merge( UserMailer::send(
$newTo, $from, $subject, $body, $options ) );
+ }
+ return $status;
+ }
+ }
+
+ // Allow transformation of content, such as encrypting/signing
+ $error = false;
+ if ( !Hooks::run( 'UserMailerTransformContent', array( $to,
$from, &$body, &$error ) ) ) {
+ if ( $error ) {
+ return Status::newFatal( 'php-mail-error',
$error );
+ } else {
+ return Status::newFatal(
'php-mail-error-unknown' );
+ }
+ }
+
/**
* Forge email headers
* -------------------
--
To view, visit https://gerrit.wikimedia.org/r/242791
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I4c3a018110173c3b5d52a753fdcbec397b590ced
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits