Class ImapLine

java.lang.Object
net.messagevortex.transport.imap.ImapLine

public class ImapLine extends Object

A Imap conformant parser/scanner.

Author:
Martin Gwerder
  • Constructor Details

    • ImapLine

      public ImapLine(ImapConnection con, String line, InputStream input) throws ImapException

      Creates an imap line object with a parser for a command.

      A passed input stream is appended to line. Reading takes place according to the ABNF-Rules defined in the respective RFC.

      Parameters:
      con - The ImapConnection object which generated the Command line
      line - The String which has already been read (as Read ahead)
      input - The Stream offering more data to read if required
      Throws:
      ImapException - if reading fails
      NullPointerException - if connection and line are null
    • ImapLine

      public ImapLine(ImapConnection con, String line) throws ImapException

      Trivial constructor omiting a stream.

      This constructor is mainly meant for testing purposes

      Parameters:
      con - The ImapConnection object which generated the Command line
      line - The String which has already been read (as Read ahead)
      Throws:
      ImapException - if reading fails
      NullPointerException - if connection and line are null
  • Method Details

    • charlistBuilder

      public static String charlistBuilder(int start, int end)

      Builds a set of chracters ranging from the ASCII code of start until the ASCII code of end.

      This helper is mainly used to build ABNF strings.

      Parameters:
      start - The first ASCII code to be used
      end - The last ASCII code to be used
      Returns:
      the generated character list
    • charlistDifferencer

      public static String charlistDifferencer(String superset, String subset)

      Removes a given set of characters from a superset.

      Parameters:
      superset - the set where character should be removed from
      subset - the set of characters to be removed
      Returns:
      the difference of the two given charsets
    • commandEncoder

      public static String commandEncoder(String command)

      Encodes a command so that newlines are visible.

      Parameters:
      command - the command to be encoded for output on screen
      Returns:
      a printable string representation
    • getNextTag

      public static String getNextTag()

      Get a unique identifier as a tag.

      Returns:
      A unique tag ("A" prefixed)
    • getNextTag

      public static String getNextTag(String prefix)

      Get a unique identifier as a tag.

      Parameters:
      prefix - the prefix prepended to the tag
      Returns:
      A unique tag
    • getConnection

      public ImapConnection getConnection()

      Getter for the Imap connection in Control of this command.

      Returns:
      ImapConnection storing the context of this command
    • getCommand

      public String getCommand()

      Getter for the command.

      Returns:
      command token
    • getTag

      public String getTag()

      Getter for the command tag.

      Returns:
      command tag
    • snoopEscQuotes

      public boolean snoopEscQuotes()

      Returns true if escaped quotes are present at the current position.

      Returns:
      true if escaped quotes are present
    • snoopBytes

      public String snoopBytes(long num)

      Get the specified number of characters without moving from the current position.

      if num is 0 or negative then null is returned. If the number of available bytes is lower than the number of requested characters then the buffer content is returned.

      Parameters:
      num - the number of bytes to be snooped
      Returns:
      the requested string
    • getContext

      public String getContext()

      Returns the current buffer (including position) and some of the already read characters.

      Returns:
      String representation of the current context
    • skipBytes

      public String skipBytes(long num)

      Skips the specified number of characters and adds them to the past context.

      Parameters:
      num - number of characters to be skipped
      Returns:
      String representation of the skipped characters
    • skipBytes

      public String skipBytes(long num, boolean modContext)

      Skips the specified number of bytes.

      Parameters:
      num - the number of bytes to be skipped
      modContext - if true the context is updated by the operation
      Returns:
      the skipped bytes
    • skipWhitespace

      public final int skipWhitespace(int num)

      Skips the specified number of SPACES.

      Parameters:
      num - number of spaces to be skipped
      Returns:
      number of skipped spaces
    • skipLineEnd

      public boolean skipLineEnd()

      Skips a CRLF combo in the buffer.

      Returns:
      True if a combo has been skipped
    • skipUntilLineEnd

      public boolean skipUntilLineEnd()

      Skips up to a CRLF combo in the buffer.

      Returns:
      True if a combo has been skipped (false if buffer ended before a CRLF combo was read
    • getString

      public String getString()

      Get an IMAP String from the buffer (quoted or prefixed).

      Returns:
      The String or null if no string is at the current position
    • getAString

      public String getAString()

      Get an IMAP AString (direct, quoted or prefixed) from the current buffer position.

      Returns:
      The String or null if no string at the current position
    • getATag

      public String getATag()

      Get the tag at the current position.

      Returns:
      the tag or null if no valid is found