Skip to content

Encoding issues - garbled japanese characters results after 'parse' function #37

@maksimlya

Description

@maksimlya

Hi, I am having issues with my email client. Some users report garbled characters on their ends. Most of these users have non-standard text values. I have managed to reproduce the issue, but not sure how to tackle it. I saw some other tickets suggesting to use different methods, but they did not provide an example.

Here is a git with my issue:

https://github.com/maksimlya/emailjs-imap-handler-garbled-example

Can:
git clone
npm i
npm start

put a breakpoint at
console.log(res);

and see the 'Subject' text is garbled, altho I could read it correctly using TextDecoder.

This is the result I get from 'TextDecoder().decode(testVal):

* 17 FETCH (UID 27 BODY[HEADER.FIELDS (FROM TO CC BCC SUBJECT REPLY-TO MESSAGE-ID REFERENCES IN-REPLY-TO X-WELCOME X-WELCOME-EMAIL X-SSHIDE X-SSSINGLEHIDE DISPOSITION-NOTIFICATION-TO X-CONFIRM-READING-TO RETURN-RECEIPT-TO X-PRIORITY IMPORTANCE)] {81}\r\nFrom: [email protected]\nTo: [email protected]\nSubject: テストメール\n\r\n)

And this is the counter-part of that value after using parse function from this lib:

From: [email protected]\nTo: [email protected]\nSubject: ã��ã�¹ã��ã�¡ã�¼ã�«\n\r\n

Screenshot 2024-05-19 at 15 03 40

Any advice / solution?

I've tried to convert the Uint8Array to string, then converting it back with the 'suggested' method of using 'fromCharCode(0)', but that resulted with other errors of 'Unexpected char at position x', so I'm not quite sure what to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions