chadxz / imap-simple

Wrapper over node-imap, providing a simpler api for common use cases
MIT License
243 stars 80 forks source link

Not getting new single unseen messages #98

Closed jobayersarkar closed 3 years ago

jobayersarkar commented 3 years ago

I am trying to get all unseen message.I can successfully get that and mark them as read by following code.

It works perfectly if there is more than one new email. But,If there is only one new follow-up email in the INBOX,then the code only mark it as read but doesn't read the message. But,marking one email as unread manually and then the code can read the email and mark it unread.

  `var config = {
  imap: {
      user: 'sd@sdf.com', 
      password: 'dcbfmgh', 
      host: 'imap.gfggdf.com', 
      port: 993,
      tls: true,
      tlsOptions: { rejectUnauthorized: false }
        }}; 
         imaps.connect(config).then(function (connection) {
       return connection.openBox('INBOX'/*,false*/).then(function () {
      var searchCriteria = ['UNSEEN'];  //UNSEEN
      var fetchOptions = {
          bodies: ['HEADER', 'TEXT', ''],
          markSeen: true,
      };
      return connection.search(searchCriteria, fetchOptions).then(function (messages) {
          console.log('reading...');
          messages.forEach(function (item) {
              var all = _.find(item.parts, { "which": "" })
              var id = item.attributes.uid;
              var idHeader = "Imap-Id: "+id+"\r\n";
              simpleParser(idHeader+all.body, (err, mail) => {

                    console.log(mail.from.value[0].address); 

                 console.log(mail.subject)
              });
          });
      });`