This is rfc822.egg.info, produced by makeinfo version 4.7 from
eggdoc-output.texi.

INFO-DIR-SECTION The Algorithmic Language Scheme
START-INFO-DIR-ENTRY
* rfc822.egg: (rfc822.egg).		RFC822 message parsing
END-INFO-DIR-ENTRY


File: rfc822.egg.info,  Node: Top,  Next: About this egg,  Up: (dir)

rfc822 egg
**********

RFC822 message parsing

Written by Shiro Kawai, ported to Chicken by Reed Sheridan

   This manual corresponds to version 1.5 of the rfc822 extension
library for Chicken Scheme.

* Menu:

* About this egg::
* Documentation::
* License::
* Index::


File: rfc822.egg.info,  Node: About this egg,  Next: Documentation,  Prev: Top,  Up: Top

1 About this egg
****************

* Menu:

* Version history::
* Usage::


File: rfc822.egg.info,  Node: Version history,  Next: Usage,  Up: About this egg

1.1 Version history
===================

`1.5'
     Parses strings with #/ correctly

`1.4'
     rfc822-field->tokens fix

`1.3'
     rfc822-header->list now defined

`1.2'
     Fix bug in rfc822-field->tokens

`1.1'
     Hide internal procedure

`1.0'
     Initial release


File: rfc822.egg.info,  Node: Usage,  Prev: Version history,  Up: About this egg

1.2 Usage
=========

Load this egg like so:

   `(require-extension rfc822)'


File: rfc822.egg.info,  Node: Documentation,  Next: License,  Prev: About this egg,  Up: Top

2 Documentation
***************

This is a complete port of Gauche's rfc.822 module, with the exception
of the procedure `rfc822-date->date'.

* Menu:

* Parsing a message header::
* Basic field parsers ::
* Specific field parsers::


File: rfc822.egg.info,  Node: Parsing a message header,  Next: Basic field parsers,  Up: Documentation

2.1 Parsing a message header
============================

 -- procedure: rfc822-header->list
          (rfc822-header->list iport &keyword strict? reader)

     Reads RFC822 format message from an input port iport, until it
     reaches the end of the message header. The header fields are
     unfolded, and broken into a list of the following format:

     ((name body) ...)

     Name ... are the field names, and body ... are the corresponding
     field body, both as strings. Field names are converted to
     lower-case characters. Field bodies are not modified, except the
     folded line is concatenated, CRLFs removed. The order of fields
     are preserved.

     By default, the parser works permissively. If EOF is encountered
     during parsing header, it is taken as the end of the message. And
     if a line that doesn't consist neither continuing (folded) line
     nor start a new header field, it is simply ignored. You can change
     this behavior by giving true value to the keyword argument
     strict?; then the parser raises an error for such a malformed
     header.

     The keyword argument reader takes a procedure that reads a line
     from iport. Its default is read-line, which should be enough for
     most cases.

 -- procedure: rfc822-header-ref
          (rfc822-header-ref header-list field-name &optional default)

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

     Field-name specifies the field name in a lowercase string. If the
     field with given 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.


File: rfc822.egg.info,  Node: Basic field parsers,  Next: Specific field parsers,  Prev: Parsing a message header,  Up: Documentation

2.2 Basic field parsers
=======================

Several procedures are provided to parse "structured" header fields of
RFC2822 messages. These procedures deal with the body of a header
field, i.e. if the header field is "To: Wandering Schemer
<schemer@example.com>", they parse "Wandering Schemer
<schemer@example.com>".

   Most of procedures take an input port. Usually you first parse the
entire header fields by rfc822-header->list, obtain the body of the
header by rfc822-header-ref, then open an input string port for the
body and use those procedures to parse them.

   The reason for this complexity is because you need different
tokenization schemes depending on the type of the field. Rfc2822 also
allows comments to appear between tokens for most cases, so a
simple-minded regexp won't do the job, since rfc2822 comment can be
nested and can't be represented by regular grammar. So, this layer of
procedures are designed flexible enough to handle various syntaxes. For
the standard header types, high-level parsers are also provided; see
"specific field parsers" below.

 -- procedure: rfc822-next-token
          (rfc822-next-token iport &optional tokenizer-specs)

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

     Tokenizer-specs is a list of tokenizer spec, which is either a
     char-set or a cons of a char-set and a procedure.

     After skipping CFWS, the procedure peeks a character at the head
     of iport, 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 as follows: If the tokenizer
     spec is just a char-set, a sequence of characters that belong to
     the char-set consists a token. If it is a cons, the procedure is
     called with iport to read a token.

     If the head character doesn't match any char-sets, the character
     is taken from iport and returned.

     The default tokenizer-specs is as follows:


     (list (cons (char-set #") rfc822-quoted-string)
           (cons *rfc822-atext-chars* rfc822-dot-atom))

     Where rfc822-quoted-string and rfc822-dot-atom are tokenizer
     procedures described below, and *rfc822-atext-chars* is bound to a
     char-set of atext specified in rfc2822. This means
     rfc822-next-token retrieves a token either quoted-string or
     dot-atom specified in rfc2822 by default.

     Using tokenizer-specs, you can customize how the header field is
     parsed. For example, if you want to retrieve a token that is
     either (1) a word constructed by uppercase characters, or (2) a
     quoted string, then you can call rfc822-next-token by this:


     (rfc822-next-token iport
        `(,char-set:uppercase (,(char-set #") . ,rfc822-quoted-string)))


 -- procedure: rfc822-field->tokens
          (rfc822-field->tokens field &optional tokenizer-specs)

     A convenience procedure. Creates an input string port for a field
     body field, and calls rfc822-next-token repeatedly on it until it
     consumes all input, then returns a list of tokens. Tokenizer-specs
     is passed to rfc822-next-token.

 -- procedure: rfc822-skip-cfws
          (rfc822-skip-cfws iport)

     A utility procedure that consumes any comments and/or whitespace
     characters from iport, and returns the head character that is
     neither whitespace nor a comment. The returned character remains
     in iport.

 -- constant: *rfc822-atext-chars*
     Bound to a char-set that is a valid constituent of atom.

 -- constant: *rfc822-standard-tokenizers*
     Bound to the default tokenizer-specs.

 -- procedure: rfc822-atom
          (rfc822-atom iport)


 -- procedure: rfc822-dot-atom
          (rfc822-dot-atom iport)


 -- procedure: rfc822-quoted-string
          (rfc822-quoted-string iport)


   Tokenizers for atom, dot-atom and quoted-string, respectively. The
double-quotes and escaping backslashes within quoted-string are removed
by rfc822-quoted-string.


File: rfc822.egg.info,  Node: Specific field parsers,  Prev: Basic field parsers,  Up: Documentation

2.3 Specific field parsers
==========================

 -- procedure: rfc822-parse-date
          (rfc822-parse-date string)

     Takes RFC-822 type date string, and returns eight values:

     year, month, day-of-month, hour, minutes, seconds, timezone,
     day-of-week.

     Timezone 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.


File: rfc822.egg.info,  Node: License,  Next: Index,  Prev: Documentation,  Up: Top

3 License
*********


Copyright (c) 2000-2003 Shiro Kawai, All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

  1. Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in the
     documentation and/or other materials provided with the distribution.

  3. Neither the name of the authors nor the names of its contributors
     may be used to endorse or promote products derived from this
     software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


File: rfc822.egg.info,  Node: Index,  Prev: License,  Up: Top

Index
*****

 [index ]
* Menu:

* *rfc822-atext-chars*:                  Basic field parsers. (line  87)
* *rfc822-standard-tokenizers*:          Basic field parsers. (line  90)
* rfc822-atom:                           Basic field parsers. (line  93)
* rfc822-dot-atom:                       Basic field parsers. (line  97)
* rfc822-field->tokens:                  Basic field parsers. (line  71)
* rfc822-header->list:                   Parsing a message header.
                                                              (line   7)
* rfc822-header-ref:                     Parsing a message header.
                                                              (line  34)
* rfc822-next-token:                     Basic field parsers. (line  27)
* rfc822-parse-date:                     Specific field parsers.
                                                              (line   7)
* rfc822-quoted-string:                  Basic field parsers. (line 101)
* rfc822-skip-cfws:                      Basic field parsers. (line  79)



Tag Table:
Node: Top226
Node: About this egg569
Node: Version history736
Node: Usage1095
Node: Documentation1257
Node: Parsing a message header1587
Node: Basic field parsers3430
Node: Specific field parsers7711
Node: License8344
Node: Index9990

End Tag Table
