mscdex / node-imap

An IMAP client module for node.js.
MIT License
2.17k stars 382 forks source link

markSeen:true isn't working #811

Closed chetanpatel6 closed 4 years ago

chetanpatel6 commented 4 years ago

imap.search(['UNSEEN', ['SINCE', 'July 1, 2020']], function (err, results) { if (err) throw err; var f = imap.fetch(results, { bodies: '' ,markSeen:true}); var newMails = []; f.on('message', function (msg, seqno) { var mailFields = { subject: "", date: "", name: "", email: "", text: "" } msg.on('body', function (stream, info) { // use a specialized mail parsing library (https://github.com/andris9/mailparser)
simpleParser(stream, (err, mail) => { var from = mail.from.text; var address = parser(from); mailFields.subject = mail.subject; mailFields.date = mail.date; mailFields.name = address[0].name; mailFields.email = address[0].address; mailFields.text = mail.text; // console.log(mail.from.text); // console.log(mail.subject); // console.log(mail.date) // console.log(address[0].name); // console.log(address[0].address); // console.log(prefix + mail.text); });

                    // or, write to file
                    //stream.pipe(fs.createWriteStream('msg-' + seqno + '-body.txt'));
                  });
                msg.once('attributes', function (attrs) {
                    console.log('Attributes: %s', inspect(attrs, false, 8));
                    console.log('UID: %s', attrs.uid);
                });
                msg.once("error", function () {
                    console.log("Got an error");
                })
                msg.once('end', function () {
                    newMails.push({
                        mail: mailFields,
                        seqNo: seqno
                    });

                    console.log('Finished');
                });
            });

            // console.log('Message #%d', seqno);
            // var prefix = '(#' + seqno + ') ';

            f.once('error', function (err) {
                // callback(imap, newMails);
                callback(imap, newMails);
                console.log('Fetch error: ' + err);
            });
            f.once('end', function () {
                // callback(imap, newMails);
                callback(imap, newMails);
                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();

}

mscdex commented 4 years ago

What does your call to .openBox() look like?

chetanpatel6 commented 4 years ago

//Readonly mode was True function openInbox(cb) { imap.openBox('INBOX', true, cb); }

//And I changed it to false function openInbox(cb) { imap.openBox('INBOX', false, cb); }

//Now it is working //Thankyou