Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.745.2.13
diff -u -r1.745.2.13 user.module
--- modules/user/user.module	26 Jul 2007 19:16:50 -0000	1.745.2.13
+++ modules/user/user.module	4 Sep 2007 05:26:36 -0000
@@ -441,12 +441,21 @@
         $find = array();
         // Replace wildcards with MySQL/PostgreSQL wildcards.
         $keys = preg_replace('!\*+!', '%', $keys);
-        $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
-        while ($account = db_fetch_object($result)) {
-          $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, NULL, NULL, TRUE));
+        if (user_access('administer users')) {
+          // Administrators can also search in the otherwise private email field.
+          $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
+          while ($account = db_fetch_object($result)) {
+            $find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));  
+          }
+        }
+        else {
+          $result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); 
+          while ($account = db_fetch_object($result)) {
+            $find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));  
+          }
         }
-        return $find;
       }
+      return $find;
   }
 }
 
@@ -771,7 +780,7 @@
 
     if (module_exists('search')) {
       $items[] = array('path' => 'admin/user/search', 'title' => t('Search users'),
-        'description' => t('Search users by name.'),
+        'description' => t('Search users by name or e-mail address.'),
         'callback' => 'user_admin', 'callback arguments' => array('search'), 'access' => $admin_access,
         'type' => MENU_NORMAL_ITEM);
     }
@@ -2380,7 +2389,7 @@
       <li>Authenticated user: this role is automatically granted to all logged in users.</li>
       </ul>', array('@permissions' => url('admin/user/access')));
     case 'admin/user/search':
-      return '<p>'. t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda".') .'</p>';
+      return '<p>'. t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') .'</p>';
     case 'user/help#user':
       $site = variable_get('site_name', 'Drupal');
 
