Class UuencodeDecoder

java.lang.Object
com.mimecast.robin.util.UuencodeDecoder

public final class UuencodeDecoder extends Object
Decoder for the classic Unix uuencode format.

Handles legacy attachments pasted as plain text, starting with a begin MODE FILENAME line and ending with an end line - predating MIME multipart attachments, but still occasionally seen, and sometimes used deliberately to slip content past scanners that no longer recognise the format.

  • Field Details

    • BEGIN_LINE

      private static final Pattern BEGIN_LINE
  • Constructor Details

    • UuencodeDecoder

      private UuencodeDecoder()
  • Method Details

    • looksLikeUuencode

      public static boolean looksLikeUuencode(byte[] content)
      Checks whether the given content starts with a uuencode "begin" preamble.
      Parameters:
      content - Raw content bytes.
      Returns:
      true if the content looks like uuencoded data.
    • decode

      public static Optional<UuencodeDecoder.Result> decode(byte[] content)
      Decodes uuencoded content.
      Parameters:
      content - Raw content bytes, expected to contain a uuencode "begin" preamble.
      Returns:
      Decoded result, or empty if the content isn't valid uuencode.
    • decodeLine

      private static void decodeLine(String line, ByteArrayOutputStream out)
      Decodes a single uuencoded line (a length character followed by groups of 4 encoded characters, each group representing up to 3 decoded bytes) and appends its declared number of bytes to the output.
      Parameters:
      line - Trimmed uuencode data line.
      out - Output buffer to append decoded bytes to.
    • stripTrailingWhitespace

      private static String stripTrailingWhitespace(String line)