Index: src/java/org/apache/james/imapserver/ProtocolException.java
===================================================================
--- src/java/org/apache/james/imapserver/ProtocolException.java (revision 475827)
+++ src/java/org/apache/james/imapserver/ProtocolException.java (working copy)
@@ -24,8 +24,29 @@
  */
 public class ProtocolException extends Exception
 {
+    private final boolean resetConnection;
+
     public ProtocolException( String s )
     {
         super( s );
+        // TODO: This is the current behaviour but IMO this is wrong
+        resetConnection = true;
     }
+
+    /**
+     * Constructs an protocol exception.
+     * @param s message, not null
+     * @param resetConnection true if the connection should be reset,
+     * false otherwise
+     */
+    public ProtocolException( final String s , final boolean resetConnection)
+    {
+        super( s );
+        // TODO: This is the current behaviour but IMO this is wrong
+        this.resetConnection = resetConnection;
+    }
+
+    public boolean resetConnection() {
+        return resetConnection;
+    }
 }
Index: src/java/org/apache/james/imapserver/ImapHandler.java
===================================================================
--- src/java/org/apache/james/imapserver/ImapHandler.java	(revision 475827)
+++ src/java/org/apache/james/imapserver/ImapHandler.java	(working copy)
@@ -241,7 +241,7 @@
                                            socket.getInetAddress().getHostAddress());
 
             theWatchdog.start();
-            while ( requestHandler.handleRequest( ins, outs, session ) ) {
+            while ( handleNextRequest(remoteHost, remoteIP) ) {
                 if (!handlerIsUp) {
                     getLogger().debug("Handler has been resetted");
                     return;
@@ -249,6 +249,7 @@
                 theWatchdog.reset();
             }
             // TODO is this unreachable code because of !handlerIsUp -> return?
+            getLogger().warn("Stopping watchdog after handling last request");
             theWatchdog.stop();
             
 
@@ -290,6 +291,54 @@
         }
     }
 
+    private boolean handleNextRequest(String remoteHost, String remoteIP) throws ProtocolException {
+        boolean result = true;
+        try {
+            result = requestHandler.handleRequest( ins, outs, session );
+        } 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 );
+            }
+            if (e.resetConnection()) {
+                throw e;
+            }
+        } 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 );
+            }
+            //
+            // This will result in a connection reset.
+            //
+            throw e;
+        }
+        return result;
+    }
+    
+    
+
     /**
      * Resets the handler data to a basic state.
      */
