You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ba...@apache.org on 2006/07/27 01:30:14 UTC

svn commit: r425902 - in /james/server/trunk/src/java/org/apache: james/transport/mailets/ james/transport/mailets/smime/ mailet/

Author: bago
Date: Wed Jul 26 16:30:13 2006
New Revision: 425902

URL: http://svn.apache.org/viewvc?rev=425902&view=rev
Log:
Move utility methods (checkInitParameter / arrayAsString) from specific mailets to GenericMailet (this code does not introduce new dependencies and remove duplication)
Hint came from http://james.apache.org/server/cpd.html

Modified:
    james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
    james/server/trunk/src/java/org/apache/james/transport/mailets/ClamAVScan.java
    james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
    james/server/trunk/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java
    james/server/trunk/src/java/org/apache/mailet/GenericMailet.java

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java?rev=425902&r1=425901&r2=425902&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/AbstractRedirect.java Wed Jul 26 16:30:13 2006
@@ -1140,25 +1140,6 @@
     }
 
     /**
-     * Utility method for obtaining a string representation of an array of Objects.
-     */
-    private String arrayToString(Object[] array) {
-        if (array == null) {
-            return "null";
-        }
-        StringBuffer sb = new StringBuffer(1024);
-        sb.append("[");
-        for (int i = 0; i < array.length; i++) {
-            if (i > 0) {
-                sb.append(",");
-            }
-            sb.append(array[i]);
-        }
-        sb.append("]");
-        return sb.toString();
-    }
-
-    /**
      * Utility method for obtaining a string representation of a
      * Message's headers
      */
@@ -1414,37 +1395,6 @@
         if (getFakeDomainCheck(mail)) {
             return mail.getSender() == null || getMailetContext().getMailServers(mail.getSender().getHost()).size() != 0;
         } else return true;
-    }
-    
-    /**
-     * Checks if there are unallowed init parameters specified in the configuration file
-     * against the String[] allowedInitParameters.
-     */
-    private void checkInitParameters(String[] allowedArray) throws MessagingException {
-        // if null then no check is requested
-        if (allowedArray == null) {
-            return;
-        }
-        
-        Collection allowed = new HashSet();
-        Collection bad = new ArrayList();
-        
-        for (int i = 0; i < allowedArray.length; i++) {
-            allowed.add(allowedArray[i]);
-        }
-        
-        Iterator iterator = getInitParameterNames();
-        while (iterator.hasNext()) {
-            String parameter = (String) iterator.next();
-            if (!allowed.contains(parameter)) {
-                bad.add(parameter);
-            }
-        }
-        
-        if (bad.size() > 0) {
-            throw new MessagingException("Unexpected init parameters found: "
-                                         + arrayToString(bad.toArray()));
-        }
     }
 
     /**

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/ClamAVScan.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/ClamAVScan.java?rev=425902&r1=425901&r2=425902&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/ClamAVScan.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/ClamAVScan.java Wed Jul 26 16:30:13 2006
@@ -36,8 +36,6 @@
 import java.net.InetAddress;
 import java.net.Socket;
 import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
@@ -185,7 +183,7 @@
     
     private static final int DEFAULT_STREAM_BUFFER_SIZE = 8192;
     
-    private static final int DEFAULT_CONNECTION_TIMEOUT = 20000;
+    //private static final int DEFAULT_CONNECTION_TIMEOUT = 20000;
 
     private static final String STREAM_PORT_STRING = "PORT ";
     
@@ -706,58 +704,6 @@
             } catch (Throwable t) {}
         }
         
-    }
-    
-    /**
-     * Checks if there are unallowed init parameters specified in the configuration file
-     * against the String[] allowedInitParameters.
-     * @param allowedArray array of strings containing the allowed parameter names
-     * @throws MessagingException if an unknown parameter name is found
-     */
-    protected final void checkInitParameters(String[] allowedArray) throws MessagingException {
-        // if null then no check is requested
-        if (allowedArray == null) {
-            return;
-        }
-        
-        Collection allowed = new HashSet();
-        Collection bad = new ArrayList();
-        
-        for (int i = 0; i < allowedArray.length; i++) {
-            allowed.add(allowedArray[i]);
-        }
-        
-        Iterator iterator = getInitParameterNames();
-        while (iterator.hasNext()) {
-            String parameter = (String) iterator.next();
-            if (!allowed.contains(parameter)) {
-                bad.add(parameter);
-            }
-        }
-        
-        if (bad.size() > 0) {
-            throw new MessagingException("Unexpected init parameters found: "
-                    + arrayToString(bad.toArray()));
-        }
-    }
-    
-    /**
-     * Utility method for obtaining a string representation of an array of Objects.
-     */
-    private final String arrayToString(Object[] array) {
-        if (array == null) {
-            return "null";
-        }
-        StringBuffer sb = new StringBuffer(1024);
-        sb.append("[");
-        for (int i = 0; i < array.length; i++) {
-            if (i > 0) {
-                sb.append(",");
-            }
-            sb.append(array[i]);
-        }
-        sb.append("]");
-        return sb.toString();
     }
     
     /**

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java?rev=425902&r1=425901&r2=425902&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/DSNBounce.java Wed Jul 26 16:30:13 2006
@@ -552,25 +552,6 @@
     }
 
     /**
-     * Utility method for obtaining a string representation of an array of Objects.
-     */
-    private String arrayToString(Object[] array) {
-        if (array == null) {
-            return "null";
-        }
-        StringBuffer sb = new StringBuffer(1024);
-        sb.append("[");
-        for (int i = 0; i < array.length; i++) {
-            if (i > 0) {
-                sb.append(",");
-            }
-            sb.append(array[i]);
-        }
-        sb.append("]");
-        return sb.toString();
-    }
-
-    /**
      * Create a unique new primary key name.
      *
      * @param mail the mail to use as the basis for the new mail name

Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java?rev=425902&r1=425901&r2=425902&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/smime/SMIMEAbstractSign.java Wed Jul 26 16:30:13 2006
@@ -33,11 +33,7 @@
 import javax.mail.internet.ParseException;
 
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
 
 /**
  * <P>Abstract mailet providing common SMIME signature services.<BR>
@@ -555,56 +551,6 @@
      * @return The massaged MimeBodyPart to sign, or null to have the whole message signed "as is".
      */    
     protected abstract MimeBodyPart getWrapperBodyPart(Mail mail) throws MessagingException, IOException;
-    
-    /**
-     * Checks if there are unallowed init parameters specified in the configuration file
-     * against the String[] allowedInitParameters.
-     */
-    private void checkInitParameters(String[] allowedArray) throws MessagingException {
-        // if null then no check is requested
-        if (allowedArray == null) {
-            return;
-        }
-        
-        Collection allowed = new HashSet();
-        Collection bad = new ArrayList();
-        
-        for (int i = 0; i < allowedArray.length; i++) {
-            allowed.add(allowedArray[i]);
-        }
-        
-        Iterator iterator = getInitParameterNames();
-        while (iterator.hasNext()) {
-            String parameter = (String) iterator.next();
-            if (!allowed.contains(parameter)) {
-                bad.add(parameter);
-            }
-        }
-        
-        if (bad.size() > 0) {
-            throw new MessagingException("Unexpected init parameters found: "
-            + arrayToString(bad.toArray()));
-        }
-    }
-    
-    /**
-     * Utility method for obtaining a string representation of an array of Objects.
-     */
-    private final String arrayToString(Object[] array) {
-        if (array == null) {
-            return "null";
-        }
-        StringBuffer sb = new StringBuffer(1024);
-        sb.append("[");
-        for (int i = 0; i < array.length; i++) {
-            if (i > 0) {
-                sb.append(",");
-            }
-            sb.append(array[i]);
-        }
-        sb.append("]");
-        return sb.toString();
-    }
     
     /**
      * Utility method that checks if there is at least one address in the "From:" header

Modified: james/server/trunk/src/java/org/apache/mailet/GenericMailet.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/mailet/GenericMailet.java?rev=425902&r1=425901&r2=425902&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/mailet/GenericMailet.java (original)
+++ james/server/trunk/src/java/org/apache/mailet/GenericMailet.java Wed Jul 26 16:30:13 2006
@@ -18,6 +18,10 @@
 package org.apache.mailet;
 
 import javax.mail.MessagingException;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
 
 /**
@@ -207,6 +211,61 @@
      * @throws javax.mail.MessagingException - if an exception occurs that interferes with the mailet's normal operation
      */
     public abstract void service(Mail mail) throws javax.mail.MessagingException;
+    
+    
+    
+    /**
+     * Utility method: Checks if there are unallowed init parameters specified in the 
+     * configuration file against the String[] allowedInitParameters.
+     * @param allowedArray array of strings containing the allowed parameter names
+     * @throws MessagingException if an unknown parameter name is found
+     */
+    protected final void checkInitParameters(String[] allowedArray) throws MessagingException {
+        // if null then no check is requested
+        if (allowedArray == null) {
+            return;
+        }
+        
+        Collection allowed = new HashSet();
+        Collection bad = new ArrayList();
+        
+        for (int i = 0; i < allowedArray.length; i++) {
+            allowed.add(allowedArray[i]);
+        }
+        
+        Iterator iterator = getInitParameterNames();
+        while (iterator.hasNext()) {
+            String parameter = (String) iterator.next();
+            if (!allowed.contains(parameter)) {
+                bad.add(parameter);
+            }
+        }
+        
+        if (bad.size() > 0) {
+            throw new MessagingException("Unexpected init parameters found: "
+                    + arrayToString(bad.toArray()));
+        }
+    }
+    
+    /**
+     * Utility method for obtaining a string representation of an array of Objects.
+     */
+    protected final String arrayToString(Object[] array) {
+        if (array == null) {
+            return "null";
+        }
+        StringBuffer sb = new StringBuffer(1024);
+        sb.append("[");
+        for (int i = 0; i < array.length; i++) {
+            if (i > 0) {
+                sb.append(",");
+            }
+            sb.append(array[i]);
+        }
+        sb.append("]");
+        return sb.toString();
+    }
+
 }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org