Mime Design
This page is intended to help with the design of a generic Mime module in order to replace the similar offerings in net.http, as well as add support for email.
Goals
- Generic Mime module supports for the following rfcs: 2045, 2046, 2047, 2822
- Fast (as not to impact performance with existing HttpMessage? and friends)
- Support for 2047 decoding, unfolding, base64, quoted-printable
Solution/Design
Mime Headers
There's basically two methods of access that are required:
- Easy access to a header value: headers["content-type"].value would be an example.
- Easily access the order of, remove, and add headers (again with respect to order),
module tango.net.Mime; class Headers { class Header { char[] name(); // name of header char[] raw(); // raw un-encoded value of header char[] decoded(); // unfolded, 2047 decoded value of header Header opIndex(uint index); // access header by index of this header name (ie: received[3].raw) Header add(char[] name, char[] value) // append new header after this header (encode on write) void remove(); // remove this header } this(Conduit); // parse from conduit uint length(); // number of headers Header opIndex(char[] key); // access header by name (ie: headers["content-type"].raw) Header opIndex(uint key); // access header by index (ie: headers[0].raw) Header add(char[] name, char[] value); // append a new header with name/value (auto-encode on write) }
Mime Body
There are a few things required for this module:
- Be able to modify the mime message (remove/add/modify parts)
- Be able to support base64 and quoted-printable encodings
- Be able to save modified messages to a conduit
Basic outline:
class Body { this(Conduit); // Parse from Conduit Headers header; // Part headers Body[] children; // Children Parts char[] raw; // raw data char[] decoded; // data decoded from base64/quoted-printable }
Discussion