[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MIME parser




Hi,

I almost finished translating a Java MIME parser to RPG and now I am
thinking about how to add it to HTTP API.

Java parser:  http://docs.sun.com/source/816-6028-10/asd3j.htm#1057113
Download:
http://www.koders.com/java/fid5E090D1FA93F6CFF7C65B9642BD0FD4CB51E2223.aspx.



I drop everything from the Java code that was related to building a MIME
message and just kept the code that supports the user callback procedures.
So the result is a RPG MIME parser that works similar to a SAX parser. I
also developed an adapter for HTTP API that reduces the number of callback
procedures from 22 to 3. These callback procedures are:

D HTTPDataSink_startPart...
D                 PR
D  i_pPart                        *   const
D  i_pUserData                    *   const

D HTTPDataSink_bodyData...
D                 PR
D  i_pPart                        *   const
D  i_pUserData                    *   const
D  i_data                         *   const
D  i_size                       10I 0 const

D HTTPDataSink_endPart...
D                 PR
D  i_pPart                        *   const
D  i_pUserData                    *   const

The parameters are:

  i_pPart      = Current MIME part
  i_pUserData  = Generic global (message scoped) user data
  i_data       = Pointer to body data
  i_size       = Size of body data

The following procedures can be used to access various attributes of a
given MIME part:

  http_mime_Part_getHeaderKey(part: index)
  http_mime_Part_getHeaderValue(part: key: noQuotes)
  http_mime_Part_getBoundary(part)
  http_mime_Part_getContentType(part)
  http_mime_Part_getContentSubType(part)
  http_mime_Part_getContentTransferEncoding(part)
  http_mime_Part_getFileName(part)
  http_mime_Part_getUserData(part)
  http_mime_Part_setUserData(part: userData)

Typically an application opens a file in HTTPDataSink_startPart() and
stores the file handle in some allocated memory. The memory pointer is
stored in the MIME part using http_mime_Part_setUserData(). The scope of
that user data is the MIME part. Then with each call to
HTTPDataSink_bodyData() the application retrieves the user data and writes
the data to a file. Finally the application closes the file in
HTTPDataSink_endPart() and frees the allocated memory.

So far the parser supports decoding of BASE64 and "quoted-printable"
encoded data.

The parser works fine in a simple test environment and I already
successfully decoded a PDF file from a given Ascii MIME message (e-mail).

Now the question is how to add the parser to HTTP API. What I prefer is a
http_post_mime() method that works similar to http_post_xml(). Instead of
specifying start and end element callback procedures a programmer would
specify StartPart, EndPart and BodyData callback procedures. Insdide the
BodyData callback proecdure he could decide whether to save the data to a
file or to directly forward the xml data stream to the eXpat parser.
However for that purpose I needed the http_parser_init(),
http_parse_xml_raw() and http_parser_free() procedures that I suggested in
a former posting.

Am I correct when assuming that the default character set of a MIME message
is 819?

Let me know what you think about the MIME parser and your ideas how to add
it to HTTP API.

Thomas.


--
IMPORTANT NOTICE:
This email is confidential, may be legally privileged, and is for the
intended recipient only. Access, disclosure, copying, distribution, or
reliance on any of it by anyone else is prohibited and may be a criminal
offence. Please delete if obtained in error and email confirmation to the sender.
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------