Changeset 33936 in project


Ignore:
Timestamp:
04/05/17 06:55:22 (6 months ago)
Author:
iraikov
Message:

Summary: updated internet-message documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/internet-message

    r24967 r33936  
    1010(Internet Message Format).
    1111
    12 === Library Procedures
     12=== Usage
    1313
    1414The combinator procedures in this library are based on the interface
     
    4949</enscript>
    5050
     51Once the instance of {{<InetMessage>}} is defined, the {{message}}
     52procedure can be used to parse messages in the form of character
     53lists:
     54
     55<enscript highlight="scheme">
     56;; A procedure which creates an input stream from a string
     57(define (string->input-stream s) `(() ,(string->list s)))
     58
     59;; Used to report parse errors
     60(define (err s)
     61  (print "internet message error on stream: " s)
     62  (list))
     63
     64(with-instance ((<InetMessage> char-list-<InetMessage>))
     65
     66  (let* (;; Parser combinator procedure which takes continuation and input stream
     67         (parse-message (lambda (cont s) ((message) (compose cont car) err s)))
     68         (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\".")
     69          )       
     70
     71  (parse-message (lambda (s) (test (apply sprintf "~S -> ~S" p) res s))
     72                 (string->input-stream inp))
     73  ))
     74->
     75(message
     76  (fields (From (mailbox-list (mailbox (display-name (" John " "Doe ")) (local-part "jdoe") (domain "machine.example"))))
     77          (To (mailbox (display-name (" Mary " "Smith ")) (local-part "mary") (domain "example.net")))
     78          (Subject " Saying Hello")
     79          (Date (day-of-week "Fri") (date "21" "Nov" "1997") (time "09" "55" "06" "-" "06" "00"))
     80          (Message-id  (message-id "1234" "local.machine.example")))
     81  (body "This is a message just to say hello." "So, " "\"Hello\"."))
     82</enscript>
     83
     84               
     85=== Library Procedures
     86
     87The following procedures are provided as fields in the {{<InetMessage>}} typeclass:
     88
    5189<procedure>fields</procedure>
    5290
    5391This parser will parse an arbitrary number of header fields as defined
    54 in the RFC. For each field, an appropriate alist is created. The
     92in the RFC. For each field, an appropriate alist is created. Themartin luther kingtr   
    5593following fields are recognized:
    5694
     
    88126<procedure>message</procedure>
    89127
    90 This parser will parse a complete message as defined by the RFC and
    91 it broken down into the separate header fields and the message
    92 body. 
     128This parser will parse a complete message as defined by the RFC and it
     129will break it down into the separate header fields and the message
     130body.
    93131
    94132<procedure>comment</procedure>
     
    121159Based on the Haskell Rfc2822 module by Peter Simons.
    122160
    123   Copyright 2009-2011 Ivan Raikov and the Okinawa Institute of Science and Technology.
     161  Copyright 2009-2017 Ivan Raikov.
    124162
    125163
Note: See TracChangeset for help on using the changeset viewer.