Class InternetHeaders
Header
objects.
This class is mostly intended for service providers. MimeMessage and MimeBody use this class for holding their headers.
A note on RFC822 and MIME headers
RFC822 and MIME header fields must contain only
US-ASCII characters. If a header contains non US-ASCII characters,
it must be encoded as per the rules in RFC 2047. The MimeUtility
class provided in this package can be used to to achieve this.
Callers of the setHeader
, addHeader
, and
addHeaderLine
methods are responsible for enforcing
the MIME requirements for the specified headers. In addition, these
header fields must be folded (wrapped) before being sent if they
exceed the line length limitation for the transport (1000 bytes for
SMTP). Received headers may have been folded. The application is
responsible for folding and unfolding headers as appropriate.
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate an empty InternetHeaders object.Read and parse the given RFC822 message stream till the blank line separating the header from the body. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a header with the specified name and value to the header list.void
addHeaderLine
(String line) Add an RFC822 header line to the header store.Return all the header lines as a collectionReturn all the headers as an Enumeration ofHeader
objects.String[]
Return all the values for the specified header.Get all the headers for this header name, returned as a single String, with headers separated by the delimiter.void
load
(InputStream is) Read and parse the given RFC822 message stream till the blank line separating the header from the body.void
removeHeader
(String name) Remove all header entries that match the given namevoid
Change the first header line that matches name to have value, adding a new header if no existing header matches.
-
Constructor Details
-
InternetHeaders
public InternetHeaders()Create an empty InternetHeaders object. -
InternetHeaders
Read and parse the given RFC822 message stream till the blank line separating the header from the body. The input stream is left positioned at the start of the body. The header lines are stored internally.For efficiency, wrap a BufferedInputStream around the actual input stream and pass it as the parameter.
- Parameters:
is
- RFC822 input stream- Throws:
MessagingException
- in case of error
-
-
Method Details
-
load
Read and parse the given RFC822 message stream till the blank line separating the header from the body. Store the header lines inside this InternetHeaders object.Note that the header lines are added into this InternetHeaders object, so any existing headers in this object will not be affected.
- Parameters:
is
- RFC822 input stream- Throws:
MessagingException
- in case of error
-
getHeader
Return all the values for the specified header. The values are String objects. Returnsnull
if no headers with the specified name exist.- Parameters:
name
- header name- Returns:
- array of header values, or null if none
-
getHeader
Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. If the delimiter isnull
, only the first header is returned. Returnsnull
if no headers with the specified name exist.- Parameters:
name
- header namedelimiter
- delimiter- Returns:
- the value fields for all headers with this name, or null if none
-
setHeader
Change the first header line that matches name to have value, adding a new header if no existing header matches. Remove all matching headers but the first.Note that RFC822 headers can only contain US-ASCII characters.
- Parameters:
name
- header namevalue
- header value
-
addHeader
Add a header with the specified name and value to the header list. Note that RFC822 headers can only contain US-ASCII characters.- Parameters:
name
- header namevalue
- header value
-
removeHeader
Remove all header entries that match the given name- Parameters:
name
- header name
-
getAllHeaders
Return all the headers as an Enumeration ofHeader
objects.- Returns:
- Header objects
-
addHeaderLine
Add an RFC822 header line to the header store. If the line starts with a space or tab (a continuation line), add it to the last header line in the list.Note that RFC822 headers can only contain US-ASCII characters
- Parameters:
line
- raw RFC822 header line
-
getAllHeaderLines
Return all the header lines as a collection- Returns:
- list of header lines.
-