Skip to content

setFlags not working after IDLE #580

Description

@silverwind

I'm hitting a puzzling issue where setFlags seems to not work after a fetch and after the client sends the IDLE (I'm doing some async action after the messages are parsed).

Here's a example that will flag all unflagged messages:

module.exports.test = function() {
  var imap = new Imap(opts);
  imap.once("ready", function() {
    imap.openBox("INBOX", false, function(_err) {
      imap.search(["UNFLAGGED"], function(_err, results) {
        imap.fetch(results, {bodies: ""}).on("message", function(_, seq) {
          setTimeout(function() { // problematic timeout
            console.log("flagging", seq);
            imap.seq.addFlags(seq, "\\Flagged", function(err) {
              if (err) console.error(err);
              console.log("flagged", seq);
            });
          }, 3000);
        });
      });
    });
  }).on("error", console.error).connect();
};

This results in the following debug log (after fetch). Notice the addFlags callback is never triggered:

<= 'A6 OK Fetch completed (0.002 + 0.000 + 0.001 secs).'
=> 'IDLE IDLE'
<= '+ idling'
flagging 7623
=> DONE
flagging 7624
flagging 7625
flagging 7626
flagging 7627
<= 'IDLE OK Idle completed (0.001 + 2.999 + 2.998 secs).'

Now, when you remove the setTimeout, it works as expected:

<= 'A6 OK Fetch completed (0.002 + 0.000 + 0.001 secs).'
=> 'A7 STORE 7625 +FLAGS.SILENT (\\Flagged)'
flagging 7626
flagging 7627
<= '* 7625 FETCH (MODSEQ (10070))'
<= 'A7 OK Store completed (0.001 + 0.000 secs).'
flagged 7625
=> 'A8 STORE 7626 +FLAGS.SILENT (\\Flagged)'
<= '* 7626 FETCH (MODSEQ (10071))'
<= 'A8 OK Store completed (0.001 + 0.000 secs).'
flagged 7626
=> 'A9 STORE 7627 +FLAGS.SILENT (\\Flagged)'
<= '* 7627 FETCH (MODSEQ (10072))'
<= 'A9 OK Store completed (0.001 + 0.000 secs).'
flagged 7627
=> 'IDLE IDLE'
<= '+ idling'

It almost seems like there's a bug that prevents setFlags from working after the IDLE command has been sent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions