Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/internet-message|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[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:]] == internet-message === Description {{internet-message}} is a collection of parser combinators for the grammar defined in [[http://www.ietf.org/rfc/rfc5322.txt|RFC 5322]] (Internet Message Format). === Usage The combinator procedures in this library are based on the interface provided by the [[abnf]] library. These procedures are provided as fields of the {{<InetMessage>}} typeclass. Please see the [[typeclass]] library for information on type classes. The {{<InetMessage>}} typeclass is intended to provide abstraction over different kinds of input sequences, e.g. character lists, strings, streams, etc. {{<InetMessage>}} inherits from {{<CoreABNF>}}, which provides the core parsing primitives used to build the CSV grammar parser (see the [[abnf]] library for more information). The following example illustrates the creation of an instance of {{<InetMessage>}} specialized for character lists. <enscript highlight="scheme"> (use typeclass internet-message abnf) (define char-list-<Input> (make-<Input> null? car cdr)) (define char-list-<Token> (Input->Token char-list-<Input>)) (define char-list-<CharLex> (Token->CharLex char-list-<Token>)) (define char-list-<CoreABNF> (CharLex->CoreABNF char-list-<CharLex>)) (define char-list-<InetMessage> (CoreABNF->InetMessage char-list-<CoreABNF> )) (import-instance (<InetMessage> char-list-<InetMessage>)) </enscript> Each procedure contained in the instance of {{<InetMessage>}} is a parser combinator of the form {{(lambda (cont s) ...)}}, which takes a continuation and input stream. For instance, the {{message}} parser combinator can be used to parse messages: <enscript highlight="scheme"> ;; A procedure which creates an input stream from a string (define (string->input-stream s) `(() ,(string->list s))) ;; A procedure used to report parse errors (define (err s) (print "internet message error on stream: " s) (list)) (with-instance ((<InetMessage> char-list-<InetMessage>)) (let* (;; Parser combinator procedure which takes continuation and input stream (parse-message (lambda (cont s) ((message) (compose cont car) err s))) (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\".") ) (parse-message (lambda (s) (test (apply sprintf "~S -> ~S" p) res s)) (string->input-stream inp)) )) -> (message (fields (From (mailbox-list (mailbox (display-name (" John " "Doe ")) (local-part "jdoe") (domain "machine.example")))) (To (mailbox (display-name (" Mary " "Smith ")) (local-part "mary") (domain "example.net"))) (Subject " Saying Hello") (Date (day-of-week "Fri") (date "21" "Nov" "1997") (time "09" "55" "06" "-" "06" "00")) (Message-id (message-id "1234" "local.machine.example"))) (body "This is a message just to say hello." "So, " "\"Hello\".")) </enscript> === Library Procedures The following procedures are provided as fields in the {{<InetMessage>}} typeclass: <procedure>fields</procedure> 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: * {{from}} * {{sender}} * {{return-path}} * {{reply-to}} * {{to}} * {{cc}} * {{bcc}} * {{message-id}} * {{in-reply-to}} * {{references}} * {{subject}} * {{comments}} * {{keywords}} * {{orig-date}} * {{resent-date}} * {{resent-from}} * {{resent-sender}} * {{resent-to}} * {{resent-cc}} * {{resent-bcc}} * {{resent-msg-id}} * {{resent-reply-to}} * {{received}} * {{optional-field}} <procedure>body</procedure> 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 {{CRLF}}. <procedure>message</procedure> 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. <procedure>comment</procedure> This parser parses comment text, as defined by the RFC. Comments may nest. === Requires * [[abnf]] === Version History * 5.3 Bug fix in received-token * 5.2 Updated test script to return proper exit code * 5.1 Compatibility with improved CharLex->CoreABNF constructor * 5.0 Compatibility with abnf 5 * 4.1-4.2 Typeclass interface fixes * 4.0 Implemented typeclass interface * 3.1 Additional parsing combinators exported * 3.0 Changes to the interface of the fields parser * 2.0 Extensions to the header function and many bugfixes * 1.3 Update to reflect changes in lexgen * 1.1 Fix in date parsing * 1.0 Initial release === License Based on the Haskell Rfc2822 module by Peter Simons. Copyright 2009-2017 Ivan Raikov. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you add 10 to 0?