Class AddressParser.

Inherits Garbage

The AddressParser class helps parse email addresses and lists.

In the interests of simplicity, AddressParser parses everything as if it were a list of addresses - either of the mailbox-list or address-list productions in RFC 2822. The user of this class must check that the supplied addresses fit the (often more specific) requirements.

AddressParser supports most of RFC 822 and 2822, but mostly omits address groups. An empty address group is translated into a single Address, a nonempty group is translated into the equivalent number of addresses.

AddressParser does not attempt to canonicalize the addresses parsed or get rid of duplicates (To: ams@oryx.com, ams@ory.com), it only parses.

The first error seen is stored and can be accessed using error().

AddressParser::AddressParser( EString s )

Constructs an Address Parser parsing s. After construction, addresses() and error() may be accessed immediately.

void AddressParser::add( UString name, const EString & localpart, const EString & domain )

This private helper adds the address with name, localpart and domain to the list, unless it's there already.

name is adjusted heuristically.

void AddressParser::add( const EString & localpart, const EString & domain )

This version of add() uses only localpart and domain.

void AddressParser::address( int & i )

This private function parses an address ending at position i and adds it to the list.

List<Address> * AddressParser::addresses() const

Returns a pointer to the addresses parsed. The pointer remains valid until this object is deleted.

void AddressParser::assertSingleAddress()

Asserts that addresses() should return a list of a single regular fully-qualified address. error() will return an error message if that isn't the case.

EString AddressParser::atom( int & i )

This private function parses and returns the atom ending at i.

void AddressParser::ccontent( int & i )

This very private helper helps comment() handle nested comments. It advances i to the start of a comment (where it points to '(').

void AddressParser::comment( int & i )

This private function skips past a sequence of spaces and comments at i, or past nothing. Nothing is perfectly okay.

EString AddressParser::domain( int & i )

This private function picks up a domain ending at i and returns it as a string. The validity of the domain is not checked (and should not be - it may come from an old mail message) only its syntactical validity.

void AddressParser::error( const char * s, int i )

This private function records the error s, which is considered to occur at position i.

The name error() is overloaded, nastily. But I don't feel like fixing that right now.

EString AddressParser::error() const

Returns the first error detected (and not compensated) this parser.

int AddressParser::findBorder( int left, int right )

Finds the point between left and right which is most likely to be the border between two addresses. Mucho heuristics. Never used for correct addresses, only when we're grasping at straws.

Both left and right are considered to be possible borders, but a border between the extremes is preferred if possible.

EString AddressParser::localpart( int & i )

This private function parses the localpart ending at i, and returns it as a string.

UString AddressParser::phrase( int & i )

This private function parses an RFC 2822 phrase (a sequence of words, more or less) ending at i, and returns the phrase as a string.

static AddressParser * AddressParser::references( const EString & r )

This static function parses the references field r. This is in AddressParser because References and Message-ID both use the address productions in RFC 822/1034.

This function does it best to skip ahead to the next message-id if there is a syntax error in one. It silently ignores the errors. This is because it's so common to have a bad message-id in the references field of an otherwise impeccable message.

void AddressParser::route( int & i )

If i points to an obs-route, this function silently skips the route.

void AddressParser::space( int & i )

This private function skips past space at position i, or past nothing. Nothing is perfectly okay.

static EString AddressParser::unqp( const EString & s )

This static helper removes quoted-pair from s and turns all sequences of spaces into a single space. It returns the result.

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