ccs.mime
Class MimeEntity

java.lang.Object
  extended by ccs.mime.HeaderedEntity
      extended by ccs.mime.MimeEntity

public class MimeEntity
extends HeaderedEntity

The HeaderedEntity finds multiple uses in simple MIME or MIME-like applications (e.g. HTTP, which is similar to MIME but is nevertheless not MIME conformant.) However, it does not support the MIME feature whereby MIME entities may be nested inside other MIME entities, potentially forming an arbitrary tree. This does. It does not supplant other constructs; specifically there remain situations where it's preferable to use a basic HeaderedEntity or simpler constructs, e.g. MUtil.rawMultipartSet. MT-UNSAFE.

Before any API on this can be used, the body must have been read in, as a RepeatingSwappingBuffer. (This constraint avoids consistency issues when the body is or is not composite).

Known quirk: The preamble and epilogue buffers frequently pick up a superfluous CRLF pair after whatever is actually supposed to be there (this is an artifact of the way the line-parsing mechanism copes with MIME boundary strings). The MIME definition has little to say about these areas, so applications which care about them need to have parsers which are tolerant of this (and more). This trailer will be automatically stripped off when (if) compileBody is invoked, so don't do it yourself.

Note that due to permitted formatting variations for MIME headers, a parseBody-then-compileBody round trip is not always an identity transformation. (So, for example, only do crypto on the original body).


Nested Class Summary
 
Nested classes/interfaces inherited from class ccs.mime.HeaderedEntity
HeaderedEntity.UnmarshalModes
 
Field Summary
 RepeatingSwappingBuffer epilogue
          If composite, the epilogue between the end of the last part and EOF.
 RepeatingSwappingBuffer preamble
          If composite, the preamble to the set.
 MimeEntity[] subparts
          If composite, the subparts contained within this. else null.
 
Constructor Summary
MimeEntity()
          Create a MimeEntity with collapsing headers.
MimeEntity(boolean isCollapse)
          Create a MimeEntity.
 
Method Summary
 void cleanupRepeatableBody()
          Recursively clean up the body, preamble, epilogue and any subparts.
 void compileBody()
          If composite, recursively reassemble the message body from its subparts.
 boolean isComposite()
          Whether this entity is composite, i.e. it contains other entities.
 void parseBody()
          If composite, analyse the body into subparts, recursively.
 
Methods inherited from class ccs.mime.HeaderedEntity
addHeader, addHeader, bodySize, deleteHeader, deleteHeader, getBody, getBodyBytes, getBodyHasTrailer, getHeader, getHeaderIndex, getHeaderInt, getHeaderNames, getName, getValue, getWireLength, isBoundary, marshalTo, nHeaders, out, readBodyFrom, readBodyFrom, readFrom, readHeadersFrom, readRepeatableBodyFrom, readRepeatableBodyFrom, readRepeatableFrom, setBody, setBodyHasTrailer, setHeader, setHeader, swallowPreamble, unmarshalFrom, wasLastBoundary, writeBodyTo, writeHeadersTo, writeln
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

preamble

public RepeatingSwappingBuffer preamble
If composite, the preamble to the set. Else null.


epilogue

public RepeatingSwappingBuffer epilogue
If composite, the epilogue between the end of the last part and EOF. Else null.


subparts

public MimeEntity[] subparts
If composite, the subparts contained within this. else null.

Constructor Detail

MimeEntity

public MimeEntity()
Create a MimeEntity with collapsing headers.


MimeEntity

public MimeEntity(boolean isCollapse)
Create a MimeEntity.

Parameters:
isCollapse - Whether to collapse headers which have the same name.
Method Detail

isComposite

public boolean isComposite()
Whether this entity is composite, i.e. it contains other entities.


parseBody

public void parseBody()
               throws java.io.IOException
If composite, analyse the body into subparts, recursively. Note that the raw body is not altered - the tree exists along side the raw body. Otherwise does nothing.

Throws:
java.io.IOException

compileBody

public void compileBody()
                 throws java.io.IOException
If composite, recursively reassemble the message body from its subparts. Otherwise does nothing (the message body is OK).

Throws:
java.io.IOException

cleanupRepeatableBody

public void cleanupRepeatableBody()
                           throws java.io.IOException
Recursively clean up the body, preamble, epilogue and any subparts.

Overrides:
cleanupRepeatableBody in class HeaderedEntity
Throws:
java.io.IOException