[Haskell-cafe] Question: mime-mail and base64 encoding

Michael Snoyman michael at snoyman.com
Tue Dec 7 17:36:36 CET 2010


On Tue, Dec 7, 2010 at 8:21 AM, Nathan Howell <nathan.d.howell at gmail.com> wrote:
> On Mon, Dec 6, 2010 at 8:42 PM, Michael Snoyman <michael at snoyman.com> wrote:
>> The request is to make both the HTML and plain text parts use base64
>> encoding by default. This *seems* to me to make a lot of sense, since
>> it will ensure that your message arrives exactly as you intended it,
>> and will ensure that any non-ASCII code points don't get killed
>> somewhere along the way. On the other hand, I'm not sure what client
>> support is like for base-64 encoding. Don't we need to leave *some*
>> form of non-encoded data for less sophisticated email clients?
>
> The way I've seen it done before was to:
> - calculate the size of the body in quoted-printable and base64 encoding
> - select the smaller encoded form of the two
>
> quoted-printable is fairly human readable. This strategy also works
> for encoding headers, particularly Subject: lines (substituting
> q-encoding for qp).
>

Seems like quoted-printable *is* the correct answer here. I've
implemented both that and encoded-word for headers, and the code seems
to work just fine. Of course, testing by everyone else is always
welcome; the code is in my github repo[1].

Now I have some design questions for everyone:

* There does not appear to be a way to encode MIME header *keys*, so
it's entirely possible that mime-mail will generate invalid messages.
Is this something to worry about? It basically means the user shot
him/herself in the foot by putting non-ASCII data in the key, but even
so it feels wrong that the type system isn't helping us at all here.

* Internally the header values all get converted to Text values for
processing. Does it make sense to just make all the records in the
Mail and Part datatypes use Text instead of String? Especially given
OverloadedStrings it should not hurt usability too much, and in theory
will help performance a bit.

Since I have breaking changes in the API from a previous commit, the
new version will be mime-mail 0.1.0. As long as we're breaking things,
does anyone have anything else they'd like to throw in?

Michael

[1] https://github.com/snoyberg/mime-mail



More information about the Haskell-Cafe mailing list