Author: manolo
Date: Sat Mar 15 10:32:46 2014
New Revision: 1577821

URL: http://svn.apache.org/r1577821
Log:
Do not repeat contacts

Modified:
    
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java

Modified: 
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
URL: 
http://svn.apache.org/viewvc/james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java?rev=1577821&r1=1577820&r2=1577821&view=diff
==============================================================================
--- 
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
 (original)
+++ 
james/hupa/trunk/server/src/main/java/org/apache/hupa/server/preferences/UserPreferencesStorage.java
 Sat Mar 15 10:32:46 2014
@@ -32,8 +32,6 @@ import java.util.List;
  */
 public abstract class UserPreferencesStorage {
     
-    protected static final String CONTACTS_ATTR = "contacts";
-    
     protected static final String REGEX_OMITTED_EMAILS = 
"^.*(reply)[A-z0-9._%\\+\\-]*@.*$";
         
     /**
@@ -59,12 +57,26 @@ public abstract class UserPreferencesSto
     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;
     }
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to