Class SmtpResponseDecoder

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler

@UnstableApi public final class SmtpResponseDecoder extends LineBasedFrameDecoder
Decoder for SMTP responses.
  • Field Details

    • DEFAULT_MAX_RESPONSE_SIZE

      private static final int DEFAULT_MAX_RESPONSE_SIZE
      See Also:
    • DETAIL_ENTRY_OVERHEAD

      private static final int DETAIL_ENTRY_OVERHEAD
      See Also:
    • maxResponseSize

      private final int maxResponseSize
    • details

      private java.util.List<java.lang.CharSequence> details
    • responseSize

      private long responseSize
  • Constructor Details

    • SmtpResponseDecoder

      public SmtpResponseDecoder(int maxLineLength)
      Creates a new instance that enforces the given maxLineLength and a default limit of 64 KiB on the accumulated size of a multi-line response.
      Parameters:
      maxLineLength - the maximum length of a single response line, in bytes.
    • SmtpResponseDecoder

      public SmtpResponseDecoder(int maxLineLength, int maxResponseSize)
      Creates a new instance that enforces the given maxLineLength and maxResponseSize.

      The lines of a multi-line response are buffered until its terminating line arrives. maxResponseSize bounds that buffering. Once it is exceeded, decoding fails with a TooLongFrameException. The limit is approximate and tracks retained memory rather than bytes received, as it charges each buffered line a fixed object overhead in addition to its detail bytes, and ignores the response code, the separator and the terminating line.

      Parameters:
      maxLineLength - the maximum length of a single response line, in bytes.
      maxResponseSize - the maximum accumulated size of a multi-line response, in bytes.
  • Method Details

    • decode

      protected SmtpResponse decode(ChannelHandlerContext ctx, ByteBuf buffer) throws java.lang.Exception
      Description copied from class: LineBasedFrameDecoder
      Create a frame out of the ByteBuf and return it.
      Overrides:
      decode in class LineBasedFrameDecoder
      Parameters:
      ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs to
      buffer - the ByteBuf from which to read data
      Returns:
      frame the ByteBuf which represent the frame or null if no frame could be created.
      Throws:
      java.lang.Exception
    • reset

      private void reset()
    • newDecoderException

      private static DecoderException newDecoderException(ByteBuf buffer, int readerIndex, int readable)
    • parseCode

      private static int parseCode(ByteBuf buffer)
      Parses the io.netty.handler.codec.smtp code without any allocation, which is three digits.
      Returns:
      the code, or -1 if one of the three bytes is not a digit.
    • parseNumber

      private static int parseNumber(byte b)