Methods Summary |
---|
public void | addHeader(java.lang.String name, java.lang.String value)Add this value to the existing values for this header_name.
Throws IllegalWriteException because POP3 messages are read-only.
// XXX - should check for read-only folder?
throw new IllegalWriteException("POP3 messages are read-only");
|
public void | addHeaderLine(java.lang.String line)Add a raw RFC822 header-line.
Throws IllegalWriteException because POP3 messages are read-only.
// XXX - should check for read-only folder?
throw new IllegalWriteException("POP3 messages are read-only");
|
public java.util.Enumeration | getAllHeaderLines()Get all header lines as an Enumeration of Strings. A Header
line is a raw RFC822 header-line, containing both the "name"
and "value" field.
if (headers == null)
loadHeaders();
return headers.getAllHeaderLines();
|
public java.util.Enumeration | getAllHeaders()Return all the headers from this Message as an enumeration
of Header objects.
Note that certain headers may be encoded as per RFC 2047
if they contain non US-ASCII characters and these should
be decoded.
if (headers == null)
loadHeaders();
return headers.getAllHeaders();
|
protected java.io.InputStream | getContentStream()Produce the raw bytes of the content. The data is fetched using
the POP3 RETR command.
try {
synchronized(this) {
if (contentStream == null) {
InputStream rawcontent = folder.getProtocol().retr(msgnum,
msgSize > 0 ? msgSize + hdrSize : 0);
if (rawcontent == null) {
expunged = true;
throw new MessageRemovedException(); // XXX - what else?
}
if (headers == null ||
((POP3Store)(folder.getStore())).forgetTopHeaders) {
headers = new InternetHeaders(rawcontent);
hdrSize =
(int)((SharedInputStream)rawcontent).getPosition();
} else {
/*
* Already have the headers, have to skip the headers
* in the content array and return the body.
*
* XXX - It seems that some mail servers return slightly
* different headers in the RETR results than were returned
* in the TOP results, so we can't depend on remembering
* the size of the headers from the TOP command and just
* skipping that many bytes. Instead, we have to process
* the content, skipping over the header until we come to
* the empty line that separates the header from the body.
*/
int offset = 0;
for (;;) {
int len = 0; // number of bytes in this line
int c1;
while ((c1 = rawcontent.read()) >= 0) {
if (c1 == '\n") // end of line
break;
else if (c1 == '\r") {
// got CR, is the next char LF?
if (rawcontent.available() > 0) {
rawcontent.mark(1);
if (rawcontent.read() != '\n")
rawcontent.reset();
}
break; // in any case, end of line
}
// not CR, NL, or CRLF, count the byte
len++;
}
// here when end of line or out of data
// if out of data, we're done
if (rawcontent.available() == 0)
break;
// if it was an empty line, we're done
if (len == 0)
break;
}
hdrSize =
(int)((SharedInputStream)rawcontent).getPosition();
}
contentStream =
((SharedInputStream)rawcontent).newStream(hdrSize, -1);
rawcontent = null; // help GC
}
}
} catch (EOFException eex) {
folder.close(false);
throw new FolderClosedException(folder, eex.toString());
} catch (IOException ex) {
throw new MessagingException("error fetching POP3 content", ex);
}
return super.getContentStream();
|
public java.lang.String[] | getHeader(java.lang.String name)Get all the headers for this header_name. Note that certain
headers may be encoded as per RFC 2047 if they contain
non US-ASCII characters and these should be decoded.
if (headers == null)
loadHeaders();
return headers.getHeader(name);
|
public java.lang.String | getHeader(java.lang.String name, java.lang.String delimiter)Get all the headers for this header name, returned as a single
String, with headers separated by the delimiter. If the
delimiter is null , only the first header is
returned.
if (headers == null)
loadHeaders();
return headers.getHeader(name, delimiter);
|
public java.util.Enumeration | getMatchingHeaderLines(java.lang.String[] names)Get matching header lines as an Enumeration of Strings.
A Header line is a raw RFC822 header-line, containing both
the "name" and "value" field.
if (headers == null)
loadHeaders();
return headers.getMatchingHeaderLines(names);
|
public java.util.Enumeration | getMatchingHeaders(java.lang.String[] names)Return matching headers from this Message as an Enumeration of
Header objects.
if (headers == null)
loadHeaders();
return headers.getMatchingHeaders(names);
|
public java.util.Enumeration | getNonMatchingHeaderLines(java.lang.String[] names)Get non-matching header lines as an Enumeration of Strings.
A Header line is a raw RFC822 header-line, containing both
the "name" and "value" field.
if (headers == null)
loadHeaders();
return headers.getNonMatchingHeaderLines(names);
|
public java.util.Enumeration | getNonMatchingHeaders(java.lang.String[] names)Return non-matching headers from this Message as an
Enumeration of Header objects.
if (headers == null)
loadHeaders();
return headers.getNonMatchingHeaders(names);
|
public int | getSize()Return the size of the content of this message in bytes.
Returns -1 if the size cannot be determined.
Note that this number may not be an exact measure of the
content size and may or may not account for any transfer
encoding of the content.
try {
synchronized (this) {
if (msgSize >= 0)
return msgSize;
if (msgSize < 0) {
/*
* Use LIST to determine the entire message
* size and subtract out the header size
* (which may involve loading the headers,
* which may load the content as a side effect).
* If the content is loaded as a side effect of
* loading the headers, get the size directly.
*/
if (headers == null)
loadHeaders();
if (contentStream != null)
msgSize = contentStream.available();
else
msgSize = folder.getProtocol().list(msgnum) - hdrSize;
}
return msgSize;
}
} catch (EOFException eex) {
folder.close(false);
throw new FolderClosedException(folder, eex.toString());
} catch (IOException ex) {
throw new MessagingException("error getting size", ex);
}
|
public synchronized void | invalidate(boolean invalidateHeaders)Invalidate the cache of content for this message object, causing
it to be fetched again from the server the next time it is needed.
If invalidateHeaders is true, invalidate the headers
as well.
content = null;
contentStream = null;
msgSize = -1;
if (invalidateHeaders) {
headers = null;
hdrSize = -1;
}
|
private void | loadHeaders()Load the headers for this message into the InternetHeaders object.
The headers are fetched using the POP3 TOP command.
try {
synchronized (this) {
if (headers != null) // check again under lock
return;
InputStream hdrs = null;
if (((POP3Store)(folder.getStore())).disableTop ||
(hdrs = folder.getProtocol().top(msgnum, 0)) == null) {
// possibly because the TOP command isn't supported,
// load headers as a side effect of loading the entire
// content.
InputStream cs = getContentStream();
cs.close();
} else {
hdrSize = hdrs.available();
headers = new InternetHeaders(hdrs);
}
}
} catch (EOFException eex) {
folder.close(false);
throw new FolderClosedException(folder, eex.toString());
} catch (IOException ex) {
throw new MessagingException("error loading POP3 headers", ex);
}
|
public void | removeHeader(java.lang.String name)Remove all headers with this name.
Throws IllegalWriteException because POP3 messages are read-only.
// XXX - should check for read-only folder?
throw new IllegalWriteException("POP3 messages are read-only");
|
public void | saveChanges()POP3 message can't be changed. This method throws
IllegalWriteException.
// POP3 Messages are read-only
throw new IllegalWriteException("POP3 messages are read-only");
|
public void | setFlags(javax.mail.Flags newFlags, boolean set)Set the specified flags on this message to the specified value.
Flags oldFlags = (Flags)flags.clone();
super.setFlags(newFlags, set);
if (!flags.equals(oldFlags))
folder.notifyMessageChangedListeners(
MessageChangedEvent.FLAGS_CHANGED, this);
|
public void | setHeader(java.lang.String name, java.lang.String value)Set the value for this header_name. Throws IllegalWriteException
because POP3 messages are read-only.
// XXX - should check for read-only folder?
throw new IllegalWriteException("POP3 messages are read-only");
|
public java.io.InputStream | top(int n)Fetch the header of the message and the first n lines
of the raw content of the message. The headers and data are
available in the returned InputStream.
try {
synchronized (this) {
return folder.getProtocol().top(msgnum, n);
}
} catch (EOFException eex) {
folder.close(false);
throw new FolderClosedException(folder, eex.toString());
} catch (IOException ex) {
throw new MessagingException("error getting size", ex);
}
|