Subject: Re: bug#17720: 24.3; EUDC LDAP duplicate mail handling broken.

From: Thomas Fitzsimmons <[email-masked]>
Date: Wed, 24 Dec 2014 01:30:06 -0500

Hi Raimund,

Can you try this patch?

Thanks,
Thomas
diff --git a/lisp/net/eudcb-ldap.el b/lisp/net/eudcb-ldap.el
index 6c806d7..1c5bab2 100644
--- a/lisp/net/eudcb-ldap.el
+++ b/lisp/net/eudcb-ldap.el
@@ -74,16 +74,28 @@
 		   '(eudc-ldap-check-base)
 		   'ldap)
 
+(defun eudc-ldap-combine-mail-fields (record)
+  "Combine mail fields in RECORD."
+  (let (result)
+    (dolist (element record)
+      (let ((result-element (assoc (car element) result)))
+	(if (and result-element (eq (car element) 'mail))
+	    (setf (cdr result-element)
+		  (list (cdr result-element) (cdr element)))
+	  (setq result (append result (list element))))))
+    result))
+
 (defun eudc-ldap-cleanup-record-simple (record)
   "Do some cleanup in a RECORD to make it suitable for EUDC."
-  (mapcar
-   (function
-    (lambda (field)
-      (cons (intern (car field))
-	    (if (cdr (cdr field))
-		(cdr field)
-	      (car (cdr field))))))
-   record))
+  (eudc-ldap-combine-mail-fields
+   (mapcar
+    (function
+     (lambda (field)
+       (cons (intern (car field))
+	     (if (cdr (cdr field))
+		 (cdr field)
+	       (car (cdr field))))))
+    record)))
 
 (defun eudc-filter-$ (string)
   (mapconcat 'identity (split-string string "\\$") "\n"))
@@ -92,18 +104,19 @@
 ;;   Make the record a cons-cell instead of a list if it is single-valued
 ;;   Filter the $ character in addresses into \n if not done by the LDAP lib
 (defun eudc-ldap-cleanup-record-filtering-addresses (record)
-  (mapcar
-   (function
-    (lambda (field)
-      (let ((name (intern (car field)))
-	    (value (cdr field)))
-	(if (memq name '(postaladdress registeredaddress))
-	    (setq value (mapcar 'eudc-filter-$ value)))
-	(cons name
-	      (if (cdr value)
-		  value
-		(car value))))))
-   record))
+  (eudc-ldap-combine-mail-fields
+   (mapcar
+    (function
+     (lambda (field)
+       (let ((name (intern (car field)))
+	     (value (cdr field)))
+	 (if (memq name '(postaladdress registeredaddress))
+	     (setq value (mapcar 'eudc-filter-$ value)))
+	 (cons name
+	       (if (cdr value)
+		   value
+		 (car value))))))
+    record)))
 
 (defun eudc-ldap-simple-query-internal (query &optional return-attrs)
   "Query the LDAP server with QUERY.