1

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();
          });
        })
      })
Kerim092
  • 1,367
  • 1
  • 12
  • 32
  • Just set an appropriately named flag on a message. The list of flags you're looking at is something the server computes based on the flags used by clients in the past. – arnt Apr 23 '18 at 10:01
  • @arnt so u are suggesting to use setFlags() instead of addFlags()? – Kerim092 Apr 23 '18 at 12:56
  • setFlag, addFlag, all the same. If the server supports arbitrary flags the flag will be set. (If it does _not_ support arbitrary flags, * will not be listed in the PERMANENTFLAGS response.) – arnt Apr 23 '18 at 13:09
  • @arnt Aaa so it just matters if server supports arbitrary flags. If it does you can name it however you want? or just some of additional flags provided by server? – Kerim092 Apr 23 '18 at 13:48
  • Right. Most servers do support arbitrary flags. But I'm sure there are some around that don't. – arnt Apr 23 '18 at 14:48

1 Answers1

0

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.

Kerim092
  • 1,367
  • 1
  • 12
  • 32