node-imap
node-imap copied to clipboard
markSeen not working with latest npm release
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 ?
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.
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