Class MIMEMessage

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class MIMEMessage
    extends java.lang.Object
    implements java.io.Closeable
    Represents MIME message. MIME message parsing is done lazily using a pull parser.
    • Constructor Summary

      Constructors 
      Constructor Description
      MIMEMessage​(java.io.InputStream in, java.lang.String boundary)  
      MIMEMessage​(java.io.InputStream in, java.lang.String boundary, MIMEConfig config)
      Creates a MIME message from the content's stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes all parsed parts.
      private void close​(java.util.Collection<MIMEPart> parts)  
      java.util.List<MIMEPart> getAttachments()
      Gets all the attachments by parsing the entire MIME message.
      private MIMEPart getDecodedCidPart​(java.lang.String cid)  
      MIMEPart getPart​(int index)
      Creates nth attachment lazily.
      MIMEPart getPart​(java.lang.String contentId)
      Creates a lazy attachment for a given Content-ID.
      boolean makeProgress()
      Parses the MIME message in a pull fashion.
      void parseAll()
      Parses the whole MIME message eagerly
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final java.util.logging.Logger LOGGER
      • in

        private final java.io.InputStream in
      • it

        private final java.util.Iterator<MIMEEvent> it
      • parsed

        private boolean parsed
      • currentPart

        private MIMEPart currentPart
      • currentIndex

        private int currentIndex
      • partsList

        private final java.util.List<MIMEPart> partsList
      • partsMap

        private final java.util.Map<java.lang.String,​MIMEPart> partsMap
    • Constructor Detail

      • MIMEMessage

        public MIMEMessage​(java.io.InputStream in,
                           java.lang.String boundary)
        Parameters:
        in - MIME message stream
        boundary - the separator for parts(pass it without --)
        See Also:
        MIMEMessage(InputStream, String, MIMEConfig)
      • MIMEMessage

        public MIMEMessage​(java.io.InputStream in,
                           java.lang.String boundary,
                           MIMEConfig config)
        Creates a MIME message from the content's stream. The content stream is closed when EOF is reached.
        Parameters:
        in - MIME message stream
        boundary - the separator for parts(pass it without --)
        config - various configuration parameters
    • Method Detail

      • getAttachments

        public java.util.List<MIMEPart> getAttachments()
        Gets all the attachments by parsing the entire MIME message. Avoid this if possible since it is an expensive operation.
        Returns:
        list of attachments.
      • getPart

        public MIMEPart getPart​(int index)
        Creates nth attachment lazily. It doesn't validate if the message has so many attachments. To do the validation, the message needs to be parsed. The parsing of the message is done lazily and is done while reading the bytes of the part.
        Parameters:
        index - sequential order of the part. starts with zero.
        Returns:
        attachemnt part
      • getPart

        public MIMEPart getPart​(java.lang.String contentId)
        Creates a lazy attachment for a given Content-ID. It doesn't validate if the message contains an attachment with the given Content-ID. To do the validation, the message needs to be parsed. The parsing of the message is done lazily and is done while reading the bytes of the part.
        Parameters:
        contentId - Content-ID of the part, expects Content-ID without <, >
        Returns:
        attachemnt part
      • getDecodedCidPart

        private MIMEPart getDecodedCidPart​(java.lang.String cid)
      • parseAll

        public final void parseAll()
        Parses the whole MIME message eagerly
      • close

        public void close()
        Closes all parsed parts. This method is safe to call even if parsing of message failed.

        Does not throw MIMEParsingException if an error occurred during closing a MIME part. The exception (if any) is still logged.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • close

        private void close​(java.util.Collection<MIMEPart> parts)
      • makeProgress

        public boolean makeProgress()
        Parses the MIME message in a pull fashion.
        Returns:
        false if the parsing is completed.