Main Page | Namespace List | Class Hierarchy | Class List | Namespace Members | Class Members

Headers Class Reference

Inheritance diagram for Headers:

Node List of all members.

Detailed Description

Headers represents the collection of header fields (often called just headers) in an entity (either a message or body part), as described in RFC 2822 and RFC 2045. A Headers object manages a list of Field objects, which represent the individual header fields.

In the document tree representation of a message, a Headers object is an intermediate node, having both a parent node and several child nodes. The parent node is the Entity object that contains it. The child nodes are the Field objects in the list it manages. (See the man page for Node for a discussion of the tree representation of a message.)

Normally, you do not create a Headers object directly, but you access it through the Entity::headers() member function of Entity, which creates the Headers object for you.

You may use public methods in Headers for adding, removing, or accessing the Field objects it contains. Alternatively, you may use the convenience functions Headers provides. You may call the member functions to(), from(), contentType(), and other similar member functions to directly access the field bodies of the most common structured header fields. These member functions also create Field and FieldBody objects if necessary. For example, if you call to() to access the To header field body, and the To header field does not exist, the function will create it for you. You may call hasField() to check if a particular header field exists. For example, to check if the Content-Type header field exists, call the member function hasField("Content-Type"). You may call fieldBody() to directly access the field body of any header field. If the field does not exist, fieldBody() creates it.


Public Member Functions

 Headers ()
 Default constructor.
 Headers (const Headers &other)
 Copy constructor.
 Headers (const String &str, Node *parent=0)
 Constructor that takes an initial string and parent node.
virtual ~Headers ()
 Destructor.
const Headersoperator= (const Headers &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.
int numFields () const
 Gets the number of header fields in the list.
void addField (Field *field)
 Adds a header field to the end of the list.
void deleteAllFields ()
 Deletes all header fields in the list.
FieldfieldAt (int index) const
 Gets the header field at the specified position in the list.
void insertFieldAt (int index, Field *field)
 Inserts a header field at the specified position in the list.
FieldremoveFieldAt (int index)
 Removes the header field at the specified position in the list.
bool hasField (const char *fieldName) const
 Returns true if the specified header field is present.
FieldBodyfieldBody (const char *fieldName)
 Gets the field body of the specified header field.
AddressListbcc ()
 Gets the field body of the Bcc header field.
AddressListcc ()
 Gets the field body of the Cc header field.
DateTimedate ()
 Gets the field body of the Date header field.
MailboxListfrom ()
 Gets the field body of the From header field.
MsgIdmessageId ()
 Gets the field body of the Message-Id header field.
Stampreceived ()
 Gets the field body of the Received header field.
AddressListreplyTo ()
 Gets the field body of the Reply-To header field.
AddressListresentBcc ()
 Gets the field body of the Resent-Bcc header field.
AddressListresentCc ()
 Gets the field body of the Resent-Cc header field.
DateTimeresentDate ()
 Gets the field body of the Resent-Date header field.
MailboxListresentFrom ()
 Gets the field body of the Resent-From header field.
MsgIdresentMessageId ()
 Gets the field body of the Resent-%Message-Id header field.
AddressListresentReplyTo ()
 Gets the field body of the Resent-Reply-To header field.
MailboxresentSender ()
 Gets the field body of the Resent-Sender header field.
AddressListresentTo ()
 Gets the field body of the Resent-To header field.
AddressreturnPath ()
 Gets the field body of the Return-Path header field.
Mailboxsender ()
 Gets the field body of the Sender header field.
Textsubject ()
 Gets the field body of the Subject header field.
AddressListto ()
 Gets the field body of the To header field.
MsgIdcontentId ()
 Gets the field body of the Content-Id header field.
TransferEncodingTypecontentTransferEncoding ()
 Gets the field body of the Content-Transfer-Encoding header field.
MediaTypecontentType ()
 Gets the field body of the Content-Type header field.
DispositionTypecontentDisposition ()
 Gets the field body of the Content-Dispostion header field.
FieldfindField (const char *fieldName) const
 Searches for the specified field.
int findFieldPos (const char *fieldName) const
 Searches for the specified field.

Static Public Member Functions

HeadersnewHeaders ()
 Creates a new instance.

Static Public Attributes

Headers *(* sNewHeaders )()
 Provides a class factory hook.

Protected Member Functions

void _copyFields (const Headers &headers)
 Copies all header fields from another list.
void _addField (Field *field)
 Adds a header field to the end of the list.
void _insertFieldAt (int index, Field *field)
 Inserts a header field at the specified position in the list.
Field_removeFieldAt (int index)
 Removes the header field at the specified position in the list.
void _deleteAllFields ()
 Deletes all header fields in the list.


Constructor & Destructor Documentation

Headers  ) 
 

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

Headers const Headers other  ) 
 

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

Parameters:
other Headers instance to copy

Headers const String str,
Node parent = 0
 

This constructor sets the Headers 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

~Headers  )  [virtual]
 

Destructor


Member Function Documentation

void _addField Field field  )  [protected]
 

Same as addField(), but does not set the is-modified flag.

See also:
addField()

void _copyFields const Headers headers  )  [protected]
 

Copies the list of Field objects from headers. Assumes the list in this Headers object is emtpy. Does not set the is-modified flag.

Parameters:
headers Headers object to copy Field objects from

void _deleteAllFields  )  [protected]
 

Same as deleteAllFields(), but does not set the is-modified flag.

See also:
deleteAllFields()

void _insertFieldAt int  index,
Field field
[protected]
 

Same as insertFieldAt(), but does not set the is-modified flag.

See also:
insertFieldAt()

Field * _removeFieldAt int  index  )  [protected]
 

Same as removeFieldAt(), but does not set the is-modified flag.

See also:
removeFieldAt()

void addField Field field  ) 
 

Adds field to the end of the header field list.

The Headers destructor deletes the Field objects in the list.

Parameters:
field Field object to add

void assemble  )  [virtual]
 

This virtual function, inherited from Node, executes the assemble operation for Headers objects. The assemble operation creates or updates the string representation from the broken-down representation. For Headers objects, the assemble operation builds the string representation from its list of Field objects. Before it builds the string representation for the Headers object, this member function calls the assemble() member function of each Field object in its list.

You should call this member function after you set or modify any of the contained header fields, and before you retrieve the string representation.

This function clears the is-modified flag.

Implements Node.

AddressList & bcc  ) 
 

Gets the field body of the Bcc header field. If the field does not exist, the function creates it.

Returns:
field body of the Bcc header field

AddressList & cc  ) 
 

Gets the field body of the Cc header field. If the field does not exist, the function creates it.

Returns:
field body of the Cc header field

Node * clone  )  const [virtual]
 

This virtual function, inherited from Node, creates a new Headers object that has the same value as this Headers object. The parent node of the new Headers object is set to NULL.

Returns:
a copy of this object

Implements Node.

DispositionType & contentDisposition  ) 
 

Gets the field body of the Content-Disposition header field. If the field does not exist, the function creates it.

Returns:
field body of the Content-Disposition header field

MsgId & contentId  ) 
 

Gets the field body of the Content-ID header field. If the field does not exist, the function creates it.

Returns:
field body of the Content-ID header field

TransferEncodingType & contentTransferEncoding  ) 
 

Gets the field body of the Content-Transfer-Encoding header field. If the field does not exist, the function creates it.

Returns:
field body of the Content-Transfer-Encoding header field

MediaType & contentType  ) 
 

Gets the field body of the Content-Type header field. If the field does not exist, the function creates it.

Returns:
field body of the Content-Type header field

DateTime & date  ) 
 

Gets the field body of the Date header field. If the field does not exist, the function creates it.

Returns:
field body of the Date header field

void deleteAllFields  ) 
 

Removes and deletes all Field objects in the header field list.

Field & fieldAt int  index  )  const
 

Gets the Field object at position index in the header field list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index < numFields().

Parameters:
index position of the Field object to get
Returns:
reference to the Field object at the specified position

FieldBody & fieldBody const char *  fieldName  ) 
 

Gets a reference to the FieldBody object for the header field with field name fieldName.

If the header field does not exist, the function creates it. You may call hasField() to test if the header field exists without creating it.

Parameters:
fieldName name of the field to get
Returns:
reference to the FieldBody for the specified field

Field * findField const char *  fieldName  )  const
 

Searches for a header field by its field name. If the field is not found, the function returns NULL.

Parameters:
fieldName name of the field to search for
Returns:
if found, a pointer to the Field searched for; otherwise, NULL

int findFieldPos const char *  fieldName  )  const
 

Searches for a header field by its field name.

If the function finds the field, it returns the index of the field. Otherwise, the function returns -1.

Parameters:
fieldName name of the field to search for
Returns:
if found, the index of the Field searched for; otherwise, -1

MailboxList & from  ) 
 

Gets the field body of the From header field. If the field does not exist, the function creates it.

Returns:
field body of the From header field

bool hasField const char *  fieldName  )  const
 

Returns true if a field with the specified name exists.

Parameters:
fieldName name of the field to search for
Returns:
true if the specified field exists

void insertFieldAt int  index,
Field field
 

Inserts field into the header field list at position index.

If index is zero, then the function inserts field into the first position in the list. If index equals numFields(), then the function inserts field into the last position in the list. If index is less than numFields(), then the function moves the Field objects at position index or greater to a higher position in the list.

The Headers destructor deletes the Field objects in the list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index <= numFields().

Parameters:
index position in the list to insert the Field object
field Field object to insert

MsgId & messageId  ) 
 

Gets the field body of the Message-ID header field. If the field does not exist, the function creates it.

Returns:
field body of the Message-ID header field

Headers * newHeaders  )  [static]
 

Creates a new Headers object.

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

Returns:
new Headers instance
See also:
sNewHeaders

int numFields  )  const
 

Gets the number of Field objects in the header field list.

Returns:
number of Field objects in the list

const Headers & operator= const Headers other  ) 
 

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

Parameters:
other Headers instance to copy

void parse  )  [virtual]
 

This virtual function, inherited from Node, executes the parse operation for Headers objects. The parse operation creates or updates the broken-down representation from the string representation. For Headers objects, the parse operation parses the string representation to create a list of Field objects. This member function also calls the parse() member function of each Field object in its list.

You should call this member function after you set or modify the string representation, and before you access any of the contained header fields.

This function clears the is-modified flag.

Implements Node.

Stamp & received  ) 
 

Gets the field body of the Received header field. If the field does not exist, the function creates it.

Returns:
field body of the Received header field

Field * removeFieldAt int  index  ) 
 

Removes the Field object at position index from the header field list and returns it.

If index is less than numFields()-1, then the function moves the Field objects at position (index + 1) or greater to a lower position in the list.

The function's behavior is undefined if index is out of range. Valid values for index are 0 <= index < numFields().

Parameters:
index position of the Field object to remove
Returns:
pointer to the removed Field object

AddressList & replyTo  ) 
 

Gets the field body of the Reply-To header field. If the field does not exist, the function creates it.

Returns:
field body of the Reply-To header field

AddressList & resentBcc  ) 
 

Gets the field body of the Resent-Bcc header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-Bcc header field

AddressList & resentCc  ) 
 

Gets the field body of the Resent-Cc header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-Cc header field

DateTime & resentDate  ) 
 

Gets the field body of the Resent-Date header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-Date header field

MailboxList & resentFrom  ) 
 

Gets the field body of the Resent-From header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-From header field

MsgId & resentMessageId  ) 
 

Gets the field body of the Resent-%Message-ID header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-%Message-ID header field

AddressList & resentReplyTo  ) 
 

Gets the field body of the Resent-Reply-To header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-Reply-To header field

Mailbox & resentSender  ) 
 

Gets the field body of the Resent-Sender header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-Sender header field

AddressList & resentTo  ) 
 

Gets the field body of the Resent-To header field. If the field does not exist, the function creates it.

Returns:
field body of the Resent-To header field

Address & returnPath  ) 
 

Gets the field body of the Return-Path header field. If the field does not exist, the function creates it.

Returns:
field body of the Return-Path header field

Mailbox & sender  ) 
 

Gets the field body of the Sender header field. If the field does not exist, the function creates it.

Returns:
field body of the Sender header field

Text & subject  ) 
 

Gets the field body of the Subject header field. If the field does not exist, the function creates it.

Returns:
field body of the Subject header field

AddressList & to  ) 
 

Gets the field body of the To header field. If the field does not exist, the function creates it.

Returns:
field body of the To header field


Member Data Documentation

Headers *(* sNewHeaders)()=0 [static]
 

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

See also:
newHeaders()

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