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 bt...@apache.org on 2018/01/19 02:19:26 UTC

[02/13] james-project git commit: JAMES-2310 Use LineBasedFrameDecoder instead of DelimiterBasedFrameDecoder

JAMES-2310 Use LineBasedFrameDecoder instead of DelimiterBasedFrameDecoder

The resulting decoder should be the same as before commit b4f1ed6 except
starttls handling. This is because delimiter decoder will try to use
line decoder *if* the delimiter is CRLF and LF AND the decoder is
not subclass of delimiter decoder. Therefore, before b4f1ed6 the
underlying decoder is actually line decoder, after that commit the
decoder became generic delimiter decoder which cause huge performance
drop (in my simple benchmark, using line decoder only take 60% time of
delimiter decoder to complete the same SMTP transcations).

The same applies to IMAP server's frame decoder.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/a2b0345d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/a2b0345d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/a2b0345d

Branch: refs/heads/master
Commit: a2b0345d3cc93201ecf142b4951fa69cb89cdb9b
Parents: 4247d88
Author: TzeKei Lee <ch...@gmail.com>
Authored: Tue Jan 16 23:59:44 2018 +0800
Committer: benwa <bt...@linagora.com>
Committed: Fri Jan 19 09:04:31 2018 +0700

----------------------------------------------------------------------
 .../AllButStartTlsDelimiterChannelHandler.java  | 79 -------------------
 .../AllButStartTlsLineBasedChannelHandler.java  | 80 ++++++++++++++++++++
 ...AllButStartTlsLineChannelHandlerFactory.java | 37 +++++++++
 ...rtTlsLineDelimiterChannelHandlerFactory.java | 38 ----------
 .../smtp/netty/NettyStartTlsSMTPServerTest.java |  4 +-
 .../james/imapserver/netty/IMAPServer.java      |  2 +-
 .../netty/ImapRequestFrameDecoder.java          |  4 +-
 .../SwitchableDelimiterBasedFrameDecoder.java   | 58 --------------
 .../netty/SwitchableLineBasedFrameDecoder.java  | 59 +++++++++++++++
 .../SwitchableLineBasedFrameDecoderFactory.java | 37 +++++++++
 ...leLineDelimiterBasedFrameDecoderFactory.java | 38 ----------
 .../james/smtpserver/netty/SMTPServer.java      |  4 +-
 12 files changed, 220 insertions(+), 220 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsDelimiterChannelHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsDelimiterChannelHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsDelimiterChannelHandler.java
deleted file mode 100644
index b42f1d3..0000000
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsDelimiterChannelHandler.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.protocols.smtp;
-
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.james.protocols.netty.HandlerConstants;
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
-
-import com.google.common.base.CharMatcher;
-import com.google.common.base.Splitter;
-
-
-public class AllButStartTlsDelimiterChannelHandler extends DelimiterBasedFrameDecoder {
-
-    private static final String STARTTLS = "starttls";
-    private final ChannelPipeline pipeline;
-
-    public AllButStartTlsDelimiterChannelHandler(ChannelPipeline pipeline, int maxFrameLength, boolean stripDelimiter, ChannelBuffer[] delimiters) {
-        super(maxFrameLength, stripDelimiter, delimiters);
-        this.pipeline = pipeline;
-    }
-
-    @Override
-    protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
-        SMTPSession session = (SMTPSession) pipeline.getContext(HandlerConstants.CORE_HANDLER).getAttachment();
-
-        if (session == null || session.needsCommandInjectionDetection()) {
-            String trimedLowerCasedInput = readAll(buffer).trim().toLowerCase(Locale.US);
-            if (hasCommandInjection(trimedLowerCasedInput)) {
-                throw new CommandInjectionDetectedException();
-            }
-        }
-        return super.decode(ctx, channel, buffer);
-    }
-
-    private String readAll(ChannelBuffer buffer) {
-        return buffer.toString(StandardCharsets.US_ASCII);
-    }
-
-    private boolean hasCommandInjection(String trimedLowerCasedInput) {
-        List<String> parts = Splitter.on(CharMatcher.anyOf("\r\n")).omitEmptyStrings()
-            .splitToList(trimedLowerCasedInput);
-
-        return hasInvalidStartTlsPart(parts) || multiPartsAndOneStartTls(parts);
-    }
-
-    private boolean multiPartsAndOneStartTls(List<String> parts) {
-        return parts.stream()
-            .anyMatch(line -> line.startsWith(STARTTLS)) && parts.size() > 1;
-    }
-
-    private boolean hasInvalidStartTlsPart(List<String> parts) {
-        return parts.stream()
-            .anyMatch(line -> line.startsWith(STARTTLS) && !line.endsWith(STARTTLS));
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineBasedChannelHandler.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineBasedChannelHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineBasedChannelHandler.java
new file mode 100644
index 0000000..eba24c6
--- /dev/null
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineBasedChannelHandler.java
@@ -0,0 +1,80 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.protocols.smtp;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.james.protocols.netty.HandlerConstants;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
+
+import com.google.common.base.CharMatcher;
+import com.google.common.base.Splitter;
+
+
+public class AllButStartTlsLineBasedChannelHandler extends LineBasedFrameDecoder {
+
+    private static final String STARTTLS = "starttls";
+    private static final Boolean FAIL_FAST = true;
+    private final ChannelPipeline pipeline;
+
+    public AllButStartTlsLineBasedChannelHandler(ChannelPipeline pipeline, int maxFrameLength, boolean stripDelimiter) {
+        super(maxFrameLength, stripDelimiter, !FAIL_FAST);
+        this.pipeline = pipeline;
+    }
+
+    @Override
+    protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
+        SMTPSession session = (SMTPSession) pipeline.getContext(HandlerConstants.CORE_HANDLER).getAttachment();
+
+        if (session == null || session.needsCommandInjectionDetection()) {
+            String trimedLowerCasedInput = readAll(buffer).trim().toLowerCase(Locale.US);
+            if (hasCommandInjection(trimedLowerCasedInput)) {
+                throw new CommandInjectionDetectedException();
+            }
+        }
+        return super.decode(ctx, channel, buffer);
+    }
+
+    private String readAll(ChannelBuffer buffer) {
+        return buffer.toString(StandardCharsets.US_ASCII);
+    }
+
+    private boolean hasCommandInjection(String trimedLowerCasedInput) {
+        List<String> parts = Splitter.on(CharMatcher.anyOf("\r\n")).omitEmptyStrings()
+            .splitToList(trimedLowerCasedInput);
+
+        return hasInvalidStartTlsPart(parts) || multiPartsAndOneStartTls(parts);
+    }
+
+    private boolean multiPartsAndOneStartTls(List<String> parts) {
+        return parts.stream()
+            .anyMatch(line -> line.startsWith(STARTTLS)) && parts.size() > 1;
+    }
+
+    private boolean hasInvalidStartTlsPart(List<String> parts) {
+        return parts.stream()
+            .anyMatch(line -> line.startsWith(STARTTLS) && !line.endsWith(STARTTLS));
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineChannelHandlerFactory.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineChannelHandlerFactory.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineChannelHandlerFactory.java
new file mode 100644
index 0000000..94d9b2f
--- /dev/null
+++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineChannelHandlerFactory.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.protocols.smtp;
+
+import org.apache.james.protocols.netty.ChannelHandlerFactory;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.channel.ChannelPipeline;
+
+public class AllButStartTlsLineChannelHandlerFactory implements ChannelHandlerFactory {
+
+    private int maxFrameLength;
+
+    public AllButStartTlsLineChannelHandlerFactory(int maxFrameLength) {
+        this.maxFrameLength = maxFrameLength;
+    }
+
+    @Override
+    public ChannelHandler create(ChannelPipeline pipeline) {
+        return new AllButStartTlsLineBasedChannelHandler(pipeline, maxFrameLength, false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineDelimiterChannelHandlerFactory.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineDelimiterChannelHandlerFactory.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineDelimiterChannelHandlerFactory.java
deleted file mode 100644
index 22939ff..0000000
--- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/AllButStartTlsLineDelimiterChannelHandlerFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.protocols.smtp;
-
-import org.apache.james.protocols.netty.ChannelHandlerFactory;
-import org.jboss.netty.channel.ChannelHandler;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.Delimiters;
-
-public class AllButStartTlsLineDelimiterChannelHandlerFactory implements ChannelHandlerFactory {
-
-    private int maxFrameLength;
-
-    public AllButStartTlsLineDelimiterChannelHandlerFactory(int maxFrameLength) {
-        this.maxFrameLength = maxFrameLength;
-    }
-
-    @Override
-    public ChannelHandler create(ChannelPipeline pipeline) {
-        return new AllButStartTlsDelimiterChannelHandler(pipeline, maxFrameLength, false, Delimiters.lineDelimiter());
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
----------------------------------------------------------------------
diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
index 5e33b6d..996f69b 100644
--- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
+++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/netty/NettyStartTlsSMTPServerTest.java
@@ -46,7 +46,7 @@ import org.apache.james.protocols.api.utils.BogusTrustManagerFactory;
 import org.apache.james.protocols.api.utils.ProtocolServerUtils;
 import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
 import org.apache.james.protocols.netty.NettyServer;
-import org.apache.james.protocols.smtp.AllButStartTlsLineDelimiterChannelHandlerFactory;
+import org.apache.james.protocols.smtp.AllButStartTlsLineChannelHandlerFactory;
 import org.apache.james.protocols.smtp.SMTPConfigurationImpl;
 import org.apache.james.protocols.smtp.SMTPProtocol;
 import org.apache.james.protocols.smtp.SMTPProtocolHandlerChain;
@@ -80,7 +80,7 @@ public class NettyStartTlsSMTPServerTest {
         NettyServer server = NettyServer.builder()
                 .protocol(protocol)
                 .secure(enc)
-                .frameHandlerFactory(new AllButStartTlsLineDelimiterChannelHandlerFactory(AbstractChannelPipelineFactory.MAX_LINE_LENGTH))
+                .frameHandlerFactory(new AllButStartTlsLineChannelHandlerFactory(AbstractChannelPipelineFactory.MAX_LINE_LENGTH))
                 .build();
         server.setListenAddresses(new InetSocketAddress(LOCALHOST_IP, RANDOM_PORT));
         return server;

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index bccdd57..d834e0b 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -225,7 +225,7 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
 
     @Override
     protected ChannelHandlerFactory createFrameHandlerFactory() {
-        return new SwitchableLineDelimiterBasedFrameDecoderFactory(maxLineLength);
+        return new SwitchableLineBasedFrameDecoderFactory(maxLineLength);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
index 2d7f44e..6e99515 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/ImapRequestFrameDecoder.java
@@ -180,7 +180,7 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
                 //    channel.getPipeline().addFirst(FRAMER, handler);
                 //}
                 
-                ((SwitchableDelimiterBasedFrameDecoder) channel.getPipeline().get(FRAMER)).enableFraming();
+                ((SwitchableLineBasedFrameDecoder) channel.getPipeline().get(FRAMER)).enableFraming();
                 
                 attachment.clear();
                 return message;
@@ -200,7 +200,7 @@ public class ImapRequestFrameDecoder extends FrameDecoder implements NettyConsta
                 //attachment.put(FRAMER, handler);
 
                 // SwitchableDelimiterBasedFrameDecoder added further to JAMES-1436.
-                final SwitchableDelimiterBasedFrameDecoder framer = (SwitchableDelimiterBasedFrameDecoder) pipeline.get(FRAMER);
+                final SwitchableLineBasedFrameDecoder framer = (SwitchableLineBasedFrameDecoder) pipeline.get(FRAMER);
                 framer.disableFraming(framerContext);
                 
                 buffer.resetReaderIndex();

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableDelimiterBasedFrameDecoder.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableDelimiterBasedFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableDelimiterBasedFrameDecoder.java
deleted file mode 100644
index 0b3e127..0000000
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableDelimiterBasedFrameDecoder.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.imapserver.netty;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.Channels;
-import org.jboss.netty.channel.MessageEvent;
-import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
-
-public class SwitchableDelimiterBasedFrameDecoder extends DelimiterBasedFrameDecoder {
-
-    private volatile boolean framingEnabled = true;
-
-    public SwitchableDelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, ChannelBuffer... delimiters) {
-        super(maxFrameLength, stripDelimiter, delimiters);
-    }
-
-    @Override
-    public synchronized void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
-        if (this.framingEnabled) {
-            super.messageReceived(ctx, e);
-        } else {
-            ctx.sendUpstream(e);
-        }
-    }
-
-    public synchronized void enableFraming() {
-        this.framingEnabled = true;
-
-    }
-
-    public synchronized void disableFraming(ChannelHandlerContext ctx) {
-        this.framingEnabled = false;
-        if (this.cumulation != null && this.cumulation.readable()) {
-            final ChannelBuffer spareBytes = this.cumulation.readBytes(this.cumulation.readableBytes());
-            Channels.fireMessageReceived(ctx, spareBytes);
-        }
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoder.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoder.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoder.java
new file mode 100644
index 0000000..b05cdc6
--- /dev/null
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoder.java
@@ -0,0 +1,59 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.imapserver.netty;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder;
+
+public class SwitchableLineBasedFrameDecoder extends LineBasedFrameDecoder {
+
+    private static final Boolean FAIL_FAST = true;
+    private volatile boolean framingEnabled = true;
+
+    public SwitchableLineBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter) {
+        super(maxFrameLength, stripDelimiter, !FAIL_FAST);
+    }
+
+    @Override
+    public synchronized void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
+        if (this.framingEnabled) {
+            super.messageReceived(ctx, e);
+        } else {
+            ctx.sendUpstream(e);
+        }
+    }
+
+    public synchronized void enableFraming() {
+        this.framingEnabled = true;
+
+    }
+
+    public synchronized void disableFraming(ChannelHandlerContext ctx) {
+        this.framingEnabled = false;
+        if (this.cumulation != null && this.cumulation.readable()) {
+            final ChannelBuffer spareBytes = this.cumulation.readBytes(this.cumulation.readableBytes());
+            Channels.fireMessageReceived(ctx, spareBytes);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
new file mode 100644
index 0000000..9c5f5d4
--- /dev/null
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imapserver.netty;
+
+import org.apache.james.protocols.netty.ChannelHandlerFactory;
+import org.jboss.netty.channel.ChannelHandler;
+import org.jboss.netty.channel.ChannelPipeline;
+
+public class SwitchableLineBasedFrameDecoderFactory implements ChannelHandlerFactory {
+
+    private int maxLineLength;
+
+    public SwitchableLineBasedFrameDecoderFactory(int maxLineLength) {
+        this.maxLineLength = maxLineLength;
+    }
+
+    @Override
+    public ChannelHandler create(ChannelPipeline pipeline) {
+        return new SwitchableLineBasedFrameDecoder(maxLineLength, false);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineDelimiterBasedFrameDecoderFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineDelimiterBasedFrameDecoderFactory.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineDelimiterBasedFrameDecoderFactory.java
deleted file mode 100644
index 0350f09..0000000
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineDelimiterBasedFrameDecoderFactory.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imapserver.netty;
-
-import org.apache.james.protocols.netty.ChannelHandlerFactory;
-import org.jboss.netty.channel.ChannelHandler;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.frame.Delimiters;
-
-public class SwitchableLineDelimiterBasedFrameDecoderFactory implements ChannelHandlerFactory {
-
-    private int maxLineLength;
-
-    public SwitchableLineDelimiterBasedFrameDecoderFactory(int maxLineLength) {
-        this.maxLineLength = maxLineLength;
-    }
-
-    @Override
-    public ChannelHandler create(ChannelPipeline pipeline) {
-        return new SwitchableDelimiterBasedFrameDecoder(maxLineLength, false, Delimiters.lineDelimiter());
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/a2b0345d/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
index a7c8233..78e1fe2 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
@@ -32,7 +32,7 @@ import org.apache.james.protocols.lib.handler.HandlersPackage;
 import org.apache.james.protocols.lib.netty.AbstractProtocolAsyncServer;
 import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
-import org.apache.james.protocols.smtp.AllButStartTlsLineDelimiterChannelHandlerFactory;
+import org.apache.james.protocols.smtp.AllButStartTlsLineChannelHandlerFactory;
 import org.apache.james.protocols.smtp.SMTPConfiguration;
 import org.apache.james.protocols.smtp.SMTPProtocol;
 import org.apache.james.smtpserver.CoreCmdHandlerLoader;
@@ -371,7 +371,7 @@ public class SMTPServer extends AbstractProtocolAsyncServer implements SMTPServe
 
     @Override
     protected ChannelHandlerFactory createFrameHandlerFactory() {
-        return new AllButStartTlsLineDelimiterChannelHandlerFactory(AbstractChannelPipelineFactory.MAX_LINE_LENGTH);
+        return new AllButStartTlsLineChannelHandlerFactory(AbstractChannelPipelineFactory.MAX_LINE_LENGTH);
     }
 
 }


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