jenkins-bot has submitted this change and it was merged.
Change subject: Notify administrators on API failing to parse bounce emails
......................................................................
Notify administrators on API failing to parse bounce emails
A bounce email, can go un-processed, even after it passed valid
VERP checks. The wiki admin needs to be notified on this event,
so that he can improve his regex functions. Added a test to check
existence of $user in BounceHandlerHooks
Change-Id: I1c3577a9ed87f6a2656d20e319d9f66dd38d3d70
---
M BounceHandler.php
M BounceHandlerHooks.php
M ProcessBounceEmails.php
A ProcessUnRecognizedBounces.php
M i18n/en.json
M i18n/qqq.json
6 files changed, 51 insertions(+), 4 deletions(-)
Approvals:
Hoo man: Looks good to me, approved
jenkins-bot: Verified
diff --git a/BounceHandler.php b/BounceHandler.php
index b118e63..0267ab6 100644
--- a/BounceHandler.php
+++ b/BounceHandler.php
@@ -29,6 +29,7 @@
$wgAutoloadClasses['BounceHandlerJob'] = $dir. '/BounceHandlerJob.php';
$wgAutoloadClasses['ProcessBounceEmails'] = $dir. '/ProcessBounceEmails.php';
$wgAutoloadClasses['BounceHandlerActions'] = $dir. '/BounceHandlerActions.php';
+$wgAutoloadClasses['ProcessUnRecognizedBounces'] = $dir.
'/ProcessUnRecognizedBounces.php';
$wgJobClasses['BounceHandlerJob'] = 'BounceHandlerJob';
@@ -59,5 +60,8 @@
$wgIMAPpass = 'pass';
$wgIMAPserver = '{localhost:143/imap/novalidate-cert}INBOX';
-/*Allow only internal IP range to do the POST request */
+/* Allow only internal IP range to do the POST request */
$wgBounceHandlerInternalIPs = array( '127.0.0.1', '::1' );
+
+/* Admin email address which should be notified in the case of an unprocessed
valid bounce */
+$wgUnrecognizedBounceNotify = array( '[email protected]' );
diff --git a/BounceHandlerHooks.php b/BounceHandlerHooks.php
index 5e2247f..8d8a715 100644
--- a/BounceHandlerHooks.php
+++ b/BounceHandlerHooks.php
@@ -11,6 +11,9 @@
*/
public static function onVERPAddressGenerate( $recip, &$returnPath ) {
$user = User::newFromName( $recip[0]->name );
+ if ( !$user ) {
+ return true;
+ }
$email = $recip[0]->address;
if ( $user->getEmail() === $email && $user->isEmailConfirmed()
) {
$uid = $user->getId();
diff --git a/ProcessBounceEmails.php b/ProcessBounceEmails.php
index bec568d..d0386e4 100644
--- a/ProcessBounceEmails.php
+++ b/ProcessBounceEmails.php
@@ -6,7 +6,7 @@
* @return bool
*/
public function processEmail( $email ) {
- global $wgBounceRecordPeriod, $wgBounceRecordLimit;
+ global $wgBounceRecordPeriod, $wgBounceRecordLimit,
$wgUnrecognizedBounceNotify, $wgPasswordSender;
$emailHeaders = array();
$failedUser = array();
if ( !stream_resolve_include_path(
'vendor/pear/mail_mime-decode/Mail/mimeDecode.php' ) ) {
@@ -52,6 +52,8 @@
$takeBounceActions->handleFailingRecipient(
$originalEmail, $bounceTimestamp );
} else {
wfDebugLog( 'BounceHandler', "Received temporary bounce
from $to" );
+ $handleUnIdentifiedBounce = new
ProcessUnRecognizedBounces( $wgUnrecognizedBounceNotify, $wgPasswordSender );
+ $handleUnIdentifiedBounce->processUnRecognizedBounces(
$email );
}
}
diff --git a/ProcessUnRecognizedBounces.php b/ProcessUnRecognizedBounces.php
new file mode 100644
index 0000000..55ed5c5
--- /dev/null
+++ b/ProcessUnRecognizedBounces.php
@@ -0,0 +1,36 @@
+<?php
+class ProcessUnRecognizedBounces {
+ /**
+ * @var string
+ */
+ protected $passwordSender;
+
+ /**
+ * @var array
+ */
+ protected $unrecognizedBounceNotify;
+
+ public function __construct( $unrecognizedBounceNotify, $passwordSender
) {
+ $this->unrecognizedBounceNotify = $unrecognizedBounceNotify;
+ $this->passwordSender = $passwordSender;
+ }
+
+ /**
+ * Notify the system administrator about a temporary bounce which
failed to get parsed
+ *
+ * @param string $email The received email bounce
+ */
+ public function processUnRecognizedBounces( $email ) {
+ $subject = 'bouncehandler-notify_subject';
+ $sender = new MailAddress( $this->passwordSender, wfMessage(
'emailsender' )->inContentLanguage()->text() );
+ $to = array();
+ if ( isset( $this->urecognizedBounceNotify ) ) {
+ foreach ( $this->unrecognizedBounceNotify as
$notifyEmails ) {
+ $to[] = new MailAddress( $notifyEmails );
+ }
+ UserMailer::send( $to, $sender, $subject, $email,
$sender );
+ } else {
+ wfDebugLog( 'BounceHandler', "Cannot send notification
to administrators" );
+ }
+ }
+}
\ No newline at end of file
diff --git a/i18n/en.json b/i18n/en.json
index 0f6275b..ad7c7cd 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -4,5 +4,6 @@
"Tony Thomas"
]
},
- "bouncehandler-desc": "Helps in handling email bounces for MediaWiki"
+ "bouncehandler-desc": "Helps in handling email bounces for MediaWiki",
+ "bouncehandler-notify_subject": "Returning temporary bounce"
}
\ No newline at end of file
diff --git a/i18n/qqq.json b/i18n/qqq.json
index d14b539..8f3aafe 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -4,5 +4,6 @@
"Tony Thomas"
]
},
- "bouncehandler-desc": "{{desc|name=Bounce
Handler|url=https://www.mediawiki.org/wiki/Extension:BounceHandler}}"
+ "bouncehandler-desc": "{{desc|name=Bounce
Handler|url=https://www.mediawiki.org/wiki/Extension:BounceHandler}}",
+ "bouncehandler-notify_subject": "Subject of notification email sent to
wiki administrators on a failed to parse bounce"
}
--
To view, visit https://gerrit.wikimedia.org/r/148456
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1c3577a9ed87f6a2656d20e319d9f66dd38d3d70
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/BounceHandler
Gerrit-Branch: master
Gerrit-Owner: 01tonythomas <[email protected]>
Gerrit-Reviewer: 01tonythomas <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jgreen <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits