Class Header.

Inherits Garbage

The Header class models an RFC 2822 or MIME header.

Essentially, it's a container for HeaderField objects which can check whether its contents make sense and are legal (see RFC 2822 page 19), and will give them to callers on demand.

Fields are available by calling field() with the right type. This works well for some fields, but fields which can occur several times have a problem. Will have to solve that eventually.

Some fields are also available as values, e.g. date().

Header::Header( Mode m )

Constructs an empty Header in m mode. If m is Rfc2822, the header's validity will follow RFC 2822 rules, while if m is Mime, RFC 2045-2049 rules are used.

void Header::add( HeaderField * hf )

Appends the HeaderField hf to this Header.

If hf is a From/To/Cc/Reply-To/Bcc field, and the same address field already is present in this header, the addresses in hf are merged into the existing field and hf is discarded. This is nominally incorrect, and we do it to accept mail from a variety of buggy mail senders. More address fields may be added to the list if necessary.

void Header::add( const String & name, const String & value )

Creates a header field with the supplied name and value, and appends it to this Header, adjusting validity as necessary.

AddressField * Header::addressField( HeaderField::Type t, uint n ) const

Returns a pointer to the address field of type t at index n in this header, or a null pointer if no such field exists.

List< Address > * Header::addresses( HeaderField::Type t ) const

Returns a pointer to the addresses in the t header field, which must be an address field such as From or Bcc. If not, or if the field is empty, addresses() returns a null pointer.

void Header::appendField( String & r, HeaderField * hf ) const

Appends the string representation of the field hf to r. Does nothing if hf is 0.

This function doesn't wrap. That's probably a bug. How to fix it?

(The details of the function are liable to change.)

String Header::asText() const

Returns the canonical text representation of this Header.

String Header::contentDescription() const

Returns the value of the Content-Description field, or an empty string if there isn't one. RFC 2047 encoding is not considered - should it be?

ContentDisposition * Header::contentDisposition() const

Returns a pointer to the Content-Disposition header field, or a null pointer if there isn't one.

ContentLanguage * Header::contentLanguage() const

Returns a pointer to the Content-Language header field, or a null pointer if there isn't one.

String Header::contentLocation() const

Returns the value of the Content-Location field, or an empty string if there isn't one. The URI is not validated in any way.

ContentTransferEncoding * Header::contentTransferEncoding() const

Returns a pointer to the Content-Transfer-Encoding header field, or a null pointer if there isn't one.

ContentType * Header::contentType() const

Returns a pointer to the Content-Type header field, or a null pointer if there isn't one.

Date * Header::date( HeaderField::Type t ) const

Returns the header's data t, which is the normal date by default, but can also be orig-date or resent-date. If there is no such field or t is meaningless, date() returns a null pointer.

DefaultType Header::defaultType() const

Returns whatever was set using setDefaultType(), or TextPlain if setDefaultType() hasn't been called.

String Header::error() const

Returns a one-line error message describing the first error detected in this Header, or an empty string if there is no error.

HeaderField * Header::field( HeaderField::Type t, uint n ) const

Returns a pointer to the header field with type t and index n, or a null pointer if there is no such field in this header.

if n is 0, as it is by default, the first field with type t is returned. 1 refers to the second.

HeaderField * Header::field( const char * h, uint n ) const

Returns a pointer to the header field with type Other, name h and index n, or a null pointer if there is no such field in this header.

If n is 0, as it is by default, the first field with the desired name is returned, 1 refers to the second, and so on.

List< HeaderField > * Header::fields() const

Returns a pointer to a list containing all the HeaderField objects in this Header. Neither the list nor the HeaderField objects it in may be modified or freed by the caller - Header keeps other pointers to these objects.

void Header::fix8BitFields( class Codec * c )

Scans for fields containing unlabelled 8-bit content and encodes them using c.

At the moment, this covers most unstructured fields. The exact scope of the function may change.

String Header::inReplyTo() const

Returns the header's in-reply-to value. This comes straight from the RFC 2822 representation.

String Header::messageId( HeaderField::Type t ) const

Returns the header's message-id t, which is the normal message-id by default but can also be the first resent-message-id or the content-id. The returned string is in the cleanest possible form. If there is no such message-id, messageId() returns an empty string.

Mode Header::mode() const

Returns the header's mode, either Mime or Rfc2822, which is set using the constructor and decides whether a particular header is valid. For example, in Rfc2822 mode a Date field is mandatory, while in Mime mode it's not allowed.

void Header::removeField( HeaderField::Type t )

This private helper removes all fields with type t from the header.

void Header::repair( Multipart * p, const String & body )

Repairs a few harmless and common problems, such as inserting two Date fields with the same value. Assumes that p is its companion body (whose text is in body), and may look at it to decide what/how to repair.

void Header::repair()

Repairs problems that can be repaired without knowing the associated bodypart.

void Header::setDefaultType( DefaultType t )

Notifies this Header that if no ContentType is set, its default type is t. The initial value is TextPlain.

void Header::simplify()

Removes any redundant header fields from this header. For example, if 'sender' or 'reply-to' points to the same address as 'from', that field can be removed.

String Header::subject() const

Returns the header's subject. For the moment, this is a simple string. It'll have to morph soon, to handle RFC 2047 at least.

bool Header::valid() const

Returns true if this Header fills all the conditions laid out in RFC 2821 for validity, and false if not.

void Header::verify() const

This private function verifies that the entire header is consistent and legal, and that each contained HeaderField is legal.

This web page based on source code belonging to Oryx Mail Systems GmbH. All rights reserved.