eml-parse-js
eml-parse-js copied to clipboard
Multipart encoded file attachment names are not properly decoded
When using attachment headers that include multiple parts of encoded strings the parser fails to return the proper file names.
I think the behavior should be like in emailjs-mime-codec mimeWordsDecode function.
Here are a few unit tests for validation:
it('should return an empty string for empty input', () => {
expect(mimeWordsDecode('')).toBe('')
})
it('should return the original string if not MIME-encoded', () => {
const plain = 'simple-filename.txt'
expect(mimeWordsDecode(plain)).toBe(plain)
})
it('should decode a single Base64-encoded word', () => {
const encoded = '=?UTF-8?Q?See_on_=C3=B5hin_test?='
const decoded = mimeWordsDecode(encoded)
expect(decoded).toBe('See on õhin test')
})
it('should decode multipart Base64-encoded words into a single string', () => {
const encoded
= '=?utf-8?B?UmVwb3J0X0ZpbmFuY2lhbF9TdW1t?= =?utf-8?B?YXJ5XzIwMjVfSmFuLnBkZg==?='
const decoded = mimeWordsDecode(encoded)
expect(decoded).toBe('Report_Financial_Summary_2025_Jan.pdf')
})
it('should handle different encodings in the same header', () => {
const plain = `=?utf-8?B?anVzdCBhbiBleGFtcGxlX18=?=
=?utf-8?Q?unencoded.xlsx?=`
expect(mimeWordsDecode(plain)).toBe('just an example__unencoded.xlsx')
})
Contributions are welcome!