smtp/mime: update encoding test & document encoding support limitations

This commit is contained in:
Zack Schuster 2020-06-09 22:35:51 -07:00
parent a48d0ce78d
commit db069d4a9d
2 changed files with 11 additions and 3 deletions

View File

@ -134,7 +134,11 @@ function checkRanges(nr: number) {
* byte value in hex. This function does not convert linebreaks etc. it
* only escapes character sequences
*
* NOTE: Encoding support depends on util.TextDecoder, which is severely limited
* prior to Node.js 13.
*
* @see https://nodejs.org/api/util.html#util_whatwg_supported_encodings
* @see https://github.com/nodejs/node/issues/19214
*
* @param {string|Uint8Array} data Either a string or an Uint8Array
* @param {string} encoding WHATWG supported encoding
@ -168,8 +172,12 @@ export function mimeEncode(data: string | Uint8Array = '', encoding = 'utf-8') {
/**
* Encodes a string or an Uint8Array to an UTF-8 MIME Word
*
* NOTE: Encoding support depends on util.TextDecoder, which is severely limited
* prior to Node.js 13.
*
* @see https://tools.ietf.org/html/rfc2047
* @see https://nodejs.org/api/util.html#util_whatwg_supported_encodings
* @see https://github.com/nodejs/node/issues/19214
*
* @param {string|Uint8Array} data String to be encoded
* @param {'Q' | 'B'} mimeWordEncoding='Q' Encoding for the mime word, either Q or B

View File

@ -11,7 +11,7 @@ test('mimeEncode should encode trailing whitespace', (t) => {
});
test('mimeEncode should encode non UTF-8', (t) => {
t.is(mimeEncode(new Uint8Array([0xbd, 0xc5]), 'ks_c_5601-1987'), '=EC=8B=A0');
t.is(mimeEncode(new Uint8Array([0xbd, 0xc5]), 'utf-16be'), '=EB=B7=85');
});
test('mimeWordEncode should encode', (t) => {
@ -20,11 +20,11 @@ test('mimeWordEncode should encode', (t) => {
test('mimeWordEncode should QP-encode mime word', (t) => {
t.is(
'=?UTF-8?Q?J=C3=B5ge-va=C5=BD?=',
'=?UTF-8?Q?=E4=AB=B5=E6=9D=A5=E2=B5=B6=E6=87=9E?=',
mimeWordEncode(
new Uint8Array([0x4a, 0xf5, 0x67, 0x65, 0x2d, 0x76, 0x61, 0xde]),
'Q',
'iso-8859-13'
'utf-16be'
)
);
});