((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/internet-message" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "eggs") (toc)) (section 2 "internet-message" (section 3 "Description" (p (tt "internet-message") " is a collection of parser combinators for the grammar defined in " (link "http://www.ietf.org/rfc/rfc5322.txt" "RFC 5322") " (Internet Message Format).")) (section 3 "Usage" (p "The combinator procedures in this library are based on the interface provided by the " (int-link "abnf") " library.") (p "These procedures are provided as fields of the " (tt "<InetMessage>") " typeclass. Please see the " (int-link "typeclass") " library for information on type classes.") (p "The " (tt "<InetMessage>") " typeclass is intended to provide abstraction over different kinds of input sequences, e.g. character lists, strings, streams, etc. " (tt "<InetMessage>") " inherits from " (tt "<CoreABNF>") ", which provides the core parsing primitives used to build the CSV grammar parser (see the " (int-link "abnf") " library for more information).") (p "The following example illustrates the creation of an instance of " (tt "<InetMessage>") " specialized for character lists.") (highlight scheme "(use typeclass internet-message abnf)\n\n(define char-list-<Input>\n  (make-<Input> null? car cdr))\n\n(define char-list-<Token>\n  (Input->Token char-list-<Input>))\n\n(define char-list-<CharLex>\n  (Token->CharLex char-list-<Token>))\n\n(define char-list-<CoreABNF>\n  (CharLex->CoreABNF char-list-<CharLex>))\n\n(define char-list-<InetMessage>\n  (CoreABNF->InetMessage char-list-<CoreABNF> ))\n\n(import-instance (<InetMessage> char-list-<InetMessage>))") (p "Each procedure contained in the instance of " (tt "<InetMessage>") " is a parser combinator of the form " (tt "(lambda (cont s) ...)") ", which takes a continuation and input stream. For instance, the " (tt "message") " parser combinator can be used to parse messages:") (highlight scheme ";; A procedure which creates an input stream from a string\n(define (string->input-stream s) `(() ,(string->list s)))\n\n;; A procedure used to report parse errors \n(define (err s)\n  (print \"internet message error on stream: \" s)\n  (list))\n\n(with-instance ((<InetMessage> char-list-<InetMessage>))\n\n  (let* (;; Parser combinator procedure which takes continuation and input stream\n         (parse-message (lambda (cont s) ((message) (compose cont car) err s)))\n         (my-message \"From: John Doe <jdoe@machine.example>\\r\\nTo: Mary Smith <mary@example.net>\\r\\nSubject: Saying Hello\\r\\nDate: Fri, 21 Nov 1997 09:55:06 -0600\\r\\nMessage-ID: <1234@local.machine.example>\\r\\n\\r\\nThis is a message just to say hello.\\r\\nSo, \\r\\n\\r\\n\\\"Hello\\\".\")\n          )        \n\n  (parse-message (lambda (s) (test (apply sprintf \"~S -> ~S\" p) res s))\n                 (string->input-stream inp))\n  ))\n->\n(message \n  (fields (From (mailbox-list (mailbox (display-name (\" John \" \"Doe \")) (local-part \"jdoe\") (domain \"machine.example\"))))\n          (To (mailbox (display-name (\" Mary \" \"Smith \")) (local-part \"mary\") (domain \"example.net\")))\n          (Subject \" Saying Hello\") \n\t  (Date (day-of-week \"Fri\") (date \"21\" \"Nov\" \"1997\") (time \"09\" \"55\" \"06\" \"-\" \"06\" \"00\"))\n\t  (Message-id  (message-id \"1234\" \"local.machine.example\")))\n  (body \"This is a message just to say hello.\" \"So, \" \"\\\"Hello\\\".\"))") (pre "              ")) (section 3 "Library Procedures" (p "The following procedures are provided as fields in the " (tt "<InetMessage>") " typeclass:") (def (sig (procedure "fields" (id fields))) (p "This parser will parse an arbitrary number of header fields as defined in the RFC. For each field, an appropriate alist is created. The following fields are recognized:") (ul (li (tt "from")) (li (tt "sender")) (li (tt "return-path")) (li (tt "reply-to")) (li (tt "to")) (li (tt "cc")) (li (tt "bcc")) (li (tt "message-id")) (li (tt "in-reply-to")) (li (tt "references")) (li (tt "subject")) (li (tt "comments")) (li (tt "keywords")) (li (tt "orig-date")) (li (tt "resent-date")) (li (tt "resent-from")) (li (tt "resent-sender")) (li (tt "resent-to")) (li (tt "resent-cc")) (li (tt "resent-bcc")) (li (tt "resent-msg-id")) (li (tt "resent-reply-to")) (li (tt "received")) (li (tt "optional-field")))) (def (sig (procedure "body" (id body))) (p "This parser will parse a message body as specified by the RFC; that is, any number of text characters, which may be divided into separate lines by " (tt "CRLF") ".")) (def (sig (procedure "message" (id message))) (p "This parser will parse a complete message as defined by the RFC and it will break it down into the separate header fields and the message body.")) (def (sig (procedure "comment" (id comment))) (p "This parser parses comment text, as defined by the RFC. Comments may nest."))) (section 3 "Requires" (ul (li (int-link "abnf")))) (section 3 "Version History" (ul (li "5.3 Bug fix in received-token") (li "5.2 Updated test script to return proper exit code") (li "5.1 Compatibility with improved CharLex->CoreABNF constructor") (li "5.0 Compatibility with abnf 5") (li "4.1-4.2 Typeclass interface fixes") (li "4.0 Implemented typeclass interface") (li "3.1 Additional parsing combinators exported") (li "3.0 Changes to the interface of the fields parser") (li "2.0 Extensions to the header function and many bugfixes") (li "1.3 Update to reflect changes in lexgen") (li "1.1 Fix in date parsing") (li "1.0 Initial release"))) (section 3 "License" (p "Based on the Haskell Rfc2822 module by Peter Simons.") (pre " Copyright 2009-2017 Ivan Raikov.") (pre " This program is free software: you can redistribute it and/or\n modify it under the terms of the GNU General Public License as\n published by the Free Software Foundation, either version 3 of the\n License, or (at your option) any later version.") (pre " This program is distributed in the hope that it will be useful, but\n WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n General Public License for more details.") (pre " A full copy of the GPL license can be found at\n <http://www.gnu.org/licenses/>."))))