This provides a streaming API to access attachments parts in a MIME message. Often times, a large MIME message cannot be loaded into memory. Hence the whole message or attachment parts are written to a file system and access to the attachment parts is provided using those files.
But in some cases, the attachment parts can be accessed by applications in a streaming fashion, provided: - The parts are accessed orderly(as they appear in the stream) - The parts are accessed only once. In such situations, the parts need not be written to file system(however large message it is !)
// Parts are accessed in order. The data is accessed using readOnce() // and there shouldn't be any data stored in temp files. public void testOrder() { InputStream in = ... String boundary = ... MIMEConfig config = ... MIMEMessage mm = new MIMEMessage(in, boundary, config); MIMEPart partA = mm.getPart("partA"); InputStream ais = partA.readOnce(); MIMEPart partB = mm.getPart("partB"); InputStream bis = partB.readOnce() MIMEPart partC = mm.getPart("partC"); InputStream cis = partC.readOnce() }
MIME message parsing is done using pull-parsing, much similar to StAX in XML world. The MIMEParts are constructed lazily, and parsing is triggered by applications while reading the attachment parts. MIMEConfig provides various configuration options to control parsing and storing MIME parts. It is also possible to read MIME parts in any order and multiple times, but doing so may create attachment parts on the file system.