Class HeaderField.

Inherits Garbage. Inherited by AddressField, DateField, ListIdField and MimeField.

This class models a single RFC 822 header field (e.g. From).

This class is responsible for parsing and verifying header fields. Each field has a type(), name(), and value(). It is valid() if no error() was recorded during parsing by the various functions that parse() field values, e.g. parseText()).

Users may obtain HeaderField objects only via create().

HeaderField::HeaderField( HeaderField::Type t )

Constructs a HeaderField of type t.

static HeaderField * HeaderField::assemble( const EString & name, const UString & data )

This static function returns a pointer to a new HeaderField object that represents the given field name (case-insensitive) and the field data retrieved from the database.

This function is for use by the message fetcher.

static HeaderField * HeaderField::create( const EString & name, const EString & value )

This static function returns a pointer to a new HeaderField object that represents the given field name (case-insensitive) and its value (which is parsed appropriately). Neither name nor value may contain the separating ':'.

This function is for use by the message parser.

static EString HeaderField::encodePhrase( const UString & s )

This static function returns the RFC 2047-encoded version of s.

static EString HeaderField::encodeText( const UString & s )

This static function returns the RFC 2047-encoded version of s.

static EString HeaderField::encodeWord( const UString & w )

This static function returns an RFC 2047 encoded-word representing w.

EString HeaderField::error() const

Returns a suitable error message if this header field has a known parse error, and an empty string if the field is valid() or -- as is the case for all unknown fields -- not parsed.

static const char * HeaderField::fieldName( HeaderField::Type t )

Returns the name corresponding to the field type t, or 0 if there is no such field.

static HeaderField * HeaderField::fieldNamed( const EString & name )

This private function is used by create() and assemble() to create a HeaderField object of a type appropriate to the given name.

static uint HeaderField::fieldType( const EString & n )

Returns the Type corresponding to field name n, or 0 if n isn't known.

EString HeaderField::name() const

Returns the canonical name of this header field.

void HeaderField::parse( const EString & s )

Every HeaderField subclass must define a parse() function that takes a string s from a message and sets the field value(). This default function handles fields that are not specially handled by subclasses using functions like parseText().

void HeaderField::parseContentBase( const EString & s )

Parses the Content-Base header field in s and records the first problem found. Somewhat overflexibly assumes that if there is a colon, the URL is absolute, so it accepts -:/asr as a valid URL.

void HeaderField::parseContentLocation( const EString & s )

Parses the Content-Location header field in s and records the first problem found.

void HeaderField::parseErrorsTo( const EString & s )

Parses Errors-To field s. Stores localpart@domain if it looks like a single address (and reasonably error-free) and an empty value if there's any doubt what to store.

void HeaderField::parseMimeVersion( const EString & s )

Parses the Mime-Version field from s and resolutely ignores all problems seen.

Only version 1.0 is legal. Since vast numbers of spammers send other version numbers, we replace other version numbers with 1.0 and a comment. Bayesian analysis tools will probably find the comment to be a sure spam sign.

void HeaderField::parseOther( const EString & s )

Tries to parses any (otherwise uncovered and presumably unstructured) field in s, and records an error if it contains NULs or 8-bit characters.

void HeaderField::parseText( const EString & s )

Parses the *text production from s, as modified to include encoded-words by RFC 2047. This is used to parse the Subject and Comments fields.

uint HeaderField::position() const

Returns the header field's position, as recorded by setPosition(). The initial value is UINT_MAX, which is magic. When Header sees UINT_MAX, it changes the position() to one higher than the highest existing position.

EString HeaderField::rfc822() const

Returns the RFC 2822 representation of this header field, with its contents properly folded and, if necessary, RFC 2047 encoded. This is a string we can hand out to clients.

void HeaderField::setError( const EString & s )

Records the error text s encountered during parsing.

void HeaderField::setName( const EString & n )

Sets the name of this HeaderField to n.

void HeaderField::setPosition( uint p )

Records the position of this header field, p. This function doesn't move the header field in the lost used by Header, it merely records the position so that Header can access it when needed.

void HeaderField::setUnparsedValue( const EString & s )

Records that the field's unparsed value is s. unparsedValue() will return s, unless the string is/becomes valid().

void HeaderField::setValue( const UString & s )

Sets the parsed representation of this HeaderField to s and clears the error().

Type HeaderField::type() const

Returns the type of this header field, as set by the constructor based on the name(). Unknown fields have type HeaderField::Other.

EString HeaderField::unparsedValue() const

Returns the header field's value() completely unparsed, if !valid(). If the field is valid(), this function returns an empty string.

bool HeaderField::valid() const

Returns true if this header field is valid (or unparsed, as is the case for all unknown fields), and false if an error was detected during parsing.

UString HeaderField::value() const

If the header field is valid(), this function returns the contents of this header field in a representation that is meant for storage in the database (unfolded and UTF-8 encoded, with RFC 2047 encoded-words expanded).

If the field is not valid(), this function returns an empty string.

Use rfc822() if you want a valid RFC 2822 representation.

EString HeaderField::wrap( const EString & s ) const

Returns a version of s with long lines wrapped according to the rules in RFC [2]822. This function is not static, because it needs to look at the field name.

XXX: Well, except that we ignore the rules right now.

HeaderField::~HeaderField()

Exists only to avoid compiler warnings.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.