(rfc :5322) - Internet message format library

Library (rfc :5322)

This library provides the procedures for internet message format defined in RFC5322(RFC 5322).

Parsing message headers

input-port must be input port and will be passed to reader.

Reads RFC5322 format message from the given port until it reaches the end of the message header and returns a list of the following format;

((name body) ...)

name ... are the field names and body ... are the correspoinding field body. Both are as string. Field names are converted to lower-case characters.

The keyword argument strict? switches the behaviour when the procedure encounter EOF. If it's #f, then it simply ignore the field and return the composed list. And if it's #t, it raises &rfc5322-parse-error.

The keyword argument reader reads a line from given port. The default is rfc5322-line-reader and it treats both LF and CRLF eof style. If you want to read from binary port, you need to pass own reader.

input-port must be textual input port.

Reads a line from given port. If the last character is CR chop it off.

An utility procedure to get a specific field from the parsed header list, which is returned by rfc5322-read-headers.

If the field with given field-name is in header-list, the procedure returns its value in a string. Otherwise, if default is given, it is returned, and if not, #f is returned.

An utility procedure to get a specific field from the parsed header list, which is returned by rfc5322-read-headers.

This procedure collects all the given field-name from the header-list. If there's no header named field-name, then the procedure returns ().

Basic field parsers

input-port must be textual input port.

A basic tokenizer. First it skips whitespaces and/or comments (CFWS) from input-port, if any. Then reads one token according to var{tokenizer-specs}. If input-port reaches EOF before any token is read, EOF is returned.

tokenizer-specs is a list of tokenizer spec. which is a cons of a char-set and a procedure.

After skipping CFWS, the procedure peeks a character at the head of input-port, and checks it against the char-sets in _tokenizer-specs_one by one. If a char-set that contains the character belongs to is found, then a token is retrieved with calling the procedure with input-port to read a token.

If the head character doesn’t match any char-sets, the character is taken from input-port and returned.

The default tokenizer-specs is as follows:

(list (cons (string->char-set ":") rfc5322-quoted-string) (cons *rfc5322-atext-chars* rfc5322-dot-atom)) 

A convenience procedure. Creates a string input port from given field and calls rfc5322-next-token repeatedly on it until it consumes all input, and returns a list of tokens.

Consumes whitespace characters and/or any comments from _input-port_and returns a non comment and whitespace character. The returned character remains in input-port.

A character set which is defined RFC 5322 section 3.2.3 Atom.

Default tokenizer.

Tokenizers for dot-atom and quoted-string respectively.

Specific field parsers

Takes RFC-5322 type date string and returns eight values:

year, month, day-of-month, hour, minute, second, time-zone, day-of-week.time-zone is an offset from UT in minutes. day-of-week is a day from sunday, and may be #f if that information is not available. month is an integer between 1 and 12, inclusive. If the string is not parsable, all the elements are #f.

Message constructors

_ (check :error) (continue #f)

Writes the given header to the port output.

date must be SRFI-19 date.

Returns RFC 5322 date formatted string.