[racket] mime/multipart parsing

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Jan 7 00:12:22 EST 2012

I think the main problem is that the input string has LF newlines, and
it needs to have CRLF newlines. You'll also want a terminating CRLF.

With those changes, then `(message-fields inner-message)' instead of
`(entity-fields inner-entity)' will get you the headers that include
"X-Riak-Vclock: ...". The result of `(entity-fields inner-entity)'
would correspond to a further multipart document in the inner message.

At Fri, 6 Jan 2012 20:17:21 -0700, Jordan Schatz wrote:
> I'm having difficulties parsing mime multipart messages (probably I
> missed something in the docs again). I have this code:
> 
> ----------------------------------------------------------------------
> #lang racket
> 
> (require net/mime)
> 
> (define ip
>   (open-input-string
>    "--9nbsYRvJBLRyuL4VOuuejw9LcAy
> Content-Type: multipart/mixed; boundary=NdzDrpIQMsJKtfv9VrXmp4YwCPh
> 
> --NdzDrpIQMsJKtfv9VrXmp4YwCPh
> X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fvp9087NYEpkzGNlaGCpPMGXBQA=
> Location: /buckets/invoices/keys/RAQpCw8SssXlXVhiGAGYXsVmwvk
> Content-Type: application/json
> Link: </buckets/invoices>; rel='up'
> Etag: 1qS8Wrr2vkTBxkITOjo33K
> Last-Modified: Wed, 04 Jan 2012 17:12:32 GMT
> 
> { 'date': '11/02/2011' }
> --NdzDrpIQMsJKtfv9VrXmp4YwCPh--"))
> 
> (let* ([analyzed (mime-analyze ip)] ;; port -> #<message>
>        [our-entity (message-entity analyzed)] ;; grab #<entity> of this message
>        [parts (entity-parts our-entity)] ;; #<entity> -> list of (inner) 
> #<message>
>        [inner-message (first parts)] ;; I only have one, grab it
>        [inner-entity (message-entity inner-message)] ;; get its #<entity> part
>        [body-proc (entity-body inner-entity)] ;; create a proc that returns the 
> #<entity> body
>        [tmp (open-output-string)]) 
>   (write (entity-fields inner-entity)) ;;Should be a list of string of headers? 
> Actual '()
>   (body-proc tmp) ;; call proc to get message body, it needs an output port
>   (write (get-output-string tmp))) ;; Should be json data? Actual ""
> ----------------------------------------------------------------------
> 
> I thought it would write the headers, and message body, but instead I get
> an empty list, and an empty string. I've been at it for a few hours and I
> don't see what is wrong....
> 
> Thanks : )
> Jordan
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users


Posted on the users mailing list.