Name

rfc822 — RFC 822 parsing library

Synopsis

#include <rfc822.h>

#include <rfc2047.h>

cc ... -lrfc822

DESCRIPTION

The rfc822 library provides functions for parsing E-mail headers in the RFC 822 format. This library also includes some functions to help with encoding and decoding 8-bit text, as defined by RFC 2047.

The format used by E-mail headers to encode sender and recipient information is defined by RFC 822 (and its successor, RFC 2822). The format allows the actual E-mail address and the sender/recipient name to be expressed together, for example: John Smith <jsmith@example.com>

The main purposes of the rfc822 library is to:

1) Parse a text string containing a list of RFC 822-formatted address into its logical components: names and E-mail addresses.

2) Access those individual components.

3) Allow some limited modifications of the parsed structure, and then convert it back into a text string.

Tokenizing an E-mail header

struct rfc822t *tokens=rfc822t_alloc_new(const char *header,
                void (*err_func)(const char *, int, void *),
                void *func_arg);

void rfc822t_free(tokens);

The rfc822t_alloc_new() function (superceeds rfc822t_alloc(), which is now obsolete) accepts an E-mail header, and parses it into individual tokens. This function allocates and returns a pointer to an rfc822t structure, which is later used by rfc822a_alloc() to extract individual addresses from these tokens.

If err_func argument, if not NULL, is a pointer to a callback function. The function is called in the event that the E-mail header is corrupted to the point that it cannot even be parsed. This is a rare instance -- most forms of corruption are still valid at least on the lexical level. The only time this error is reported is in the event of mismatched parenthesis, angle brackets, or quotes. The callback function receives the header pointer, an index to the syntax error in the header string, and the func_arg argument.

The semantics of err_func are subject to change. It is recommended to leave this argument as NULL in the current version of the library.

rfc822t_alloc() returns a pointer to a dynamically-allocated rfc822t structure. A NULL pointer is returned if there's insufficient memory to allocate this struct