Index: CHANGELOG
===================================================================
--- CHANGELOG	(revision 6205a30c81eab281d792edf863b6ba7b0e8804b8)
+++ CHANGELOG	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -2,4 +2,5 @@
 ===========================
 
+- Fix duplicate names handling in addressbook searches (#1488375)
 - Fix displaying HTML messages from Disqus (#1488372)
 - Exclude E_STRICT from error_reporting for PHP 5.4
Index: program/steps/addressbook/delete.inc
===================================================================
--- program/steps/addressbook/delete.inc	(revision 7fe3811c65a7c63154f03610e289a6d196f3ae2e)
+++ program/steps/addressbook/delete.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -73,4 +73,5 @@
 // update saved search after data changed
 if (($search_request = $_REQUEST['_search']) && isset($_SESSION['search'][$search_request])) {
+    $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
     $search  = (array)$_SESSION['search'][$search_request];
     $records = array();
@@ -95,5 +96,5 @@
         while ($row = $result->next()) {
             $row['sourceid'] = $s;
-            $key = $row['name'] . ':' . $row['sourceid'];
+            $key = rcmail_contact_key($row, $sort_col);
             $records[$key] = $row;
         }
Index: program/steps/addressbook/export.inc
===================================================================
--- program/steps/addressbook/export.inc	(revision 7fe3811c65a7c63154f03610e289a6d196f3ae2e)
+++ program/steps/addressbook/export.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -28,4 +28,5 @@
 if (!empty($_REQUEST['_search']) && isset($_SESSION['search'][$_REQUEST['_search']]))
 {
+    $sort_col = $RCMAIL->config->get('addressbook_sort_col', 'name');
     $search  = (array)$_SESSION['search'][$_REQUEST['_search']];
     $records = array();
@@ -45,5 +46,5 @@
         while ($row = $result->next()) {
             $row['sourceid'] = $s;
-            $key = $row['name'] . ':' . $row['sourceid'];
+            $key = rcmail_contact_key($row, $sort_col);
             $records[$key] = $row;
         }
Index: program/steps/addressbook/func.inc
===================================================================
--- program/steps/addressbook/func.inc	(revision f9a967763e2a4cc595b44f40ac1ca666b2a02af6)
+++ program/steps/addressbook/func.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -730,4 +730,22 @@
 
 
+function rcmail_contact_key($row, $sort_col)
+{
+    $key = $row[$sort_col] . ':' . $row['sourceid'];
+
+    // add email to a key to not skip contacts with the same name (#1488375)
+    if (!empty($row['email'])) {
+         if (is_array($row['email'])) {
+             $key .= ':' . implode(':', $row['email']);
+         }
+         else {
+             $key .= ':' . $row['email'];
+         }
+     }
+
+     return $key;
+}
+
+
 /**
  * Returns contact ID(s) and source(s) from GET/POST data
Index: program/steps/addressbook/list.inc
===================================================================
--- program/steps/addressbook/list.inc	(revision 43875379d5fcfc4e4d29e2edcbbed614a2050f7d)
+++ program/steps/addressbook/list.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -51,5 +51,5 @@
         while ($row = $result->next()) {
             $row['sourceid'] = $s;
-            $key = $row[$sort_col] . ':' . $row['sourceid'];
+            $key = rcmail_contact_key($row, $sort_col);
             $records[$key] = $row;
         }
Index: program/steps/addressbook/search.inc
===================================================================
--- program/steps/addressbook/search.inc	(revision 7fe3811c65a7c63154f03610e289a6d196f3ae2e)
+++ program/steps/addressbook/search.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -148,4 +148,5 @@
     $search_set = array();
     $records    = array();
+    $sort_col   = $RCMAIL->config->get('addressbook_sort_col', 'name');
 
     foreach ($sources as $s) {
@@ -186,5 +187,5 @@
         while ($row = $result->next()) {
             $row['sourceid'] = $s['id'];
-            $key = $row['name'] . ':' . $row['sourceid'];
+            $key = rcmail_contact_key($row, $sort_col);
             $records[$key] = $row;
         }
Index: program/steps/addressbook/undo.inc
===================================================================
--- program/steps/addressbook/undo.inc	(revision 7fe3811c65a7c63154f03610e289a6d196f3ae2e)
+++ program/steps/addressbook/undo.inc	(revision 0203f16312bc949a5cf46ce90fa43de9119e23a8)
@@ -69,11 +69,4 @@
         }
 
-        while ($row = $result->next()) {
-            $row['sourceid'] = $s;
-            $key = $row['name'] . ':' . $row['sourceid'];
-            $records[$key] = $row;
-        }
-        unset($result);
-
         $search[$s] = $source->get_search_set();
     }
