Do not repeat contacts

git-svn-id: https://svn.apache.org/repos/asf/james/hupa/trunk@1577821 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java b/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
index 84de47b..6172e70 100644
--- a/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
+++ b/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
@@ -32,8 +32,6 @@
  */
 public abstract class UserPreferencesStorage {
     
-    protected static final String CONTACTS_ATTR = "contacts";
-    
     protected static final String REGEX_OMITTED_EMAILS = "^.*(reply)[A-z0-9._%\\+\\-]*@.*$";
         
     /**
@@ -59,14 +57,28 @@
     final public void addContact(List<String> mails) {
         if (mails != null) {
             for (String mail: mails) {
-            	if (mail != null && !mail.matches(REGEX_OMITTED_EMAILS)) {
+                if (mail != null && !mail.matches(REGEX_OMITTED_EMAILS)) {
                     Contact contact = new Contact(mail);
-                    addContact(contact);
-            	}
+                    if (!exists(contact)) {
+                        addContact(contact);
+                    }
+                }
             }
         }
     }
     
+    boolean exists (Contact mail) {
+        for (Contact c : getContacts()) {
+            if (c.mail.equals(mail.mail)) {
+                if (c.realname == null || c.realname.isEmpty() || c.realname.equals(c.mail)) {
+                    c.realname = mail.realname;
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+    
     /**
      * Get the list of contacts 
      */