node-imap icon indicating copy to clipboard operation
node-imap copied to clipboard

markSeen not working with latest npm release

Open qorrect opened this issue 13 years ago • 2 comments

Here is my code

imap.search(['UNSEEN'], function (err, results) {
  logger.log(results);
  imap.fetch(results, { markSeen: true },
  {
    headers: ['from', 'to', 'cc', 'bcc','body'],
    body: true,
    cb: function (fetch) {}
  });
});

I'm getting the emails fine, It's just not setting the seen flag.

How can I mark emails as seen ?

qorrect avatar Mar 08 '13 22:03 qorrect

Nevermind, I copied the code from the examples, and was opening the mailbox in readOnly mode.

I'm keep this here in case someone else gets use out of it.

qorrect avatar Mar 08 '13 23:03 qorrect

imap.openBox("INBOX", false, function(err, mailBox) {
        if (err) {
            console.error(err);
            return;
        }
        imap.search(["UNSEEN"], function(err, results) {

            imap.setFlags(results, ['\\Seen'], function(err) {
                if (!err) {
                    console.log("marked as read");
                } else {
                    console.log(JSON.stringify(err, null, 2));
                }
            });

            var f = imap.seq.fetch(results, { bodies: "" });
            f.on("message", processMessage);
            f.once("error", function(err) {
                return Promise.reject(err);
            });
            f.once("end", function() {
                console.log("Done fetching all unseen messages.");
                imap.end();
            });
        });
    });

processMessage

function processMessage(msg seqno){
         //use mailparser
}

I don't know why my code is not getting properly formatted here, so basically results contains the uuid

we need to call imap.setFlags([uuids], ['\\Seen'], cb) function to make it mark as read

ankitsny avatar Mar 21 '17 08:03 ankitsny