8 Headers: Parsing and Constructing
A header is represented as a string or byte string containing CRLF-delimited lines. Each field within the header spans one or more lines. In addition, the header ends with two CRLFs (because the first one terminates the last field, and the second terminates the header).
8.1 Functions
(validate-header candidate) → void? |
candidate : (or string? bytes?) |
(extract-field field header) → (or/c string? bytes? false/c) |
field : (or/c string? bytes?) |
header : (or/c string? bytes?) |
The field and header arguments must be both strings or both byte strings, and the result (if not #f) is of the same type.
Example: | ||||
|
(extract-all-fields header) | ||||||
| ||||||
header : (or/c string? bytes?) |
The result provides strings if header is a string, byte strings if header is a byte string.
(remove-field field header) → (or/c string? bytes?) |
field : (or/c string? bytes?) |
header : (or/c string? bytes?) |
The field and header arguments must be both strings or both byte strings, and the result is of the same type.
(insert-field field value header) → (or/c string? bytes?) |
field : (or/c string? bytes?) |
value : (or/c string? bytes?) |
header : (or/c string? bytes?) |
The field, value, and header arguments must be all strings or all byte strings, and the result is of the same type.
(replaces-field field value header) → (or/c string? bytes?) |
field : (or/c string? bytes?) |
value : (or/c string? bytes? false/c) |
header : (or/c string? bytes?) |
(append-headers header1 header2) → (or/c string? bytes?) |
header1 : (or/c string? bytes?) |
header2 : (or/c string? bytes?) |
The header1 and header2 arguments must be both strings or both byte strings, and the result is of the same type.
| |||||||||||||||||||||||||||||||||||
from : string? | |||||||||||||||||||||||||||||||||||
to : (listof string?) | |||||||||||||||||||||||||||||||||||
cc : (listof string?) | |||||||||||||||||||||||||||||||||||
bcc : (listof string?) | |||||||||||||||||||||||||||||||||||
subject : string? |
The BCC recipients do not actually appear in the header, but they’re accepted anyway to complete the abstraction.
(data-lines->data listof) → string? |
listof : string? |
(extract-addresses line kind) | ||||||||
| ||||||||
line : string? | ||||||||
|
The kind argument specifies which portion of an address should be returned:
'name —
the free-form name in the address, or the address itself if no name is available. Examples:
> (extract-addresses "John Doe <doe@localhost>" 'name) '("John Doe")
> (extract-addresses "doe@localhost (Johnny Doe)" 'name) '("Johnny Doe")
> (extract-addresses "doe@localhost" 'name) '("doe@localhost")
> (extract-addresses " \"Doe, John\" <doe@localhost>, jane" 'name) '("\"Doe, John\"" "jane")
'address —
just the mailing address, without any free-form names. Examples:
> (extract-addresses "John Doe <doe@localhost>" 'address) '("doe@localhost")
> (extract-addresses "doe@localhost (Johnny Doe)" 'address) '("doe@localhost")
> (extract-addresses "doe@localhost" 'address) '("doe@localhost")
> (extract-addresses " \"Doe, John\" <doe@localhost>, jane" 'address) '("doe@localhost" "jane")
'full —
the full address, essentially as it appears in the input, but normalized. Examples:
> (extract-addresses "John Doe < doe@localhost >" 'full) '("John Doe <doe@localhost>")
> (extract-addresses " doe@localhost (Johnny Doe)" 'full) '("doe@localhost (Johnny Doe)")
> (extract-addresses "doe@localhost" 'full) '("doe@localhost")
> (extract-addresses " \"Doe, John\" <doe@localhost>, jane" 'full) '("\"Doe, John\" <doe@localhost>" "jane")
'all —
a list containing each of the three possibilities: free-form name, address, and full address (in that order). Examples:
> (extract-addresses "John Doe <doe@localhost>" 'all) '(("John Doe" "doe@localhost" "John Doe <doe@localhost>"))
> (extract-addresses "doe@localhost (Johnny Doe)" 'all) '(("Johnny Doe" "doe@localhost" "doe@localhost (Johnny Doe)"))
> (extract-addresses "doe@localhost" 'all) '(("doe@localhost" "doe@localhost" "doe@localhost"))
> (define r (extract-addresses " \"John\" <doe@localhost>, jane" 'all)) > (length r) 2
> (car r) '("\"John\"" "doe@localhost" "\"John\" <doe@localhost>")
> (cadr r) '("jane" "jane" "jane")
(assemble-address-field addrs) → string? |
addrs : (listof string?) |
Example: | ||||
|
8.2 Header Unit
(require net/head-unit) |
head@ : unit? |
8.3 Header Signature
(require net/head-sig) |
head^ : signature |
Includes everything exported by the net/head module.