Package javax.mail.internet
Class InternetHeaders
- java.lang.Object
-
- javax.mail.internet.InternetHeaders
-
public class InternetHeaders extends java.lang.ObjectA collection of RFC 822 headers.The string representation of RFC822 and MIME header fields must contain only US-ASCII characters. Non US-ASCII characters must be encoded as per the rules in RFC 2047. This class does not enforce those rules; the caller is expected to use
MimeUtilityto ensure that header values are correctly encoded.- Version:
- 1.4
- Author:
- Chris Burdess
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classInternetHeaders.InternetHeader
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ListheadersThe list of headers.
-
Constructor Summary
Constructors Constructor Description InternetHeaders()Constructor for an empty InternetHeaders.InternetHeaders(java.io.InputStream is)Constructor with an RFC 822 message stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(java.lang.String name, java.lang.String value)Adds the specified header.voidaddHeaderLine(java.lang.String line)Adds an RFC 822 header-line to this InternetHeaders.java.util.EnumerationgetAllHeaderLines()Returns all the header-lines.java.util.EnumerationgetAllHeaders()Returns all the headers.java.lang.String[]getHeader(java.lang.String name)Returns all the values for the specified header.java.lang.StringgetHeader(java.lang.String name, java.lang.String delimiter)Returns all the headers for this header name as a single string, with headers separated by the given delimiter.java.util.EnumerationgetMatchingHeaderLines(java.lang.String[] names)Returns all the header-lines with any of the given names.java.util.EnumerationgetMatchingHeaders(java.lang.String[] names)Returns all the headers with any of the given names.java.util.EnumerationgetNonMatchingHeaderLines(java.lang.String[] names)Returns all the header-lines without any of the given names.java.util.EnumerationgetNonMatchingHeaders(java.lang.String[] names)Returns all the headers without any of the given names.voidload(java.io.InputStream is)Parses the specified RFC 822 message stream, storing the headers in this InternetHeaders.voidremoveHeader(java.lang.String name)Removes all headers matching the given name.voidsetHeader(java.lang.String name, java.lang.String value)Sets the specified header.
-
-
-
Constructor Detail
-
InternetHeaders
public InternetHeaders()
Constructor for an empty InternetHeaders.
-
InternetHeaders
public InternetHeaders(java.io.InputStream is) throws MessagingExceptionConstructor with an RFC 822 message stream. The stream is parsed up to the blank line separating the headers from the body, and is left positioned at the start of the body.- Parameters:
is- an RFC 822 input stream- Throws:
MessagingException
-
-
Method Detail
-
load
public void load(java.io.InputStream is) throws MessagingExceptionParses the specified RFC 822 message stream, storing the headers in this InternetHeaders. The stream is parsed up to the blank line separating the headers from the body, and is left positioned at the start of the body. Note that the headers are added into this InternetHeaders object: any existing headers in this object are not affected.- Parameters:
is- an RFC 822 input stream- Throws:
MessagingException
-
getHeader
public java.lang.String[] getHeader(java.lang.String name)
Returns all the values for the specified header.- Parameters:
name- the header name
-
getHeader
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter)Returns all the headers for this header name as a single string, with headers separated by the given delimiter. If the delimiter isnull, only the first header is returned.- Parameters:
name- the header namedelimiter- the delimiter
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value)Sets the specified header. If existing header lines match the given name, they are all replaced by the specified value.- Parameters:
name- the header namevalue- the header value
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value)Adds the specified header.- Parameters:
name- the header namevalue- the header value
-
removeHeader
public void removeHeader(java.lang.String name)
Removes all headers matching the given name.- Parameters:
name- the header name
-
getAllHeaders
public java.util.Enumeration getAllHeaders()
Returns all the headers.- Returns:
- an Enumeration of Header objects
-
getMatchingHeaders
public java.util.Enumeration getMatchingHeaders(java.lang.String[] names)
Returns all the headers with any of the given names.- Parameters:
names- the names to match- Returns:
- an Enumeration of Header objects
-
getNonMatchingHeaders
public java.util.Enumeration getNonMatchingHeaders(java.lang.String[] names)
Returns all the headers without any of the given names.- Parameters:
names- the names not to match- Returns:
- an Enumeration of Header objects
-
addHeaderLine
public void addHeaderLine(java.lang.String line)
Adds an RFC 822 header-line to this InternetHeaders. If the line starts with a space or tab (a continuation line for a folded header), adds it to the last header line in the list.- Parameters:
line- the raw RFC 822 header-line
-
getAllHeaderLines
public java.util.Enumeration getAllHeaderLines()
Returns all the header-lines.- Returns:
- an Enumeration of Strings
-
getMatchingHeaderLines
public java.util.Enumeration getMatchingHeaderLines(java.lang.String[] names)
Returns all the header-lines with any of the given names.- Returns:
- an Enumeration of Strings
-
getNonMatchingHeaderLines
public java.util.Enumeration getNonMatchingHeaderLines(java.lang.String[] names)
Returns all the header-lines without any of the given names.- Returns:
- an Enumeration of Strings
-
-