>Currently, Pike's MIME.Message parser doesn't handle non-ASCII headers
>with specified encodings:
Sure it does.
> MIME.Message("Subject: =?UTF-8?B?SGVsbG8sIPCfjJA=?=\r\n\r\nHello, world!");
(1) Result: Message(([ ]))
> MIME.decode_words_text_remapped(_->headers->subject);
(2) Result: "Hello, \U0001f310"
>
It is not done automatially for two reasons:
1) RFC1522 encoding is only applicable to certain headers, and the way
it is applied differs between two types of fields (tokenized
fields, and free text fields). Thus, the application will need to
use the function that is appropriate for the specific field it is
accessing.
2) A remapping to unicode is not always needed or preferrable.
Therefore an option is given to use a different set of function
that preserves the original encoding:
> MIME.decode_words_text(_->headers->subject);
(2) Result: ({ /* 1 element */
({ /* 2 elements */
"Hello, \360\237\214\220",
"utf-8"
})
})
>
Encoding works similarly:
> MIME.Message("Hello, world!", (["Subject":
> MIME.encode_words_text_remapped("Hello, \U0001F310", "base64", "utf-8")]));
(1) Result: Message(([ ]))
> (string)_;
(2) Result: "Content-Length: 13\r\n"
"Subject: Hello, =?utf-8?b?8J+MkA==?=\r\n"
"\r\n"
"Hello, world!"
>