Index: src/java/org/apache/james/imapserver/ImapHandler.java
===================================================================
--- src/java/org/apache/james/imapserver/ImapHandler.java	(revision 477313)
+++ src/java/org/apache/james/imapserver/ImapHandler.java	(working copy)
@@ -37,7 +37,9 @@
         extends AbstractJamesHandler
         implements ImapHandlerInterface, ConnectionHandler, Poolable, ImapConstants
 {
-
+    
+    private static final int MINIMUM_IMAP_AUTOTIMOUT = 1800000;
+    
     private String softwaretype = "JAMES "+VERSION+" Server " + Constants.SOFTWARE_VERSION;
     private final ImapRequestHandler requestHandler = new ImapRequestHandler();
     private ImapSession session;
@@ -115,9 +117,21 @@
     
     protected void initHandler( Socket connection ) throws IOException {
         handlerIsUp=true;
-        getLogger().debug("Accepting connection for "+connection.toString());
-        // DEBUG
         
+        //      DEBUG
+        final int soTimeout = connection.getSoTimeout();
+        final Logger logger = getLogger();
+        if (logger.isDebugEnabled()) {
+            logger.debug("Accepting connection for "+connection.toString());
+            logger.debug("SO_TIMEOUT: " + soTimeout);
+            logger.debug("SO_KEEPALIVE: " + connection.getKeepAlive());
+        }
+        if (soTimeout > 0 && soTimeout < MINIMUM_IMAP_AUTOTIMOUT && logger.isWarnEnabled()) {
+            logger.warn("Timeout is set to " + soTimeout + ". This is less than required by RFC2060$5.4 and " +
+            "clients may experience timeouts. A timeout > 1800000 is recommended.");
+        }
+        
+        
         super.initHandler(connection);
     }
 
@@ -153,8 +167,46 @@
                     "Connection from " + remoteHost + " (" + remoteIP
                             + ") closed.");
 
+
+        } catch (RuntimeException e) {
+            // This most likely indicates a programming error
+            // Propagating this exception means that the 
+            // connection will be reset.
+            // IMAP is stateful. This behaviour makes the
+            // client nearly unusable.
+            final Logger logger = getLogger();
+            if (logger.isErrorEnabled()) {
+                StringBuffer exceptionBuffer =
+                    new StringBuffer( 128 )
+                .append( "IMAP failure on connection from " )
+                .append( remoteHost )
+                .append( " (" )
+                .append( remoteIP )
+                .append( ") : " )
+                .append( e.getMessage() );
+                logger.error( exceptionBuffer.toString(), e );
+            }
+            // NOTE: this will result in a connection reset
+            // For some client, this will make the IMAP server unusable
+            // TODO: more flexible and configurable exception handling
+            throw e;
         }
         catch (ProtocolException e) {
+            final Logger logger = getLogger();
+            if (logger.isInfoEnabled()) {
+                StringBuffer exceptionBuffer =
+                    new StringBuffer( 128 )
+                .append( "IMAP Protocol failure on connection from " )
+                .append( remoteHost )
+                .append( " (" )
+                .append( remoteIP )
+                .append( ") : " )
+                .append( e.getMessage() );
+                logger.info( exceptionBuffer.toString(), e );
+            }
+            // NOTE: this will result in a connection reset
+            // For some client, this will make the IMAP server unusable
+            // TODO: more flexible and configurable exception handling
             throw new RuntimeException(e.getMessage(),e);
         }
     }
