java.lang.Object
i2p.susi.webmail.MailPart

class MailPartextends Object
Represents a part of a multipart email message with headers and content.
  • Field Summary

    Modifier and Type
    Field
    Description
    private final Log
    Logger for this class.
    private final int
    Offset in the message where the part starts.
    private final int
    Offsets into readBuffer.getOffset(): begin is before the headers, beginBody is after them, and end is exclusive.
    final Buffer
    The shared mailbox buffer this part was parsed from.
    final String
    The charset parameter of the Content-Type header, or null.
    final String
    The Content-ID used to reference this part from the HTML body.
    int
    The decoded length if known, else -1.
    final String
    The Content-Description header, or null.
    final String
    The Content-Disposition header, or null when there is none.
    private static final OutputStream
    Sink discarding a part that has no destination.
    final String
    Content-Transfer-Encoding of this part, never null.
    private final int
    Offset in the message where the part ends.
    final String
    Always null, reserved for future use.
    final String[]
    The raw header lines of this part, in the order they were received.
    private final int
    Id used to address this part in the URL.
    final boolean
    True when this part is an embedded message.
    final boolean
    True when this part is a multipart container.
    final String
    The subtype of a multipart Content-Type, such as mixed or alternative.
    final String
    The name parameter of the Content-Disposition header, or null.
    final List<MailPart>
    The sub-parts, when this part is a multipart container.
    final String
    Encoding non-null.
    final String
    The UIDL of the mail, same for all parts.
    final String
    The version parameter of the Content-Type header, or null.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MailPart(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 Type
    Method
    Description
    private static String
    _t(String s, Object o)
    Looks up a localized string in the message bundle.
    (package private) static String
    charText(int c)
    Writes a character read from the stream in a form a reader can act on.
    void
    decode(int offset, Buffer out)
    Synched because FileBuffer keeps stream open.
    private static String
    Reads the first attribute value from a header line.
    private static String
    getHeaderLineAttribute(String line, String attributeName)
    Extract a quoted attribute value from a header line.
    int
    A value unique across all the parts of this Mail, and constant across restarts, so it may be part of a bookmark.
    getRawInputStream(int offset)
    Synched because FileBuffer keeps stream open Caller must call readComplete() on buffer.
    void
    Synched because FileBuffer keeps stream open Caller must close out.
    private boolean
    Swallow "\r\n" or "--\r\n".
    Renders the part metadata for debugging.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DUMMY_OUTPUT

      private static final OutputStream DUMMY_OUTPUT
      Sink discarding a part that has no destination.
    • headerLines

      public final String[] headerLines
      The raw header lines of this part, in the order they were received.
    • type

      public final String type
      Encoding non-null.
    • encoding

      public final String encoding
      Content-Transfer-Encoding of this part, never null.
    • name

      public final String name
      The name parameter of the Content-Disposition header, or null.
    • description

      public final String description
      The Content-Description header, or null.
    • disposition

      public final String disposition
      The Content-Disposition header, or null when there is none.
    • charset

      public final String charset
      The charset parameter of the Content-Type header, or null.
    • version

      public final String version
      The version parameter of the Content-Type header, or null.
    • multipart_type

      public final String multipart_type
      The subtype of a multipart Content-Type, such as mixed or alternative.
    • cid

      public final String cid
      The Content-ID used to reference this part from the HTML body.
    • beginBody

      private final int beginBody
      Offsets into readBuffer.getOffset(): begin is before the headers, beginBody is after them, and end is exclusive.
    • begin

      private final int begin
      Offset in the message where the part starts.
    • end

      private final int end
      Offset in the message where the part ends.
    • filename

      public final String filename
      Always null, reserved for future use.
    • parts

      public final List<MailPart> parts
      The sub-parts, when this part is a multipart container.
    • multipart

      public final boolean multipart
      True when this part is a multipart container.
    • message

      public final boolean message
      True when this part is an embedded message.
    • buffer

      public final Buffer buffer
      The shared mailbox buffer this part was parsed from.
    • _log

      private final Log _log
      Logger for this class.
    • decodedLength

      public int decodedLength
      The decoded length if known, else -1.
    • uidl

      public final String uidl
      The UIDL of the mail, same for all parts.
    • intID

      private final int intID
      Id 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 field
      id - a counter from which this part takes its next sequence number
      readBuffer - 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

      private boolean readBoundaryTrailer(InputStream in) throws IOException
      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

      static String charText(int c)
      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

      public void decode(int offset, Buffer out) throws IOException
      Synched because FileBuffer keeps stream open.
      Parameters:
      offset - 2 for sendAttachment, 0 otherwise, probably for \r\n
      out - the buffer the decoded body is written to
      Throws:
      IOException - if no decoder matches the encoding, or the stream cannot be read
    • outputRaw

      public void outputRaw(OutputStream out) throws IOException
      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

      private LimitInputStream getRawInputStream(int offset) throws IOException
      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

      private static String getFirstAttribute(String line)
      Reads the first attribute value from a header line.
      Parameters:
      line - the header line to read
      Returns:
      the value, null if there is none
    • getHeaderLineAttribute

      private static String getHeaderLineAttribute(String line, String attributeName)
      Extract a quoted attribute value from a header line.
      Parameters:
      line - the header line to search, e.g. a Content-Type or Content-Disposition line
      attributeName - must be lower case, will be matched case-insensitively
      Returns:
      as found, not necessarily lower case
    • _t

      private static String _t(String s, Object o)
      Looks up a localized string in the message bundle.
      Parameters:
      s - the translation key
      o - substituted for {0} in the translated string
      Returns:
      the translated string, or s itself if no translation exists
    • toString

      public String toString()
      Renders the part metadata for debugging.
      Overrides:
      toString in class Object