// Path: src/test/java/com/hubspot/smtp/ExtensibleNettyServer.java
// static final String NETTY_CHANNEL = "netty channel";


import static com.hubspot.smtp.ExtensibleNettyServer.NETTY_CHANNEL;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.future.FutureResponseImpl;
import org.apache.james.protocols.api.handler.CommandHandler;
import org.apache.james.protocols.api.handler.ExtensibleHandler;
import org.apache.james.protocols.api.handler.LineHandler;
import org.apache.james.protocols.api.handler.WiringException;
import org.apache.james.protocols.netty.HandlerConstants;
import org.apache.james.protocols.smtp.MailAddress;
import org.apache.james.protocols.smtp.MailEnvelopeImpl;
import org.apache.james.protocols.smtp.SMTPResponse;
import org.apache.james.protocols.smtp.SMTPRetCode;
import org.apache.james.protocols.smtp.SMTPSession;
import org.apache.james.protocols.smtp.core.esmtp.EhloExtension;
import org.apache.james.protocols.smtp.dsn.DSNStatus;
import org.apache.james.protocols.smtp.hook.Hook;
import org.apache.james.protocols.smtp.hook.MessageHook;
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.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import com.google.common.collect.Lists;
package com.hubspot.smtp;





public class ChunkingExtension implements EhloExtension, CommandHandler<SMTPSession>, ExtensibleHandler, Hook {
  private static final String MAIL_ENVELOPE = "mail envelope";
  private static final String BDAT_HANDLER_NAME = "BDAT handler";
  private static final Pattern BDAT_COMMAND_PATTERN = Pattern.compile("(?<size>[0-9]+)(?<last> LAST)?");

  private static final Response DELIVERY_SYNTAX = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
      DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX) + " Invalid syntax").immutable();

  private List<MessageHook> messageHandlers;

  @Override
  public Response onCommand(SMTPSession session, Request request) {
    Matcher matcher = BDAT_COMMAND_PATTERN.matcher(request.getArgument());
    if (!matcher.matches()) {
      return DELIVERY_SYNTAX;
    }

// Path: src/test/java/com/hubspot/smtp/ExtensibleNettyServer.java
// static final String NETTY_CHANNEL = "netty channel";


// Path: src/test/java/com/hubspot/smtp/ChunkingExtension.java
import static com.hubspot.smtp.ExtensibleNettyServer.NETTY_CHANNEL;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.james.protocols.api.ProtocolSession;
import org.apache.james.protocols.api.ProtocolSession.State;
import org.apache.james.protocols.api.Request;
import org.apache.james.protocols.api.Response;
import org.apache.james.protocols.api.future.FutureResponseImpl;
import org.apache.james.protocols.api.handler.CommandHandler;
import org.apache.james.protocols.api.handler.ExtensibleHandler;
import org.apache.james.protocols.api.handler.LineHandler;
import org.apache.james.protocols.api.handler.WiringException;
import org.apache.james.protocols.netty.HandlerConstants;
import org.apache.james.protocols.smtp.MailAddress;
import org.apache.james.protocols.smtp.MailEnvelopeImpl;
import org.apache.james.protocols.smtp.SMTPResponse;
import org.apache.james.protocols.smtp.SMTPRetCode;
import org.apache.james.protocols.smtp.SMTPSession;
import org.apache.james.protocols.smtp.core.esmtp.EhloExtension;
import org.apache.james.protocols.smtp.dsn.DSNStatus;
import org.apache.james.protocols.smtp.hook.Hook;
import org.apache.james.protocols.smtp.hook.MessageHook;
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.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
import com.google.common.collect.Lists;

package com.hubspot.smtp;





public class ChunkingExtension implements EhloExtension, CommandHandler<SMTPSession>, ExtensibleHandler, Hook {
  private static final String MAIL_ENVELOPE = "mail envelope";
  private static final String BDAT_HANDLER_NAME = "BDAT handler";
  private static final Pattern BDAT_COMMAND_PATTERN = Pattern.compile("(?<size>[0-9]+)(?<last> LAST)?");

  private static final Response DELIVERY_SYNTAX = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,
      DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX) + " Invalid syntax").immutable();

  private List<MessageHook> messageHandlers;

  @Override
  public Response onCommand(SMTPSession session, Request request) {
    Matcher matcher = BDAT_COMMAND_PATTERN.matcher(request.getArgument());
    if (!matcher.matches()) {
      return DELIVERY_SYNTAX;
    }

    Channel channel = (Channel) session.getAttachment(NETTY_CHANNEL, State.Connection);