ssoma-mda: Handle Subject:s that aren't RFC-2047-encoded too
authorW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 07:32:03 +0000 (23:32 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 07:55:26 +0000 (23:55 -0800)
commit22ae96b272be1e0337859286768833a0b073ea75
tree731c2ffa060f438a6cc57d0b5a28032ff0fbaa30
parentbc066f0d446583ea0e681cf25254b9e32ca29220
ssoma-mda: Handle Subject:s that aren't RFC-2047-encoded too

If the string is not RFC-2047 encoded, the charset from decode_header
is None:

  >>> import email.header
  >>> email.header.decode_header('hello')
  [('hello', None)]

so str(decoded, charset) will fail with:

  TypeError: str() argument 2 must be str, not None

Avoid that by checking charset before attempting to decode with
charset.  Since that's a bit awkward, pull it out into its own
_decode_header function.

The Simonsen example is from RFC 2047 [1].

[1]: http://tools.ietf.org/html/rfc2047#section-8
ssoma-mda