fix header encoding to match rfc2047

Non-ASCII headers must be encoded in the format defined by rfc2047.
Python provides a helper library to do this in `email.header`.
This patch encodes all MIME headers using this helper.

For email address related headers (such as "To" and "From"), we have to
be careful to only encode the name portion and not the email address
portion. This is easy for the tuple case, but for the opaque "Name
<addr>" string case we need to extract out the parts and encode them
separately. See the examples section of the rtf for more details:
http://tools.ietf.org/html/rfc2047#section-8

Testing this is complicated by the fact that many email providers (such
as gmail) will attempt to auto detect incorrectly encoded headers.
I discovered this issue when I noticed that UTF-8 subjects were encoded
wrong when viewing on hotmail.com.