Class DecoderUtil

java.lang.Object
org.apache.james.mime4j.codec.DecoderUtil

public class DecoderUtil extends Object
Static methods for decoding strings, byte arrays and encoded words.
  • Field Details

  • Constructor Details

    • DecoderUtil

      public DecoderUtil()
  • Method Details

    • getBufferRecycler

      public static BufferRecycler getBufferRecycler()
    • decodeQuotedPrintable

      private static byte[] decodeQuotedPrintable(String s, DecodeMonitor monitor)
      Decodes a string containing quoted-printable encoded data.
      Parameters:
      s - the string to decode.
      Returns:
      the decoded bytes.
    • decodeBase64

      private static byte[] decodeBase64(String s, DecodeMonitor monitor)
      Decodes a string containing base64 encoded data.
      Parameters:
      s - the string to decode.
      monitor -
      Returns:
      the decoded bytes.
    • decodeB

      static String decodeB(String encodedText, String charset, DecodeMonitor monitor) throws UnsupportedEncodingException
      Decodes an encoded text encoded with the 'B' encoding (described in RFC 2047) found in a header field body.
      Parameters:
      encodedText - the encoded text to decode.
      charset - the Java charset to use.
      monitor -
      Returns:
      the decoded string.
      Throws:
      UnsupportedEncodingException - if the given Java charset isn't supported.
    • decodeQ

      static String decodeQ(String encodedText, String charset, DecodeMonitor monitor) throws UnsupportedEncodingException
      Decodes an encoded text encoded with the 'Q' encoding (described in RFC 2047) found in a header field body.
      Parameters:
      encodedText - the encoded text to decode.
      charset - the Java charset to use.
      Returns:
      the decoded string.
      Throws:
      UnsupportedEncodingException - if the given Java charset isn't supported.
    • decodeEncodedWords

      static String decodeEncodedWords(String body)
    • decodeEncodedWords

      public static String decodeEncodedWords(String body, DecodeMonitor monitor) throws IllegalArgumentException
      Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64.
      Parameters:
      body - the string to decode
      monitor - the DecodeMonitor to be used.
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
    • decodeEncodedWords

      public static String decodeEncodedWords(String body, Charset fallback) throws IllegalArgumentException
      Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid.
      Parameters:
      body - the string to decode
      fallback - the fallback Charset to be used.
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
    • decodeEncodedWords

      public static String decodeEncodedWords(String body, DecodeMonitor monitor, Charset fallback) throws IllegalArgumentException
      Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid.
      Parameters:
      body - the string to decode
      monitor - the DecodeMonitor to be used.
      fallback - the fallback Charset to be used.
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
    • decodeEncodedWords

      public static String decodeEncodedWords(String body, DecodeMonitor monitor, Charset fallback, Map<Charset,Charset> charsetOverrides) throws IllegalArgumentException
      Decodes a string containing encoded words as defined by RFC 2047. Encoded words have the form =?charset?enc?encoded-text?= where enc is either 'Q' or 'q' for quoted-printable and 'B' or 'b' for base64. Using fallback charset if charset in encoded words is invalid. Additionally, the found charset will be overridden if a corresponding mapping is found.
      Parameters:
      body - the string to decode
      monitor - the DecodeMonitor to be used.
      fallback - the fallback Charset to be used.
      charsetOverrides - the Charsets to override and their replacements. Must not be null.
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - only if the DecodeMonitor strategy throws it (Strict parsing)
    • tryDecodeEncodedWord

      private static String tryDecodeEncodedWord(String mimeCharset, String encoding, String encodedText, DecodeMonitor monitor, Charset fallback, Map<Charset,Charset> charsetOverrides)
    • lookupCharset

      private static Charset lookupCharset(String mimeCharset, Charset fallback, Map<Charset,Charset> charsetOverrides)
    • monitor

      private static void monitor(DecodeMonitor monitor, String mimeCharset, String encoding, String encodedText, String dropDesc, String... strings) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • recombine

      private static String recombine(String mimeCharset, String encoding, String encodedText)
    • replaceUnderscores

      private static String replaceUnderscores(String str)