From: Richard Russon Date: Mon, 21 Jan 2019 23:21:10 +0000 (+0000) Subject: simplify bitfields in ImapAccountData X-Git-Tag: 2019-10-25~372^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0529a0986f60cf6894ef190c678aeb130ac1301a;p=neomutt simplify bitfields in ImapAccountData --- diff --git a/imap/auth_anon.c b/imap/auth_anon.c index 2f5fcf626..b1407dfb4 100644 --- a/imap/auth_anon.c +++ b/imap/auth_anon.c @@ -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) diff --git a/imap/auth_cram.c b/imap/auth_cram.c index 6175f9e16..82cbdf15d 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -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)...")); diff --git a/imap/auth_gss.c b/imap/auth_gss.c index ae31806bd..996858106 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -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) diff --git a/imap/auth_login.c b/imap/auth_login.c index d90f94d72..15e67aa20 100644 --- a/imap/auth_login.c +++ b/imap/auth_login.c @@ -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; diff --git a/imap/auth_oauth.c b/imap/auth_oauth.c index 926ee7968..3c038b00a 100644 --- a/imap/auth_oauth.c +++ b/imap/auth_oauth.c @@ -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; } diff --git a/imap/auth_plain.c b/imap/auth_plain.c index df329eecb..24307a19a 100644 --- a/imap/auth_plain.c +++ b/imap/auth_plain.c @@ -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); } diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index 55baf39e8..287d0daff 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -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++] = ' '; diff --git a/imap/command.c b/imap/command.c index 7a5b349e0..c74f19113 100644 --- a/imap/command.c +++ b/imap/command.c @@ -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; } diff --git a/imap/imap.c b/imap/imap.c index 94ba8c9df..e9bbec8cd 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; diff --git a/imap/imap_private.h b/imap/imap_private.h index 0b7f0a34d..5c41a26c9 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -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 */ diff --git a/imap/message.c b/imap/message.c index 192205f29..6ea048d62 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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"));