java.lang.Object
i2p.susi.webmail.encoding.Encoding
i2p.susi.webmail.encoding.HeaderLine
References for the RFC 2047 encoded-word rules this class implements.
- http://en.wikipedia.org/wiki/MIME#Encoded-Word
- http://tools.ietf.org/html/rfc2047
- https://jeffreystedfast.blogspot.com/2013/09/time-for-rant-on-mime-parsers.html
- https://jeffreystedfast.blogspot.com/2013/08/why-decoding-rfc2047-encoded-headers-is.html
Field Summary
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoiddecode(InputStream in, Buffer bout) Decode all the header lines, up through \r\n\r\n, and puts them in the ReadBuffer, including the \r\n\r\n.encode(byte[] in) This will split multibyte chars across lines, see 4th ref above.Encode a single header line ONLY.getName()The header's name.private static booleanisControlOrMultiByte(char c) Whether the char is a control or non-ASCII character.private static booleanisPSafe(char c) Whether the char is safe unencoded in an encoded-word.private static booleanisPSpecial(char c) Whether the char is an RFC 2047 special.private static booleanisWhiteSpace(char c) Whether the char is header whitespace.(package private) static StringmalformedText(String situation, String action) Describes a malformed encoded-word: what was wrong with it and what the decoder did about it.Methods inherited from class Encoding
decode, decode, decode, decode, decode, encodeModifier and TypeMethodDescriptiondecode(byte[] in) Decode a byte array using default offset and length.decode(byte[] in, int offset, int length) Decode a portion of a byte array.Decode a buffer into another buffer.voidDecode a buffer into another buffer using the input stream.Decode a string.voidencode(InputStream in, Writer out) Encode an input stream of bytes to a ASCII or ISO-8859-1 String.
Field Details
NAME
Identifier this encoding is registered under, returned bygetName().- See Also:
DECODE_MAX
private static final int DECODE_MAXLargest encoded-word the decoder accepts. It could be 75 for quoted-printable only, but base64 words are longer.- See Also:
Constructor Details
HeaderLine
public HeaderLine()Constructor. A header line is decoded from the raw header text handed to each call, so a bare instance is ready to use.
Method Details
getName
encode
This will split multibyte chars across lines, see 4th ref above.- Specified by:
encodein classEncoding- Parameters:
in- the byte array to encode- Returns:
- the encoded string, SMTP-safe
- Throws:
UnsupportedOperationException- always, since this byte[] overload is not implemented; use encode(String)EncodingException- if encoding fails
isWhiteSpace
private static boolean isWhiteSpace(char c) Whether the char is header whitespace.- Parameters:
c- the character to test- Returns:
- true for space and tab only
isControlOrMultiByte
private static boolean isControlOrMultiByte(char c) Whether the char is a control or non-ASCII character.- Parameters:
c- the character to test- Returns:
- true for control characters below 32 except space and tab, and for characters 127 and above
isPSpecial
private static boolean isPSpecial(char c) Whether the char is an RFC 2047 special.- Parameters:
c- the character to test- Returns:
- true for one of ! * + - / = _
isPSafe
private static boolean isPSafe(char c) Whether the char is safe unencoded in an encoded-word.- Parameters:
c- the character to test- Returns:
- true for letters, digits and the RFC 2047 specials
encode
Encode a single header line ONLY. Do NOT include the \r\n. Returns a string of one or more lines including the trailing \r\n. Field-name will not be encoded, must be less than 62 chars. The fieldBody is treated as "unstructured text", which is suitable only for the field names "Subject" and "Comments". We do NOT tokenize into structured fields. To make things easy, we either encode the whole field body as RFC 2047, or don't encode at all. If it's too long for a single line, we encode it, even if we didn't otherwise have to. We don't do quoted-string. This will not split multibyte chars, including supplementary chars, across lines.- Overrides:
encodein classEncoding- Parameters:
str- must start with "field-name: ", must have non-whitespace after that- Returns:
- the encoded string, SMTP-safe
- Throws:
EncodingException- if encoding fails- See Also:
malformedText
Describes a malformed encoded-word: what was wrong with it and what the decoder did about it. The header text is not quoted back, since it is what the reader is trying to fix, and a hex dump of the bytes would run to many lines for a per-header message.- Parameters:
situation- what was wrong with the encoded-wordaction- what the decoder did about it- Returns:
- the log message
decode
Decode all the header lines, up through \r\n\r\n, and puts them in the ReadBuffer, including the \r\n\r\n.- Specified by:
decodein classEncoding- Parameters:
in- the input stream to read data frombout- the buffer to write decoded data to- Throws:
IOException- if reading from input stream fails- See Also: