The rfc822 structure provides rudimentary support for parsing headers according to RFC 822 Standard for the format of ARPA Internet text messages. These headers show up in SMTP messages, HTTP headers, etc.
An RFC 822 header field consists of a field name and a field body, like so:
Subject: RFC 822 can format itself in the ARPA
Here, the field name is `Subject', and the field name is `RFC 822 can format itself in the ARPA' (note the leading space). The field body can be spread over several lines:
Subject: RFC 822 can format itself in the ARPA
In this case, RFC 822 specifies that the meaning of the field body is actually all the lines of the body concatenated, without the intervening line breaks.
The rfc822 structure provides two sets of parsing procedures -- one represents field bodies in the RFC-822-specified meaning, as a single string, the other (with -with-line-breaks appended to the names) reflects the line breaks and represents the bodies as a list of string, one for each line. The latter set only marginally useful -- mainly for code that needs to output headers in the same form as they were originally provided.
Read one field from the port, and return two values:
- name
- This is a symbol describing the field name, such as subject or to. The symbol consists of all lower-case letters.10
- body or body-lines
- This is the field body. Body is a single string, body-lines is a list of strings, one for each line of the body. In each case, the terminating cr/lf's (but nothing else) are trimmed from each string.
When there are no more fields -- EOF or a blank line has terminated the header section -- then both procedures returns [#f #f].
Port is an optional input port to read from -- it defaults to the value of (current-input-port).
Read-line is an optional parameter specifying a procedure of one argument (the input port) used to read the raw header lines. The default used by these procedures terminates lines with either cr/lf or just lf, and it trims the terminator from the line. This procedure should trim the terminator of the line, so an empty line is returned as an empty string.
The procedure raises an error if the syntax of the read field (the line returned by the read-line-function) is illegal according to RFC 822.
This procedure reads in and parses a section of text that looks like the header portion of an RFC 822 message. It returns an association list mapping field names (a symbol such as date or subject) to field bodies. The representation of the field bodies is as with read-rfc822-field and read-rfc822-field-with-line-breaks.These procedures preserve the order of the header fields. Note that several header fields might share the same field name -- in that case, the returned alist will contain several entries with the same car.
Port and read-line are as with read-rfc822-field and read-rfc822-field-with-line-breaks.
This formats a time value (as returned by scsh's time) according to the requirements of the RFC 822 Date header field. The format looks like this:Sun, 06 Nov 1994 08:49:37 GMT
10 In fact, it read-rfc822-field uses the preferred case for symbols of the underlying Scheme implementation which, in the case of scsh, happens to be lower-case.