mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.16k stars 380 forks source link

Connection not closing after getBoxes execution. #895

Open martinericksonn opened 1 year ago

martinericksonn commented 1 year ago

Supposed after executing getBoxes() the connection will end thus log connection ended but instead is stuck after logging all the key

      const connection = new Imap(credential);

        let folders = [];

        connection.once("ready", () => {
          connection.getBoxes(function more(err, boxes, path) {
            if (err) throw err;

            for (var key in boxes) {
              if (boxes[key].children)
                more(
                  undefined,
                  boxes[key].children,
                  path + key + boxes[key].delimiter
                );
              else {
                console.log(key);
                folders.push(`INBOX.${key}`);
              }
            }

          });
        });

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

        connection.once("end", function () {
          console.log("Connection ended ");
          resolve(folders);
        });

        connection.connect();