From 328143f8a20933744be51a2693c99f35234ce5b3 Mon Sep 17 00:00:00 2001
From: Christopher Smith <chris@jalakai.co.uk>
Date: Fri, 2 Aug 2013 22:53:21 +0200
Subject: [PATCH] enable email notifications & alert messages for imported
 users

---
 lib/plugins/usermanager/admin.php        | 28 ++++++++++++++++++------
 lib/plugins/usermanager/lang/en/lang.php |  3 ++-
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php
index ddf10a115..395b91053 100644
--- a/lib/plugins/usermanager/admin.php
+++ b/lib/plugins/usermanager/admin.php
@@ -606,12 +606,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
     /**
      * send password change notification email
      */
-    function _notifyUser($user, $password) {
+    function _notifyUser($user, $password, $status_alert=true) {
 
         if ($sent = auth_sendPassword($user,$password)) {
-          msg($this->lang['notify_ok'], 1);
+          if ($status_alert) {
+            msg($this->lang['notify_ok'], 1);
+          }
         } else {
-          msg($this->lang['notify_fail'], -1);
+          if ($status_alert) {
+            msg($this->lang['notify_fail'], -1);
+          }
         }
 
         return $sent;
@@ -770,7 +774,10 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
                 array_splice($raw,1,0,auth_pwgen());                          // splice in a generated password
                 $clean = $this->_cleanImportUser($raw, $error);
                 if ($clean && $this->_addImportUser($clean, $error)) {
-#                    $this->_notifyUser($clean[0],$clean[1]);
+                    $sent = $this->_notifyUser($clean[0],$clean[1],false);
+                    if (!$sent){
+                        msg(sprintf($this->lang['import_notify_fail'],$clean[0],$clean[3]),-1);
+                    }
                     $import_success_count++;
                 } else {
                     $import_fail_count++;
@@ -817,9 +824,16 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin {
             return false;
         }
 
-        if (!($this->_auth->canDo('modMail') xor empty($mail))){
-            $error = $this->lang['import_error_badmail'];
-            return false;
+        if ($this->_auth->canDo('modMail')) {
+            if (empty($mail) || !mail_isvalid($mail)) {
+                $error = $this->lang['import_error_badmail'];
+                return false;
+            }
+        } else {
+            if (!empty($mail)) {
+                $error = $this->lang['import_error_badmail'];
+                return false;
+            }
         }
 
         return $cleaned;
diff --git a/lib/plugins/usermanager/lang/en/lang.php b/lib/plugins/usermanager/lang/en/lang.php
index f22d1f805..69119e196 100644
--- a/lib/plugins/usermanager/lang/en/lang.php
+++ b/lib/plugins/usermanager/lang/en/lang.php
@@ -67,9 +67,10 @@ $lang['import_failure_count'] = 'User Import: %d failed. Failures are listed bel
 $lang['import_error_fields']  = "Insufficient fields, found %d, require 4.";
 $lang['import_error_baduserid'] = "User-id missing";
 $lang['import_error_badname'] = 'Bad name';
-$lang['import_error_badmail'] = 'Bad mail';
+$lang['import_error_badmail'] = 'Bad email address';
 $lang['import_error_upload']  = 'Import Failed. The csv file could not be uploaded or is empty.';
 $lang['import_error_readfail'] = 'Import Failed. Unable to read uploaded file.';
 $lang['import_error_create']  = 'Unable to create the user';
+$lang['import_notify_fail']   = 'Notification message could not be sent for imported user, %s with email %s.';
 
 
-- 
GitLab