]> granicus.if.org Git - neomutt/commitdiff
simplify bitfields in ImapAccountData
authorRichard Russon <rich@flatcap.org>
Mon, 21 Jan 2019 23:21:10 +0000 (23:21 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 8 Feb 2019 18:32:34 +0000 (18:32 +0000)
imap/auth_anon.c
imap/auth_cram.c
imap/auth_gss.c
imap/auth_login.c
imap/auth_oauth.c
imap/auth_plain.c
imap/auth_sasl.c
imap/command.c
imap/imap.c
imap/imap_private.h
imap/message.c

index 2f5fcf6261745561b9b405512d823806f03aad61..b1407dfb494432a8200090d9229a8967f7d22aca 100644 (file)
@@ -46,7 +46,7 @@ enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *metho
 {
   int rc;
 
-  if (!mutt_bit_isset(adata->capabilities, IMAP_CAP_AUTH_ANON))
+  if (!(adata->capabilities & IMAP_CAP_AUTH_ANON))
     return IMAP_AUTH_UNAVAIL;
 
   if (mutt_account_getuser(&adata->conn->account) < 0)
index 6175f9e16ada721569005c6f17fc813dbd401f85..82cbdf15d9a84b73e1284a29cf890b8826f26591 100644 (file)
@@ -102,7 +102,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapAccountData *adata, const char *m
   int len;
   int rc;
 
-  if (!mutt_bit_isset(adata->capabilities, IMAP_CAP_ACRAM_MD5))
+  if (!(adata->capabilities & IMAP_CAP_ACRAM_MD5))
     return IMAP_AUTH_UNAVAIL;
 
   mutt_message(_("Authenticating (CRAM-MD5)..."));
index ae31806bd6c2fcd43618ab16a30d2120bcf92492..996858106eb8a977c6d03bd1b90597d672a4844b 100644 (file)
@@ -121,7 +121,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method
   unsigned long buf_size;
   int rc;
 
-  if (!mutt_bit_isset(adata->capabilities, IMAP_CAP_AGSSAPI))
+  if (!(adata->capabilities & IMAP_CAP_AGSSAPI))
     return IMAP_AUTH_UNAVAIL;
 
   if (mutt_account_getuser(&adata->conn->account) < 0)
index d90f94d7285b03dc4ce68d028e19d873ec6fe3f0..15e67aa20577aca8c427e2b0f2b68e1f44689b64 100644 (file)
@@ -47,7 +47,7 @@ enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *meth
   char q_user[STRING], q_pass[STRING];
   char buf[LONG_STRING];
 
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_LOGINDISABLED))
+  if ((adata->capabilities & IMAP_CAP_LOGINDISABLED))
   {
     mutt_message(_("LOGIN disabled on this server"));
     return IMAP_AUTH_UNAVAIL;
index 926ee79688d404889156fe92637aacf7018967bb..3c038b00a414eb2331c0b2cadc0f251bbb2770c3 100644 (file)
@@ -52,8 +52,8 @@ enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *meth
   int rc;
 
   /* For now, we only support SASL_IR also and over TLS */
-  if (!mutt_bit_isset(adata->capabilities, IMAP_CAP_AUTH_OAUTHBEARER) ||
-      !mutt_bit_isset(adata->capabilities, IMAP_CAP_SASL_IR) || !adata->conn->ssf)
+  if (!(adata->capabilities & IMAP_CAP_AUTH_OAUTHBEARER) ||
+      !(adata->capabilities & IMAP_CAP_SASL_IR) || !adata->conn->ssf)
   {
     return IMAP_AUTH_UNAVAIL;
   }
index df329eecb1cfa2d643d2fbdeac963ea4fd4e1097..24307a19a9ff5b276deaabe01a94ef31883ef9ad 100644 (file)
@@ -60,7 +60,7 @@ enum ImapAuthRes imap_auth_plain(struct ImapAccountData *adata, const char *meth
   mutt_sasl_plain_msg(buf, sizeof(buf), auth_plain_cmd, adata->conn->account.user,
                       adata->conn->account.user, adata->conn->account.pass);
 
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_SASL_IR))
+  if (adata->capabilities & IMAP_CAP_SASL_IR)
   {
     imap_cmd_start(adata, buf);
   }
index 55baf39e8ece70c2524e94dea5ac896b7d8be6d6..287d0dafffddf3c0b23894495eb711e4773dcd88 100644 (file)
@@ -82,7 +82,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *metho
       return IMAP_AUTH_FAILURE;
     }
 
-    if (mutt_bit_isset(adata->capabilities, IMAP_CAP_AUTH_ANON) &&
+    if ((adata->capabilities & IMAP_CAP_AUTH_ANON) &&
         (!adata->conn->account.user[0] ||
          mutt_str_startswith(adata->conn->account.user, "anonymous", CASE_MATCH)))
     {
@@ -131,7 +131,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *metho
   buf = mutt_mem_malloc(bufsize);
 
   snprintf(buf, bufsize, "AUTHENTICATE %s", mech);
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_SASL_IR) && client_start)
+  if ((adata->capabilities & IMAP_CAP_SASL_IR) && client_start)
   {
     len = mutt_str_strlen(buf);
     buf[len++] = ' ';
index 7a5b349e02b58889a32f68d289f1b1cc2d43122e..c74f19113d8a11fee5733ff93f7909fb81915f7e 100644 (file)
@@ -64,8 +64,6 @@ bool ImapServernoise; ///< Config: (imap) Display server warnings as error messa
  * Capabilities - Server capabilities strings that we understand
  *
  * @note This must be kept in the same order as ImapCaps.
- *
- * @note Gmail documents one string but use another, so we support both.
  */
 static const char *const Capabilities[] = {
   "IMAP4",       "IMAP4rev1",      "STATUS",
@@ -73,8 +71,7 @@ static const char *const Capabilities[] = {
   "AUTH=GSSAPI", "AUTH=ANONYMOUS", "AUTH=OAUTHBEARER",
   "STARTTLS",    "LOGINDISABLED",  "IDLE",
   "SASL-IR",     "ENABLE",         "CONDSTORE",
-  "QRESYNC",     "X-GM-EXT-1",     "X-GM-EXT1",
-  NULL,
+  "QRESYNC",     "X-GM-EXT-1",     NULL,
 };
 
 /**
@@ -533,16 +530,15 @@ static void cmd_parse_capability(struct ImapAccountData *adata, char *s)
     *bracket = '\0';
   FREE(&adata->capstr);
   adata->capstr = mutt_str_strdup(s);
-
-  memset(adata->capabilities, 0, sizeof(adata->capabilities));
+  adata->capabilities = 0;
 
   while (*s)
   {
-    for (int i = 0; i < IMAP_CAP_MAX; i++)
+    for (size_t i = 0; Capabilities[i]; i++)
     {
       if (mutt_str_word_casecmp(Capabilities[i], s) == 0)
       {
-        mutt_bit_set(adata->capabilities, i);
+        adata->capabilities |= (1 << i);
         mutt_debug(4, " Found capability \"%s\": %d\n", Capabilities[i], i);
         break;
       }
index 94ba8c9df3bad091f8f072caec6c2f57a90a4638..e9bbec8cd0ad2ba3a5982600b857bffb561bb319 100644 (file)
@@ -86,8 +86,8 @@ static int check_capabilities(struct ImapAccountData *adata)
     return -1;
   }
 
-  if (!(mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4) ||
-        mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4REV1)))
+  if (!((adata->capabilities & IMAP_CAP_IMAP4) ||
+        (adata->capabilities & IMAP_CAP_IMAP4REV1)))
   {
     mutt_error(
         _("This IMAP server is ancient. NeoMutt does not work with it."));
@@ -462,7 +462,7 @@ static int compile_search(struct Mailbox *m, const struct Pattern *pat, struct B
       case MUTT_SERVERSEARCH:
       {
         struct ImapAccountData *adata = imap_adata_get(m);
-        if (!mutt_bit_isset(adata->capabilities, IMAP_CAP_X_GM_EXT1))
+        if (!(adata->capabilities & IMAP_CAP_X_GM_EXT1))
         {
           mutt_error(_("Server-side custom search not supported: %s"), pat->p.str);
           return -1;
@@ -871,7 +871,7 @@ int imap_open_connection(struct ImapAccountData *adata)
 #ifdef USE_SSL
     /* Attempt STARTTLS if available and desired. */
     if (!adata->conn->ssf &&
-        (SslForceTls || mutt_bit_isset(adata->capabilities, IMAP_CAP_STARTTLS)))
+        (SslForceTls || (adata->capabilities & IMAP_CAP_STARTTLS)))
     {
       int rc;
 
@@ -1201,7 +1201,7 @@ int imap_check_mailbox(struct Mailbox *m, bool force)
   int result = 0;
 
   /* try IDLE first, unless force is set */
-  if (!force && ImapIdle && mutt_bit_isset(adata->capabilities, IMAP_CAP_IDLE) &&
+  if (!force && ImapIdle && (adata->capabilities & IMAP_CAP_IDLE) &&
       (adata->state != IMAP_IDLE || time(NULL) >= adata->lastread + ImapKeepalive))
   {
     if (imap_cmd_idle(adata) < 0)
@@ -1220,7 +1220,7 @@ int imap_check_mailbox(struct Mailbox *m, bool force)
     if (result < 0)
     {
       mutt_debug(1, "Poll failed, disabling IDLE\n");
-      mutt_bit_unset(adata->capabilities, IMAP_CAP_IDLE);
+      adata->capabilities &= ~IMAP_CAP_IDLE; // Clear the flag
     }
   }
 
@@ -1271,9 +1271,9 @@ static int imap_status(struct ImapAccountData *adata, struct ImapMboxData *mdata
     return mdata->messages;
   }
 
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4REV1))
+  if (adata->capabilities & IMAP_CAP_IMAP4REV1)
     uid_validity_flag = "UIDVALIDITY";
-  else if (mutt_bit_isset(adata->capabilities, IMAP_CAP_STATUS))
+  else if (adata->capabilities & IMAP_CAP_STATUS)
     uid_validity_flag = "UID-VALIDITY";
   else
   {
@@ -1926,14 +1926,14 @@ int imap_login(struct ImapAccountData *adata)
     imap_exec(adata, "CAPABILITY", IMAP_CMD_QUEUE);
 
     /* enable RFC6855, if the server supports that */
-    if (mutt_bit_isset(adata->capabilities, IMAP_CAP_ENABLE))
+    if (adata->capabilities & IMAP_CAP_ENABLE)
       imap_exec(adata, "ENABLE UTF8=ACCEPT", IMAP_CMD_QUEUE);
 
     /* enable QRESYNC.  Advertising QRESYNC also means CONDSTORE
      * is supported (even if not advertised), so flip that bit. */
-    if (mutt_bit_isset(adata->capabilities, IMAP_CAP_QRESYNC))
+    if (adata->capabilities & IMAP_CAP_QRESYNC)
     {
-      mutt_bit_set(adata->capabilities, IMAP_CAP_CONDSTORE);
+      adata->capabilities |= IMAP_CAP_CONDSTORE;
       if (ImapQResync)
         imap_exec(adata, "ENABLE QRESYNC", IMAP_CMD_QUEUE);
     }
@@ -1978,7 +1978,7 @@ static int imap_mbox_open(struct Mailbox *m)
   mutt_message(_("Selecting %s..."), mdata->name);
 
   /* pipeline ACL test */
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_ACL))
+  if (adata->capabilities & IMAP_CAP_ACL)
   {
     snprintf(buf, sizeof(buf), "MYRIGHTS %s", mdata->munge_name);
     imap_exec(adata, buf, IMAP_CMD_QUEUE);
@@ -2001,7 +2001,7 @@ static int imap_mbox_open(struct Mailbox *m)
     imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE);
 
 #ifdef USE_HCACHE
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_CONDSTORE) && ImapCondStore)
+  if ((adata->capabilities & IMAP_CAP_CONDSTORE) && ImapCondStore)
     condstore = " (CONDSTORE)";
   else
 #endif
@@ -2103,7 +2103,7 @@ static int imap_mbox_open(struct Mailbox *m)
 
   /* check for READ-ONLY notification */
   if (mutt_str_startswith(imap_get_qualifier(adata->buf), "[READ-ONLY]", CASE_IGNORE) &&
-      !mutt_bit_isset(adata->capabilities, IMAP_CAP_ACL))
+      !(adata->capabilities & IMAP_CAP_ACL))
   {
     mutt_debug(2, "Mailbox is read-only.\n");
     m->readonly = true;
index 0b7f0a34d62b4d2270632c50efbe91d0b68ecab2..5c41a26c9f0ab855a0e76aed88dcb16c94318bbe 100644 (file)
@@ -114,32 +114,29 @@ enum ImapState
 };
 
 /**
- * enum ImapCaps - Capabilities we are interested in
+ * ImapCaps - Capabilities we are interested in
  *
  * @note This must be kept in the same order as Capabilities.
  */
-enum ImapCaps
-{
-  IMAP_CAP_IMAP4 = 0,        ///< Server supports IMAP4
-  IMAP_CAP_IMAP4REV1,        ///< Server supports IMAP4rev1
-  IMAP_CAP_STATUS,           ///< Server supports STATUS command
-  IMAP_CAP_ACL,              ///< RFC2086: IMAP4 ACL extension
-  IMAP_CAP_NAMESPACE,        ///< RFC2342: IMAP4 Namespace
-  IMAP_CAP_ACRAM_MD5,        ///< RFC2195: CRAM-MD5 authentication
-  IMAP_CAP_AGSSAPI,          ///< RFC1731: GSSAPI authentication
-  IMAP_CAP_AUTH_ANON,        ///< AUTH=ANONYMOUS
-  IMAP_CAP_AUTH_OAUTHBEARER, ///< RFC7628: AUTH=OAUTHBEARER
-  IMAP_CAP_STARTTLS,         ///< RFC2595: STARTTLS
-  IMAP_CAP_LOGINDISABLED,    ///< RFC2595: LOGINDISABLED
-  IMAP_CAP_IDLE,             ///< RFC2177: IDLE
-  IMAP_CAP_SASL_IR,          ///< SASL initial response draft
-  IMAP_CAP_ENABLE,           ///< RFC5161
-  IMAP_CAP_CONDSTORE,        ///< RFC7162
-  IMAP_CAP_QRESYNC,          ///< RFC7162
-  IMAP_CAP_X_GM_EXT1,        ///< https://developers.google.com/gmail/imap/imap-extensions
-  IMAP_CAP_X_GM_ALT1 = IMAP_CAP_X_GM_EXT1, ///< Alternative capability string
-  IMAP_CAP_MAX,
-};
+#define IMAP_CAP_IMAP4            (1 <<  0) ///< Server supports IMAP4
+#define IMAP_CAP_IMAP4REV1        (1 <<  1) ///< Server supports IMAP4rev1
+#define IMAP_CAP_STATUS           (1 <<  2) ///< Server supports STATUS command
+#define IMAP_CAP_ACL              (1 <<  3) ///< RFC2086: IMAP4 ACL extension
+#define IMAP_CAP_NAMESPACE        (1 <<  4) ///< RFC2342: IMAP4 Namespace
+#define IMAP_CAP_ACRAM_MD5        (1 <<  5) ///< RFC2195: CRAM-MD5 authentication
+#define IMAP_CAP_AGSSAPI          (1 <<  6) ///< RFC1731: GSSAPI authentication
+#define IMAP_CAP_AUTH_ANON        (1 <<  7) ///< AUTH=ANONYMOUS
+#define IMAP_CAP_AUTH_OAUTHBEARER (1 <<  8) ///< RFC7628: AUTH=OAUTHBEARER
+#define IMAP_CAP_STARTTLS         (1 <<  9) ///< RFC2595: STARTTLS
+#define IMAP_CAP_LOGINDISABLED    (1 << 10) ///< RFC2595: LOGINDISABLED
+#define IMAP_CAP_IDLE             (1 << 11) ///< RFC2177: IDLE
+#define IMAP_CAP_SASL_IR          (1 << 12) ///< SASL initial response draft
+#define IMAP_CAP_ENABLE           (1 << 13) ///< RFC5161
+#define IMAP_CAP_CONDSTORE        (1 << 14) ///< RFC7162
+#define IMAP_CAP_QRESYNC          (1 << 15) ///< RFC7162
+#define IMAP_CAP_X_GM_EXT1        (1 << 16) ///< https://developers.google.com/gmail/imap/imap-extensions
+
+#define IMAP_CAP_ALL             ((1 << 17) - 1)
 
 /**
  * struct ImapList - Items in an IMAP browser
@@ -183,7 +180,7 @@ struct ImapAccountData
    * tracking all possible capabilities. bah. (1) I don't like because
    * it's just no fun to get the same information twice */
   char *capstr;
-  unsigned char capabilities[(IMAP_CAP_MAX + 7) / 8];
+  unsigned int capabilities;
   unsigned char seqid; /* tag sequence prefix */
   unsigned int seqno; ///< tag sequence number, e.g. '{seqid}0001'
   time_t lastread; /**< last time we read a command for the server */
index 192205f29c000727aed98debd02704a842e39615..6ea048d624efc3f8b2c3626fc6632c602d604bde 100644 (file)
@@ -1027,12 +1027,12 @@ static int read_headers_fetch_new(struct Mailbox *m, unsigned int msn_begin,
   if (!adata || adata->mailbox != m)
     return -1;
 
-  if (mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4REV1))
+  if (adata->capabilities & IMAP_CAP_IMAP4REV1)
   {
     safe_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers,
                   ImapHeaders ? " " : "", NONULL(ImapHeaders));
   }
-  else if (mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4))
+  else if (adata->capabilities & IMAP_CAP_IMAP4)
   {
     safe_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s%s%s)", want_headers,
                   ImapHeaders ? " " : "", NONULL(ImapHeaders));
@@ -1272,12 +1272,11 @@ int imap_read_headers(struct Mailbox *m, unsigned int msn_begin,
 
     if (mdata->modseq)
     {
-      if (mutt_bit_isset(adata->capabilities, IMAP_CAP_CONDSTORE) && ImapCondStore)
+      if ((adata->capabilities & IMAP_CAP_CONDSTORE) && ImapCondStore)
         has_condstore = true;
 
-      /* If mutt_bit_isset(QRESYNC) and option(OPTIMAPQRESYNC) then Mutt
-       * sends ENABLE QRESYNC.  If we receive an ENABLED response back, then
-       * adata->qresync is set.
+      /* If IMAP_CAP_QRESYNC and ImapQResync then Mutt sends ENABLE QRESYNC.
+       * If we receive an ENABLED response back, then adata->qresync is set.
        */
       if (adata->qresync)
         has_qresync = true;
@@ -1878,7 +1877,7 @@ int imap_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
   e->active = false;
 
   snprintf(buf, sizeof(buf), "UID FETCH %u %s", imap_edata_get(e)->uid,
-           (mutt_bit_isset(adata->capabilities, IMAP_CAP_IMAP4REV1) ?
+           ((adata->capabilities & IMAP_CAP_IMAP4REV1) ?
                 (ImapPeek ? "BODY.PEEK[]" : "BODY[]") :
                 "RFC822"));