Index: /common/java/workspace/james-trunk/src/conf/james-config.xml
===================================================================
--- /common/java/workspace/james-trunk/src/conf/james-config.xml	(revision 477676)
+++ /common/java/workspace/james-trunk/src/conf/james-config.xml	(working copy)
@@ -111,7 +111,8 @@
       <!-- port 993 is the well-known/IANA registered port for IMAPs ie over SSL/TLS -->
       <!-- port 143 is the well-known/IANA registered port for Standard IMAP4 -->
       <port>10143</port>
-
+	  <!-- RFC 3501 requires a minimum timeout of 30 minutes -->
+      <sockettimeout>1800000</sockettimeout>      
       <handler>
        <!-- RFC 3501 requires a minimum timeout of 30 minutes -->
        <connectiontimeout>1800000</connectiontimeout>         
Index: /common/java/workspace/james-trunk/src/java/org/apache/james/core/AbstractJamesService.java
===================================================================
--- /common/java/workspace/james-trunk/src/java/org/apache/james/core/AbstractJamesService.java	(revision 477670)
+++ /common/java/workspace/james-trunk/src/java/org/apache/james/core/AbstractJamesService.java	(working copy)
@@ -70,6 +70,11 @@
      * The name of the parameter defining the connection timeout.
      */
     protected static final String TIMEOUT_NAME = "connectiontimeout";
+    
+    /**
+     * The name of the parameter defining the connection timeout.
+     */
+    protected static final String SOCKET_TIMEOUT_NAME = "sockettimeout";
 
     /**
      * The default value for the connection backlog.
@@ -141,6 +146,11 @@
      * problems from hanging a connection.
      */
     protected int timeout;
+    
+    /**
+     * The socket idle timeout for the connections (null = use default) 
+     */
+    private Integer socketTimeout = null;
 
     /**
      * The connection backlog.
@@ -191,6 +201,8 @@
      */
     private String streamDumpDir = null;
 
+
+
     public void setConnectionManager(JamesConnectionManager connectionManager) {
         this.connectionManager = connectionManager;
     }
@@ -295,6 +307,11 @@
                     .append(" handler connection timeout is: ")
                     .append(timeout);
         getLogger().info(infoBuffer.toString());
+        
+        if (conf.getChild(SOCKET_TIMEOUT_NAME).getValue(null)!=null) {
+            socketTimeout = new Integer(conf.getChild(SOCKET_TIMEOUT_NAME).getValueAsInteger());
+            getLogger().info(getServiceType()+" socket timeout is: "+socketTimeout);
+        }
 
         backlog = conf.getChild(BACKLOG_NAME).getValueAsInteger(DEFAULT_BACKLOG);
 
@@ -475,19 +492,19 @@
             }
             connectionName = sb.toString();
         }
-
+        
         if ((connectionLimit != null)) {
             if (null != threadPool) {
             if (connPerIPConfigured) {
-                    connectionManager.connect(connectionName, serverSocket, this, threadPool, connectionLimit.intValue(),connPerIP);
+                    connectionManager.connect(connectionName, serverSocket, this, threadPool, connectionLimit.intValue(),connPerIP,socketTimeout);
             } else {
-                connectionManager.connect(connectionName, serverSocket, this, threadPool, connectionLimit.intValue());
+                connectionManager.connect(connectionName, serverSocket, this, threadPool, connectionLimit.intValue(),socketTimeout);
             }
             } else {
             if (connPerIPConfigured) {
-                    connectionManager.connect(connectionName, serverSocket, this, connectionLimit.intValue(),connPerIP); // default pool
+                    connectionManager.connect(connectionName, serverSocket, this, connectionLimit.intValue(),connPerIP,socketTimeout); // default pool
                 } else {
-                    connectionManager.connect(connectionName, serverSocket, this, connectionLimit.intValue());
+                    connectionManager.connect(connectionName, serverSocket, this, connectionLimit.intValue(),socketTimeout);
                 }
             }
         } else {
@@ -493,15 +510,15 @@
         } else {
             if (null != threadPool) {
             if (connPerIPConfigured) {
-                    connectionManager.connect(connectionName, serverSocket, this, threadPool);
+                    connectionManager.connect(connectionName, serverSocket, this, threadPool,socketTimeout);
             } else {
-                connectionManager.connect(connectionName, serverSocket, this, threadPool, 0, connPerIP);
+                connectionManager.connect(connectionName, serverSocket, this, threadPool, 0, connPerIP,socketTimeout);
             }
             } else {
             if (connPerIPConfigured) {
-                    connectionManager.connect(connectionName, serverSocket, this); // default pool
+                    connectionManager.connect(connectionName, serverSocket, this,socketTimeout); // default pool
             } else {
-                    connectionManager.connect(connectionName, serverSocket, this, 0, connPerIP);
+                    connectionManager.connect(connectionName, serverSocket, this, 0, connPerIP, socketTimeout);
             }
             }
         }
Index: /common/java/workspace/james-trunk/src/java/org/apache/james/services/JamesConnectionManager.java
===================================================================
--- /common/java/workspace/james-trunk/src/java/org/apache/james/services/JamesConnectionManager.java	(revision 477670)
+++ /common/java/workspace/james-trunk/src/java/org/apache/james/services/JamesConnectionManager.java	(working copy)
@@ -57,6 +57,7 @@
      * @param handlerFactory the factory from which to acquire handlers
      * @param threadPool the thread pool to use
      * @param maxOpenConnections the maximum number of open connections allowed for this server socket.
+     * @param socketTimeout the socket timeout
      * @exception Exception if an error occurs
      */
     void connect( String name,
@@ -63,7 +64,8 @@
                   ServerSocket socket,
                   ConnectionHandlerFactory handlerFactory,
                   ThreadPool threadPool,
-                  int maxOpenConnections )
+                  int maxOpenConnections, 
+                  Integer socketTimeout)
         throws Exception;
     
     /**
@@ -74,6 +76,7 @@
      * @param socket the ServerSocket from which to
      * @param handlerFactory the factory from which to acquire handlers
      * @param maxOpenConnections the maximum number of open connections allowed for this server socket.
+     * @param socketTimeout the socket timeout
      * @exception Exception if an error occurs
      */
     void connect( String name,
@@ -79,7 +82,8 @@
     void connect( String name,
                   ServerSocket socket,
                   ConnectionHandlerFactory handlerFactory,
-                  int maxOpenConnections )
+                  int maxOpenConnections,
+                  Integer socketTimeout)
         throws Exception;
 
     /**
@@ -91,6 +95,7 @@
      * @param socket the ServerSocket from which to
      * @param handlerFactory the factory from which to acquire handlers
      * @param threadPool the thread pool to use
+     * @param socketTimeout the socket timeout
      * @exception Exception if an error occurs
      */
     void connect( String name,
@@ -96,7 +101,8 @@
     void connect( String name,
                   ServerSocket socket,
                   ConnectionHandlerFactory handlerFactory,
-                  ThreadPool threadPool )
+                  ThreadPool threadPool,
+                  Integer socketTimeout )
         throws Exception;
     
     /**
@@ -107,6 +113,7 @@
      * @param name the name of connection
      * @param socket the ServerSocket from which to
      * @param handlerFactory the factory from which to acquire handlers
+     * @param socketTimeout the socket timeout
      * @exception Exception if an error occurs
      */
     void connect( String name,
@@ -111,7 +118,8 @@
      */
     void connect( String name,
                   ServerSocket socket,
-                  ConnectionHandlerFactory handlerFactory )
+                  ConnectionHandlerFactory handlerFactory,
+                  Integer socketTimeout)
         throws Exception;
     
     /**
@@ -125,6 +133,7 @@
      * @param threadPool the thread pool to use
      * @param maxOpenConnections the maximum number of open connections allowed for this server socket.
      * @param maxOpenConnectionsPerIP the maximum number of open connections per IP allowed for this server socket.
+     * @param socketTimeout the socket timeout
      * @throws Exception
      */
     void connect( String name,
@@ -132,9 +141,10 @@
             ConnectionHandlerFactory handlerFactory,
             ThreadPool threadPool,
             int maxOpenConnections,
-            int maxOpenConnectionsPerIP)
-            throws Exception;
-
+            int maxOpenConnectionsPerIP,
+            Integer socketTimeout)
+            throws Exception;    
+    
     /**
      * Start managing a connection.
      * Management involves accepting connections and farming them out to threads
@@ -145,6 +155,7 @@
      * @param handlerFactory the factory from which to acquire handlers
      * @param maxOpenConnections the maximum number of open connections allowed for this server socket.
      * @param maxOpenConnectionsPerIP the maximum number of open connections per IP allowed for this server socket.
+     * @param socketTimeout the socket timeout
      * @throws Exception
      */
     void connect( String name,
@@ -151,7 +162,8 @@
             ServerSocket socket,
             ConnectionHandlerFactory handlerFactory,
             int maxOpenConnections,
-            int maxOpenConnectionsPerIP)
+            int maxOpenConnectionsPerIP,
+            Integer socketTimeout)
             throws Exception;
     
     /**
Index: /common/java/workspace/james-trunk/src/java/org/apache/james/util/connection/SimpleConnectionManager.java
===================================================================
--- /common/java/workspace/james-trunk/src/java/org/apache/james/util/connection/SimpleConnectionManager.java	(revision 477670)
+++ /common/java/workspace/james-trunk/src/java/org/apache/james/util/connection/SimpleConnectionManager.java	(working copy)
@@ -174,6 +174,7 @@
      * @param threadPool the thread pool to use
      * @param maxOpenConnections the maximum number of open connections allowed for this server socket.
      * @param maxOpenConnectionsPerIP the maximum number of open connections per IP allowed for this server socket.
+     * @param socketTimeout the socket timeout
      * @exception Exception if an error occurs
      */
     public void connect(
@@ -182,8 +183,15 @@
         ConnectionHandlerFactory handlerFactory,
         ThreadPool threadPool,
         int maxOpenConnections,
-        int maxOpenConnectionsPerIP)
+        int maxOpenConnectionsPerIP, 
+        Integer socketTimeout)
         throws Exception {
+        
+        if (socketTimeout==null) {
+            // set Default
+            socketTimeout= new Integer(timeout);
+        }
+        
         if (disposed) {
             throw new IllegalStateException("Connection manager has already been shutdown.");
         }
@@ -196,8 +204,11 @@
         if (maxOpenConnectionsPerIP < 0) {
             throw new IllegalArgumentException("The maximum number of client connections (per IP) per server socket cannot be less that zero.");
         }
+        if (socketTimeout.intValue() < 0) {
+            throw new IllegalArgumentException("The socket timeout cannot be less that zero.");
+        }
         ServerConnection runner =
-            new ServerConnection(socket, handlerFactory, threadPool, timeout, maxOpenConnections, maxOpenConnectionsPerIP);
+            new ServerConnection(socket, handlerFactory, threadPool, socketTimeout.intValue(), maxOpenConnections, maxOpenConnectionsPerIP);
         setupLogger(runner);
         ContainerUtil.initialize(runner);
         connectionMap.put(name, runner);
@@ -220,9 +231,35 @@
         String name,
         ServerSocket socket,
         ConnectionHandlerFactory handlerFactory,
+        ThreadPool threadPool, 
+        Integer socketTimeout)
+        throws Exception {
+        connect(name, socket, handlerFactory, threadPool, maxOpenConn, maxOpenConnPerIP,socketTimeout);
+    }
+    
+    
+    /**
+     * Start managing a connection. Management involves accepting connections
+     * and farming them out to threads from pool to be handled.
+     * 
+     * @param name
+     *            the name of connection
+     * @param socket
+     *            the ServerSocket from which to
+     * @param handlerFactory
+     *            the factory from which to acquire handlers
+     * @param threadPool
+     *            the thread pool to use
+     * @exception Exception
+     *                if an error occurs
+     */
+    public void connect(
+        String name,
+        ServerSocket socket,
+        ConnectionHandlerFactory handlerFactory,
         ThreadPool threadPool)
         throws Exception {
-        connect(name, socket, handlerFactory, threadPool, maxOpenConn, maxOpenConnPerIP);
+        connect(name, socket, handlerFactory, threadPool, maxOpenConn, maxOpenConnPerIP,null);
     }
     
     
@@ -235,9 +272,17 @@
      * @param handlerFactory the factory from which to acquire handlers
      * @exception Exception if an error occurs
      */
-    public void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory)
+    public void connect(String name, ServerSocket socket, 
+            ConnectionHandlerFactory handlerFactory, 
+            Integer socketTimeout)
         throws Exception {
-        connect(name, socket, handlerFactory, threadManager.getDefaultThreadPool());
+        connect(name, socket, handlerFactory, threadManager.getDefaultThreadPool(),socketTimeout);
+    }
+
+    public void connect(String name, ServerSocket socket, 
+            ConnectionHandlerFactory handlerFactory)
+        throws Exception {
+        connect(name, socket, handlerFactory, threadManager.getDefaultThreadPool(),null);
     }
     
     
@@ -255,9 +300,10 @@
         String name,
         ServerSocket socket,
         ConnectionHandlerFactory handlerFactory,
-        int maxOpenConnections)
+        int maxOpenConnections, 
+        Integer socketTimeout)
         throws Exception {
-        connect(name, socket, handlerFactory, threadManager.getDefaultThreadPool(), maxOpenConnections);
+        connect(name, socket, handlerFactory, threadManager.getDefaultThreadPool(), maxOpenConnections, socketTimeout);
     }
     
     
@@ -295,8 +341,10 @@
     /**
      * @see org.apache.james.services.JamesConnectionManager#connect(java.lang.String, java.net.ServerSocket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory, org.apache.excalibur.thread.ThreadPool, int)
      */
-    public void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory, ThreadPool threadPool, int maxOpenConnections) throws Exception {
-        connect(name,socket,handlerFactory,threadPool,maxOpenConnections,maxOpenConnPerIP);
+    public void connect(String name, ServerSocket socket, 
+            ConnectionHandlerFactory handlerFactory, ThreadPool threadPool, 
+            int maxOpenConnections, Integer socketTimeout) throws Exception {
+        connect(name,socket,handlerFactory,threadPool,maxOpenConnections,maxOpenConnPerIP,socketTimeout);
     }
   
     
@@ -303,8 +351,10 @@
     /**
      * @see org.apache.james.services.JamesConnectionManager#connect(java.lang.String, java.net.ServerSocket, org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory, int, int)
      */
-    public void connect(String name, ServerSocket socket, ConnectionHandlerFactory handlerFactory, int maxOpenConnections,int maxOpenConnectionsPerIP) throws Exception {
-        connect(name,socket,handlerFactory,threadManager.getDefaultThreadPool(),maxOpenConnections,maxOpenConnectionsPerIP);
+    public void connect(String name, ServerSocket socket, 
+            ConnectionHandlerFactory handlerFactory, int maxOpenConnections,
+            int maxOpenConnectionsPerIP, Integer socketTimeout) throws Exception {
+        connect(name,socket,handlerFactory,threadManager.getDefaultThreadPool(),maxOpenConnections,maxOpenConnectionsPerIP,socketTimeout);
     }
     
     
