imapnode-imap

Custom flags node-imap


Is there a way to add custom flags in node-imap?? I wanted to add flag like 'Starred' or 'Important' but not successful yet. I've read in the docs something about permFlags and adding custom flags provided by server but not sure if they think server as email provider or our backend as server. I'm successfully adding system flags but not custom ones. I'm guessing they need to be added to permFlags previously, if so how? This is code I use for adding/deleting system flags:

     imap.once('ready', () => {
        imap.openBox('inbox', false, (err, box) => {
        if (err) throw err;
          let ids = JSON.parse("[" + id + "]");
          if (data.flag) { //if true add flag
            imap.seq.addFlags(ids, data.name, (err) => {
              if (err) throw err;
            })
          } else { //if false delete flag
            imap.seq.delFlags(ids, data.name, (err) => {
              if (err) throw err;
            })
          }
          imap.closeBox(function (err) {
            if (err) throw err;
            imap.end();
          });
        })
      })

Solution

  • In meantime I've posted issue on moduls github page and owner answered pretty quickly. Settlement came to adding keywords instead of flags. First we have to check if box allows keywords (if (box.newKeywords === true)), if it does we can add keywords same as we wouldv add flags. If it doesnt then nothing could be done.