Fix detection of IMAP flags support in JavaScript

Fixes #2664