com.hunnysoft.jmime
Class FieldBody

java.lang.Object
  extended by com.hunnysoft.jmime.Node
      extended by com.hunnysoft.jmime.FieldBody
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Address, AddressList, DateTime, DispositionType, MediaType, MsgId, Stamp, Text, TransferEncodingType

public class FieldBody
extends Node

Class that represents a header field body.

FieldBody represents a header field body in an RFC 2822 message or MIME body part. It is a base class that defines the interface common to all structured and unstructured field bodies.

In the document tree representation of a message, a FieldBody object may be either a leaf node, having a parent node but no child nodes, or an intermediate node, having both a parent node and one or more child nodes. The parent node is the Field object that contains it. The child nodes, if present, depend on the particular subclass of FieldBody. An AddressList object, for example, has Address objects as its child nodes. (See the documentation for Node for a discussion of the tree representation of a message.)

Many header fields, such as the Date header field, have structured field bodies. For those header fields, the structured field body is represented by a subclass of FieldBody. Other header fields, such as the Content-Description header field, have unstructured field bodies. For those headers fields, the unstructured field body is represented by the FieldBody class itself.

You may call the inherited Node.string() method to get the text of the field body. Alternatively, you may call the text() to get the unfolded text of the field body. You may call the inherited Node.setString(ByteString) method to set the text of the field body. Alternatively, you may call setText(ByteString) to set the text and the library will fold long lines for you.

Some MIME parsers are broken in that they do not handle the folding of some fields properly. FieldBody folds its string representation by default. You may call the method setFoldingEnabled(boolean) to enable or disable folding. To determine if folding is enabled, call isFoldingEnabled().


Field Summary
protected  ByteString mText
           
 
Fields inherited from class com.hunnysoft.jmime.Node
mIsModified, mParent, mString
 
Constructor Summary
FieldBody()
          Default constructor.
FieldBody(ByteString bstr)
          Constructor that takes an initial byte string argument.
FieldBody(FieldBody other)
          Copy constructor.
 
Method Summary
 void assemble()
          Assembles the string representation.
 java.lang.Object clone()
          Creates a copy of this object.
static ByteString fold(ByteString unfolded, int offset)
          Performs line folding on its argument.
 boolean isFoldingEnabled()
          Returns true if line folding is enabled.
protected  void maybeFold()
          Folds the string representation, if line folding is enabled.
 void parse()
          Parses the string representation.
 void setFoldingEnabled(boolean b)
          Enables or disables line folding.
 void setText(ByteString text)
          Sets the unfolded text of the field body.
 ByteString text()
          Gets the unfolded text of the field body.
static ByteString unfold(ByteString folded)
          Performs line unfolding on its argument.
 
Methods inherited from class com.hunnysoft.jmime.Node
_setString, isModified, parent, setModified, setParent, setString, string, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mText

protected ByteString mText
Constructor Detail

FieldBody

public FieldBody()
Default constructor.

This constructor sets the FieldBody object's string representation to the empty string and sets its parent node to null.


FieldBody

public FieldBody(FieldBody other)
Copy constructor.

This constructor performs a deep copy of its argument. The parent node of the new FieldBody object is set to null.

Parameters:
other - FieldBody instance to copy

FieldBody

public FieldBody(ByteString bstr)
Constructor that takes an initial byte string argument.

This constructor sets the FieldBody object's string representation to bstr and sets its parent node to null.

Normally, you call the parse() method immediately after this constructor to create the broken-down representation.

Parameters:
bstr - initial value for the string representation
Method Detail

clone

public java.lang.Object clone()
Creates a copy of this object.

This method, inherited from Object, creates a new FieldBody object that has the same value as this FieldBody object. The parent node of the new FieldBody object is set to null.

Overrides:
clone in class Node
Returns:
a copy of this object

parse

public void parse()
Parses the string representation.

This method, inherited from Node, executes the parse operation for FieldBody objects. The parse operation creates or updates the broken-down representation from the string representation. For FieldBody objects, the parse operation does nothing, because FieldBody does not have a broken-down representation. (Subclasses of FieldBody, however, override this method.)

Specified by:
parse in class Node
See Also:
Node.assemble()

assemble

public void assemble()
Assembles the string representation.

This method, inherited from Node, executes the assemble operation for FieldBody objects. The assemble operation creates or updates the string representation from the broken-down representation. For FieldBody objects, the assemble operation does nothing, because FieldBody does not have a broken-down representation. (Subclasses of FieldBody, however, override this method.)

Specified by:
assemble in class Node
See Also:
Node.parse()

text

public ByteString text()
Gets the unfolded text of the field body.

Long lines in Internet mail must be "folded" according to RFC 2822 -- that is, long lines must be wrapped to create several short lines. This method is a convenience method that unfolds the text of the field body before returning it.

Returns:
unfolded text of the field body

setText

public void setText(ByteString text)
Sets the unfolded text of the field body.

Long lines in Internet mail must be "folded" according to RFC 2822 -- that is, long lines must be wrapped to create several short lines. This method is a convenience method that folds the text in its argument and sets the folded text into the field body.

Parameters:
text - unfolded text of the field body

maybeFold

protected void maybeFold()
Folds the string representation, if line folding is enabled.

This method may be called from the assemble() method of subclasses.


isFoldingEnabled

public boolean isFoldingEnabled()
Returns true if line folding is enabled.

Returns:
true if folding is enabled

setFoldingEnabled

public void setFoldingEnabled(boolean b)
Enables or disables line folding.

The default is to enable line folding.

Parameters:
b - true to enable folding

fold

public static ByteString fold(ByteString unfolded,
                              int offset)
Performs line folding on its argument.

The parameter offset indicates how much space should be reserved in the first line for the header field name.

Parameters:
unfolded - unfolded string
offset - amount of space to reserve for the header field name
Returns:
folded string

unfold

public static ByteString unfold(ByteString folded)
Performs line unfolding on its argument.

Parameters:
folded - folded string
Returns:
unfolded string