Skip to content

Getting undefined type on example from web page. #11

@pkellner

Description

@pkellner

When I create a simple node project and basically run with just ts-node runfile.ts

I get this error:

/Users/peterkellner/repos/gmail-to-icloud/process-mail-queue/node_modules/imap/lib/Connection.js:227
    var type = self._curReq.type;
                            ^
TypeError: Cannot read properties of undefined (reading 'type')

My example is just this which is exactly what is on the home page:

import Imap from "imap";
import {inspect} from "node:util";

const imap = new Imap({
  user: "xxx",
  password: "xxx",
  host: "imap.gmail.com",
  port: 993,
  tls: true,
  tlsOptions: {rejectUnauthorized: false},
});

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

imap.once("ready", function () {
  openInbox(function (err) {
    if (err) throw err;
    const f = imap.seq.fetch("1:3", {
      bodies: "HEADER.FIELDS (FROM TO SUBJECT DATE)",
      struct: true,
    });
    f.on("message", function (msg, seqno) {
      console.log("Message #%d", seqno);
      const prefix = "(#" + seqno + ") ";
      msg.on("body", function (stream) {
        let buffer = "";
        stream.on("data", function (chunk) {
          buffer += chunk.toString("utf8");
        });
        stream.once("end", function () {
          console.log(prefix + "Parsed header: %s", inspect(Imap.parseHeader(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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions