java.lang.Object
i2p.susi.webmail.MailPart
Represents a part of a multipart email message with headers and content.
Field Summary
Modifier and TypeFieldDescriptionprivate final LogLogger for this class.private final intOffset in the message where the part starts.private final intOffsets into readBuffer.getOffset(): begin is before the headers, beginBody is after them, and end is exclusive.final BufferThe shared mailbox buffer this part was parsed from.final StringThe charset parameter of the Content-Type header, or null.final StringThe Content-ID used to reference this part from the HTML body.intThe decoded length if known, else -1.final StringThe Content-Description header, or null.final StringThe Content-Disposition header, or null when there is none.private static final OutputStreamSink discarding a part that has no destination.final StringContent-Transfer-Encoding of this part, never null.private final intOffset in the message where the part ends.final StringAlways null, reserved for future use.final String[]The raw header lines of this part, in the order they were received.private final intId used to address this part in the URL.final booleanTrue when this part is an embedded message.final booleanTrue when this part is a multipart container.final StringThe subtype of a multipart Content-Type, such as mixed or alternative.final StringThe name parameter of the Content-Disposition header, or null.The sub-parts, when this part is a multipart container.final StringEncoding non-null.final StringThe UIDL of the mail, same for all parts.final StringThe version parameter of the Content-Type header, or null.Constructor Summary
ConstructorsConstructorDescriptionMailPart(String uidl, AtomicInteger id, Buffer readBuffer, InputStream in, ReadCounter counter, String[] hdrlines) Probably the same as InputStream but a different interface.Method Summary
Modifier and TypeMethodDescriptionprivate static StringLooks up a localized string in the message bundle.(package private) static StringcharText(int c) Writes a character read from the stream in a form a reader can act on.voidSynched because FileBuffer keeps stream open.private static StringgetFirstAttribute(String line) Reads the first attribute value from a header line.private static StringgetHeaderLineAttribute(String line, String attributeName) Extract a quoted attribute value from a header line.intgetID()A value unique across all the parts of this Mail, and constant across restarts, so it may be part of a bookmark.private LimitInputStreamgetRawInputStream(int offset) Synched because FileBuffer keeps stream open Caller must call readComplete() on buffer.voidoutputRaw(OutputStream out) Synched because FileBuffer keeps stream open Caller must close out.private booleanSwallow "\r\n" or "--\r\n".toString()Renders the part metadata for debugging.
Field Details
DUMMY_OUTPUT
Sink discarding a part that has no destination.headerLines
The raw header lines of this part, in the order they were received.type
Encoding non-null.encoding
Content-Transfer-Encoding of this part, never null.name
The name parameter of the Content-Disposition header, or null.description
The Content-Description header, or null.disposition
The Content-Disposition header, or null when there is none.charset
The charset parameter of the Content-Type header, or null.version
The version parameter of the Content-Type header, or null.multipart_type
The subtype of a multipart Content-Type, such as mixed or alternative.cid
The Content-ID used to reference this part from the HTML body.beginBody
private final int beginBodyOffsets into readBuffer.getOffset(): begin is before the headers, beginBody is after them, and end is exclusive.begin
private final int beginOffset in the message where the part starts.end
private final int endOffset in the message where the part ends.filename
Always null, reserved for future use.parts
multipart
public final boolean multipartTrue when this part is a multipart container.message
public final boolean messageTrue when this part is an embedded message.buffer
The shared mailbox buffer this part was parsed from._log
Logger for this class.decodedLength
public int decodedLengthThe decoded length if known, else -1.uidl
The UIDL of the mail, same for all parts.intID
private final int intIDId used to address this part in the URL.
Constructor Details
MailPart
public MailPart(String uidl, AtomicInteger id, Buffer readBuffer, InputStream in, ReadCounter counter, String[] hdrlines) throws IOException Probably the same as InputStream but a different interface. were already parsed in Mail. Null otherwise.- Parameters:
uidl- the IMAP UID of the owning message, kept in the public uidl fieldid- a counter from which this part takes its next sequence numberreadBuffer- has zero offset for top-level MailPart.in- used for reading (NOT readBuffer.getInputStream())counter- used for counting how much we have read.hdrlines- non-null for top-level MailPart, where they- Throws:
IOException- if the header block cannot be read from in
Method Details
getID
public int getID()A value unique across all the parts of this Mail, and constant across restarts, so it may be part of a bookmark.- Returns:
- this part's sequence number within its message
readBoundaryTrailer
Swallow "\r\n" or "--\r\n". We don't have any pushback if this goes wrong.- Parameters:
in- the stream positioned just after the boundary line- Returns:
- true if end of input
- Throws:
IOException- if reading the stream fails
charText
Writes a character read from the stream in a form a reader can act on. Control characters and the end of the data would otherwise be logged as a bare number or as nothing at all.- Parameters:
c- the character read, or -1 for the end of the data- Returns:
- the bracketed description
decode
Synched because FileBuffer keeps stream open.- Parameters:
offset- 2 for sendAttachment, 0 otherwise, probably for \r\nout- the buffer the decoded body is written to- Throws:
IOException- if no decoder matches the encoding, or the stream cannot be read
outputRaw
Synched because FileBuffer keeps stream open Caller must close out.- Parameters:
out- where the raw undecoded bytes are copied- Throws:
IOException- if the raw stream cannot be read
getRawInputStream
Synched because FileBuffer keeps stream open Caller must call readComplete() on buffer.- Parameters:
offset- 2 for sendAttachment, 0 otherwise, probably for \r\n- Returns:
- the raw input stream
- Throws:
IOException- if the backing buffer's stream cannot be opened
getFirstAttribute
getHeaderLineAttribute
Extract a quoted attribute value from a header line.- Parameters:
line- the header line to search, e.g. a Content-Type or Content-Disposition lineattributeName- must be lower case, will be matched case-insensitively- Returns:
- as found, not necessarily lower case
_t
toString