mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.14k stars 379 forks source link

German Umlauts or Emoji problem #898

Open Flo0806 opened 1 year ago

Flo0806 commented 1 year ago

Hello!

I use the standard example code like this:

 function openInbox(cb) {
    imap.openBox("INBOX", true, cb);
  }

  imap.once("ready", function () {
    openInbox(function (err, box) {
      if (err) throw err;
      var f = imap.seq.fetch("1:1", {
        bodies: ["HEADER.FIELDS (FROM TO SUBJECT DATE)", "TEXT"],
        struct: true,
      });
      f.on("message", function (msg, seqno) {
        console.log("Message #%d", seqno);
        var prefix = "(#" + seqno + ") ";
        msg.on("body", function (stream, info) {
          if (info.which === "TEXT")
            console.log(
              prefix + "Body [%s] found, %d total bytes",
              inspect(info.which),
              info.size
            );

          var buffer = "";

          stream.on("data", function (chunk) {
            buffer += chunk.toString("utf8");
          });
          stream.once("end", function () {
            if (info.which !== "TEXT")
              console.log(
                prefix + "Parsed header: %s",
                inspect(Imap.parseHeader(buffer, false, 10))
              );
            else {
              //   console.log(
              //     prefix + "Body [%s] Finished",
              //     inspect(info.which),
              //     buffer
              //   );
            }
          });
        });
        msg.once("attributes", function (attrs) {
          console.log(prefix + "Attributes: %s", inspect(attrs, false, 8));
        });
        msg.once("end", function () {
          console.log(prefix + "Finished");
        });
      });
      f.once("error", function (err) {
        console.log("Fetch error: " + err);
      });
      f.once("end", function () {
        console.log("Done fetching all messages!");
        imap.end();
      });
    });
  });

  imap.once("error", function (err) {
    console.log(err);
  });

  imap.once("end", function () {
    console.log("Connection ended");
  });

  imap.connect();
};

And the problem is that german umlauts or emoji are not shown like this:

(#1) Parsed header: {
  subject: [ 'Ein T├Âst' ],
  to: [ 'no-reply@flogersoft.de' ],
  from: [ '"Florian Heuberger" <fh@flogersoft.de>' ],
  date: [ 'Sun, 26 Feb 2023 00:42:20 +0100 (CET)' ]
}

The current subject name is "Ein Töst". What can I do to fix this?