Package org.apache.james.mime4j.util
Class MimeUtil
- java.lang.Object
-
- org.apache.james.mime4j.util.MimeUtil
-
public final class MimeUtil extends java.lang.ObjectA utility class, which provides some MIME related application logic.
-
-
Field Summary
Fields Modifier and Type Field Description private static intcounterstatic java.lang.StringENC_7BITThe7bitencoding.static java.lang.StringENC_8BITThe8bitencoding.static java.lang.StringENC_BASE64Thebase64encoding.static java.lang.StringENC_BINARYThebinaryencoding.static java.lang.StringENC_QUOTED_PRINTABLEThequoted-printableencoding.private static intINITIAL_YEARprivate static java.util.Randomrandomstatic java.time.format.DateTimeFormatterRFC822_DATE_FORMAT
-
Constructor Summary
Constructors Modifier Constructor Description privateMimeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringcreateUniqueBoundary()Creates a new unique message boundary string that can be used as boundary parameter for the Content-Type header field of a message.static java.lang.StringcreateUniqueMessageId(java.lang.String hostName)Creates a new unique message identifier that can be used in message header field such as Message-ID or In-Reply-To.private static java.util.Map<java.lang.Long,java.lang.String>dayOfWeek()static java.lang.Stringfold(java.lang.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).static java.lang.StringformatDate(java.util.Date date, java.util.TimeZone zone)Formats the specified date into a RFC 822 date-time string.private static intindexOfWsp(java.lang.String s, int fromIndex)static booleanisBase64Encoding(java.lang.String pTransferEncoding)Returns, whether the given transfer-encoding is "base64".static booleanisMessage(java.lang.String pMimeType)Returns true, if the given MIME type is that of a message.static booleanisMultipart(java.lang.String pMimeType)Return true, if the given MIME type indicates a multipart entity.static booleanisQuotedPrintableEncoded(java.lang.String pTransferEncoding)Returns, whether the given transfer-encoding is "quoted-printable".static booleanisSameMimeType(java.lang.String pType1, java.lang.String pType2)Returns, whether the given two MIME types are identical.private static java.util.Map<java.lang.Long,java.lang.String>monthOfYear()private static intnextCounterValue()static java.lang.Stringunfold(java.lang.String s)Unfold a multiple-line representation into a single line.private static java.lang.Stringunfold0(java.lang.String s, int crlfIdx)static java.lang.StringunscrambleHeaderValue(java.lang.String headerValue)Unfold and decode header valueprivate static java.time.ZoneIdzone(java.util.TimeZone zone)
-
-
-
Field Detail
-
ENC_QUOTED_PRINTABLE
public static final java.lang.String ENC_QUOTED_PRINTABLE
Thequoted-printableencoding.- See Also:
- Constant Field Values
-
ENC_BINARY
public static final java.lang.String ENC_BINARY
Thebinaryencoding.- See Also:
- Constant Field Values
-
ENC_BASE64
public static final java.lang.String ENC_BASE64
Thebase64encoding.- See Also:
- Constant Field Values
-
ENC_8BIT
public static final java.lang.String ENC_8BIT
The8bitencoding.- See Also:
- Constant Field Values
-
ENC_7BIT
public static final java.lang.String ENC_7BIT
The7bitencoding.- See Also:
- Constant Field Values
-
random
private static final java.util.Random random
-
counter
private static int counter
-
INITIAL_YEAR
private static final int INITIAL_YEAR
- See Also:
- Constant Field Values
-
RFC822_DATE_FORMAT
public static final java.time.format.DateTimeFormatter RFC822_DATE_FORMAT
-
-
Method Detail
-
isSameMimeType
public static boolean isSameMimeType(java.lang.String pType1, java.lang.String pType2)Returns, whether the given two MIME types are identical.
-
isMessage
public static boolean isMessage(java.lang.String pMimeType)
Returns true, if the given MIME type is that of a message.
-
isMultipart
public static boolean isMultipart(java.lang.String pMimeType)
Return true, if the given MIME type indicates a multipart entity.
-
isBase64Encoding
public static boolean isBase64Encoding(java.lang.String pTransferEncoding)
Returns, whether the given transfer-encoding is "base64".
-
isQuotedPrintableEncoded
public static boolean isQuotedPrintableEncoded(java.lang.String pTransferEncoding)
Returns, whether the given transfer-encoding is "quoted-printable".
-
createUniqueBoundary
public static java.lang.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 java.lang.String createUniqueMessageId(java.lang.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 notnullit 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 ornullif no host name should be included.- Returns:
- a new unique message identifier.
-
formatDate
public static java.lang.String formatDate(java.util.Date date, java.util.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 ornullto use the default time zone.- Returns:
- the formatted time string.
-
zone
private static java.time.ZoneId zone(java.util.TimeZone zone)
-
fold
public static java.lang.String fold(java.lang.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 java.lang.String unfold(java.lang.String s)
Unfold a multiple-line representation into a single line.- Parameters:
s- string to unfold.- Returns:
- unfolded string.
-
unscrambleHeaderValue
public static java.lang.String unscrambleHeaderValue(java.lang.String headerValue)
Unfold and decode header value
-
unfold0
private static java.lang.String unfold0(java.lang.String s, int crlfIdx)
-
indexOfWsp
private static int indexOfWsp(java.lang.String s, int fromIndex)
-
nextCounterValue
private static int nextCounterValue()
-
monthOfYear
private static java.util.Map<java.lang.Long,java.lang.String> monthOfYear()
-
dayOfWeek
private static java.util.Map<java.lang.Long,java.lang.String> dayOfWeek()
-
-