Parsing MIME-encoded data in an HTTP request

Ron Garret rNOSPAMon at flownet.com
Thu Jul 3 16:59:24 EDT 2008


I'm writing a little HTTP server and need to parse request content that 
is mime-encoded.  All the MIME routines in the Python standard library 
seem to have been subsumed into the email package, which makes this 
operation a little awkward.  It seems I have to do the following:

1.  Extract the content-length header from the HTTP request and use that 
to read the payload.

2.  Stick some artificial-looking headers onto the beginning of this 
payload to make it look like an email message (including the 
content-type and content-transfer-encoding headers)

3.  Parse the resulting string into a email message

That works, but it feels way too hackish for my tastes.  Surely there 
must be a better/more standard way of doing this?

Thanks,
rg



More information about the Python-list mailing list