Class MimeUtil


  • public final class MimeUtil
    extends Object
    A utility class, which provides some MIME related application logic.
    • Method Detail

      • isSameMimeType

        public static boolean isSameMimeType​(String pType1,
                                             String pType2)
        Returns, whether the given two MIME types are identical.
      • isMessage

        public static boolean isMessage​(String pMimeType)
        Returns true, if the given MIME type is that of a message.
      • isMultipart

        public static boolean isMultipart​(String pMimeType)
        Return true, if the given MIME type indicates a multipart entity.
      • isBase64Encoding

        public static boolean isBase64Encoding​(String pTransferEncoding)
        Returns, whether the given transfer-encoding is "base64".
      • isQuotedPrintableEncoded

        public static boolean isQuotedPrintableEncoded​(String pTransferEncoding)
        Returns, whether the given transfer-encoding is "quoted-printable".
      • createUniqueBoundary

        public static String createUniqueBoundary()
        Creates a new unique message boundary string that can be used as boundary parameter for the Content-Type header field of a message.
        Returns:
        a new unique message boundary string.
      • createUniqueMessageId

        public static String createUniqueMessageId​(String hostName)
        Creates a new unique message identifier that can be used in message header field such as Message-ID or In-Reply-To. If the given host name is not null it will be used as suffix for the message ID (following an at sign). The resulting string is enclosed in angle brackets (< and >);
        Parameters:
        hostName - host name to be included in the message ID or null if no host name should be included.
        Returns:
        a new unique message identifier.
      • formatDate

        public static String formatDate​(Date date,
                                        TimeZone zone)
        Formats the specified date into a RFC 822 date-time string.
        Parameters:
        date - date to be formatted into a string.
        zone - the time zone to use or null to use the default time zone.
        Returns:
        the formatted time string.
      • fold

        public static String fold​(String s,
                                  int usedCharacters)
        Splits the specified string into a multiple-line representation with lines no longer than 76 characters (because the line might contain encoded words; see RFC 2047 section 2). If the string contains non-whitespace sequences longer than 76 characters a line break is inserted at the whitespace character following the sequence resulting in a line longer than 76 characters.
        Parameters:
        s - string to split.
        usedCharacters - number of characters already used up. Usually the number of characters for header field name plus colon and one space.
        Returns:
        a multiple-line representation of the given string.
      • unfold

        public static String unfold​(String s)
        Unfold a multiple-line representation into a single line.
        Parameters:
        s - string to unfold.
        Returns:
        unfolded string.
      • unscrambleHeaderValue

        public static String unscrambleHeaderValue​(String headerValue)
        Unfold and decode header value