FieldBody Class Reference

Class that represents a header field body More...

Inheritance diagram for FieldBody:

Node Address AddressList DateTime DispositionType MailboxList MediaType MsgId Stamp Text TransferEncodingType

List of all members.

Public Member Functions

 FieldBody ()
 Default constructor.
 FieldBody (const FieldBody &other)
 Copy constructor.
 FieldBody (const String &str, Node *parent=0)
 Constructor that takes an initial string and parent node.
virtual ~FieldBody ()
 Destructor.
const FieldBodyoperator= (const FieldBody &other)
 Assignment operator.
virtual void parse ()
 Parses the string representation.
virtual void assemble ()
 Assembles the string representation.
virtual Nodeclone () const
 Creates a copy of this object.
const Stringtext () const
 Gets the unfolded text of the field body.
void setText (const String &text)
 Sets the unfolded text of the field body.
void maybeFold ()
 Folds the string representation, if enabled.
bool isFoldingEnabled () const
 Returns true if line folding is enabled.
void setFoldingEnabled (bool b)
 Enables or disables line folding.

Static Public Member Functions

static String fold (const String &unfolded, unsigned offset)
 Performs line folding on its argument.
static String unfold (const String &folded)
 Performs line unfolding on its argument.
static FieldBodynewFieldBody ()
 Creates a new instance.

Static Public Attributes

static FieldBody *(* sNewFieldBody )()
 Provides a class factory hook.


Detailed Description

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.

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 header fields, the unstructured field body is represented by the FieldBody class itself.

You may call the inherited member function getString() to get the text of the field body. Alternatively, you may call the member function text() to get the unfolded text of the field body. You may call the inherited member function setString() to set the text of the field body. Alternatively, you may call setText() 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 can disable folding, however, by calling the setFoldingEnabled() member function. To determine if folding is enabled, call isFoldingEnabled().


Constructor & Destructor Documentation

FieldBody (  ) 

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

FieldBody ( const FieldBody other  ) 

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 ( const String str,
Node parent = 0 
)

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

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

Parameters:
str initial value for the string representation
parent parent node for this object

~FieldBody (  )  [virtual]

Destructor


Member Function Documentation

void assemble (  )  [virtual]

This virtual function, 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 virtual function.)

Implements Node.

Reimplemented in MsgId, Text, Mailbox, AddressList, MailboxList, Group, DateTime, DispositionType, Stamp, TransferEncodingType, and MediaType.

Node * clone (  )  const [virtual]

This virtual function, inherited from Node, 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.

Returns:
a copy of this object

Implements Node.

Reimplemented in MsgId, Text, Mailbox, AddressList, MailboxList, Group, DateTime, DispositionType, Stamp, TransferEncodingType, and MediaType.

String fold ( const String unfolded,
unsigned  offset 
) [static]

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

bool isFoldingEnabled (  )  const

Returns a boolean indicating if the folding of this field body is enabled.

Returns:
true if folding is enabled

void maybeFold (  ) 

Folds the string representation, if line folding is enabled. This member function can be called from the assemble() member function of subclasses.

FieldBody * newFieldBody (  )  [static]

Creates a new FieldBody object.

If the static data member sNewFieldBody is NULL, this member function creates a new FieldBody object and returns it. Otherwise, newFieldBody() calls the user-supplied function that sNewFieldBody points to and returns the object created by that function.

Returns:
new FieldBody instance
See also:
sNewFieldBody

const FieldBody & operator= ( const FieldBody other  ) 

Performs a deep copy of its argument. The parent node of this FieldBody object is not changed.

Parameters:
other FieldBody instance to copy

void parse (  )  [virtual]

This virtual function, 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 virtual function.)

Implements Node.

Reimplemented in MsgId, Text, Mailbox, AddressList, MailboxList, Group, DateTime, DispositionType, Stamp, TransferEncodingType, and MediaType.

void setFoldingEnabled ( bool  b  ) 

Enables (b = true) or disables (b = false) the folding of this field body. The default is to fold fields.

Parameters:
b true to enable folding

void setText ( const String text  ) 

Sets the unfolded text of the field body.

Long lines in Internet mail must be "folded" according to RFC 2822. This function is a convenience function that folds the text in its argument and sets the folded text into the field body.

Parameters:
text unfolded text of the field body

const String & text (  )  const

Gets the unfolded text of the field body.

Long lines in Internet mail must be "folded" according to RFC 2822. This function is a convenience function that unfolds the text of the field body before returning it.

Returns:
unfolded text of the field body

String unfold ( const String folded  )  [static]

Performs line unfolding on its argument.

Parameters:
folded folded string
Returns:
unfolded string


Member Data Documentation

FieldBody *(* sNewFieldBody)()=0 (  )  [static]

If sNewFieldBody is not NULL, it must point to a user-supplied function that returns a new instance of a subclass of FieldBody.

See also:
newFieldBody()

Copyright © 2001-2009 Hunny Software, Inc. All rights reserved.