[racket] mime/multipart parsing

From: Jordan Schatz (jordan at noionlabs.com)
Date: Fri Jan 6 22:17:21 EST 2012

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


Posted on the users mailing list.