From: Richard Russon Date: Fri, 28 Sep 2018 15:16:39 +0000 (+0100) Subject: ImapAccountData X-Git-Tag: 2019-10-25~618 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a67009c07079c977f9628edbe61f899294e7ce1a;p=neomutt ImapAccountData Even though it's attached to a Mailbox, this is Account data. --- diff --git a/imap/auth.c b/imap/auth.c index f0e8122f6..e030b755c 100644 --- a/imap/auth.c +++ b/imap/auth.c @@ -58,13 +58,13 @@ static const struct ImapAuth imap_authenticators[] = { /** * imap_authenticate - Authenticate to an IMAP server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval num Result, e.g. #IMAP_AUTH_SUCCESS * * Attempt to authenticate using either user-specified authentication method if * specified, or any. */ -int imap_authenticate(struct ImapMboxData *mdata) +int imap_authenticate(struct ImapAccountData *adata) { int r = IMAP_AUTH_FAILURE; @@ -91,7 +91,7 @@ int imap_authenticate(struct ImapMboxData *mdata) const struct ImapAuth *auth = &imap_authenticators[i]; if (!auth->method || (mutt_str_strcasecmp(auth->method, method) == 0)) { - r = auth->authenticate(mdata, method); + r = auth->authenticate(adata, method); if (r == IMAP_AUTH_SUCCESS) { FREE(&methods); @@ -110,7 +110,7 @@ int imap_authenticate(struct ImapMboxData *mdata) for (size_t i = 0; i < mutt_array_size(imap_authenticators); ++i) { - r = imap_authenticators[i].authenticate(mdata, NULL); + r = imap_authenticators[i].authenticate(adata, NULL); if (r == IMAP_AUTH_SUCCESS) return r; } diff --git a/imap/auth.h b/imap/auth.h index 82eabe672..0188501e6 100644 --- a/imap/auth.h +++ b/imap/auth.h @@ -26,7 +26,7 @@ #ifndef MUTT_IMAP_AUTH_H #define MUTT_IMAP_AUTH_H -struct ImapMboxData; +struct ImapAccountData; /** * enum ImapAuthRes - Results of IMAP Authentication @@ -44,25 +44,25 @@ enum ImapAuthRes struct ImapAuth { /* do authentication, using named method or any available if method is NULL */ - enum ImapAuthRes (*authenticate)(struct ImapMboxData *mdata, const char *method); + enum ImapAuthRes (*authenticate)(struct ImapAccountData *adata, const char *method); /* name of authentication method supported, NULL means variable. If this * is not null, authenticate may ignore the second parameter. */ const char *method; }; /* external authenticator prototypes */ -enum ImapAuthRes imap_auth_plain(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_plain(struct ImapAccountData *adata, const char *method); #ifndef USE_SASL -enum ImapAuthRes imap_auth_anon(struct ImapMboxData *mdata, const char *method); -enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *method); +enum ImapAuthRes imap_auth_cram_md5(struct ImapAccountData *adata, const char *method); #endif -enum ImapAuthRes imap_auth_login(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method); #ifdef USE_GSS -enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method); #endif #ifdef USE_SASL -enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *method); #endif -enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method); +enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *method); #endif /* MUTT_IMAP_AUTH_H */ diff --git a/imap/auth_anon.c b/imap/auth_anon.c index 2dff2d626..e516df0c3 100644 --- a/imap/auth_anon.c +++ b/imap/auth_anon.c @@ -36,31 +36,31 @@ /** * imap_auth_anon - Authenticate anonymously - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS * * this is basically a stripped-down version of the cram-md5 method. */ -enum ImapAuthRes imap_auth_anon(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_anon(struct ImapAccountData *adata, const char *method) { int rc; - if (!mutt_bit_isset(mdata->capabilities, AUTH_ANON)) + if (!mutt_bit_isset(adata->capabilities, AUTH_ANON)) return IMAP_AUTH_UNAVAIL; - if (mutt_account_getuser(&mdata->conn->account) < 0) + if (mutt_account_getuser(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - if (mdata->conn->account.user[0] != '\0') + if (adata->conn->account.user[0] != '\0') return IMAP_AUTH_UNAVAIL; mutt_message(_("Authenticating (anonymous)...")); - imap_cmd_start(mdata, "AUTHENTICATE ANONYMOUS"); + imap_cmd_start(adata, "AUTHENTICATE ANONYMOUS"); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) @@ -69,10 +69,10 @@ enum ImapAuthRes imap_auth_anon(struct ImapMboxData *mdata, const char *method) goto bail; } - mutt_socket_send(mdata->conn, "ZHVtbXkK\r\n"); /* base64 ("dummy") */ + mutt_socket_send(adata->conn, "ZHVtbXkK\r\n"); /* base64 ("dummy") */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) @@ -81,7 +81,7 @@ enum ImapAuthRes imap_auth_anon(struct ImapMboxData *mdata, const char *method) goto bail; } - if (imap_code(mdata->buf)) + if (imap_code(adata->buf)) return IMAP_AUTH_SUCCESS; bail: diff --git a/imap/auth_cram.c b/imap/auth_cram.c index ee7efb072..d7a6d812b 100644 --- a/imap/auth_cram.c +++ b/imap/auth_cram.c @@ -91,29 +91,29 @@ static void hmac_md5(const char *password, char *challenge, unsigned char *respo /** * imap_auth_cram_md5 - Authenticate using CRAM-MD5 - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_cram_md5(struct ImapAccountData *adata, const char *method) { char ibuf[LONG_STRING * 2], obuf[LONG_STRING]; unsigned char hmac_response[MD5_DIGEST_LEN]; int len; int rc; - if (!mutt_bit_isset(mdata->capabilities, ACRAM_MD5)) + if (!mutt_bit_isset(adata->capabilities, ACRAM_MD5)) return IMAP_AUTH_UNAVAIL; mutt_message(_("Authenticating (CRAM-MD5)...")); /* get auth info */ - if (mutt_account_getlogin(&mdata->conn->account) < 0) + if (mutt_account_getlogin(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - if (mutt_account_getpass(&mdata->conn->account) < 0) + if (mutt_account_getpass(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - imap_cmd_start(mdata, "AUTHENTICATE CRAM-MD5"); + imap_cmd_start(adata, "AUTHENTICATE CRAM-MD5"); /* From RFC2195: * The data encoded in the first ready response contains a presumptively @@ -122,7 +122,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *meth * correspond to that of an RFC822 'msg-id' [RFC822] as described in [POP3]. */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) @@ -131,7 +131,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *meth goto bail; } - len = mutt_b64_decode(mdata->buf + 2, obuf, sizeof(obuf)); + len = mutt_b64_decode(adata->buf + 2, obuf, sizeof(obuf)); if (len == -1) { mutt_debug(1, "Error decoding base64 response.\n"); @@ -152,9 +152,9 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *meth * around them when the bug report comes in. Until then, we'll remain * blissfully RFC-compliant. */ - hmac_md5(mdata->conn->account.pass, obuf, hmac_response); + hmac_md5(adata->conn->account.pass, obuf, hmac_response); /* dubious optimisation I saw elsewhere: make the whole string in one call */ - int off = snprintf(obuf, sizeof(obuf), "%s ", mdata->conn->account.user); + int off = snprintf(obuf, sizeof(obuf), "%s ", adata->conn->account.user); mutt_md5_toascii(hmac_response, obuf + off); mutt_debug(2, "CRAM response: %s\n", obuf); @@ -162,10 +162,10 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *meth * plus the additional debris */ mutt_b64_encode(obuf, strlen(obuf), ibuf, sizeof(ibuf) - 2); mutt_str_strcat(ibuf, sizeof(ibuf), "\r\n"); - mutt_socket_send(mdata->conn, ibuf); + mutt_socket_send(adata->conn, ibuf); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_OK) @@ -174,7 +174,7 @@ enum ImapAuthRes imap_auth_cram_md5(struct ImapMboxData *mdata, const char *meth goto bail; } - if (imap_code(mdata->buf)) + if (imap_code(adata->buf)) return IMAP_AUTH_SUCCESS; bail: diff --git a/imap/auth_gss.c b/imap/auth_gss.c index 30ae16aa5..558476ad5 100644 --- a/imap/auth_gss.c +++ b/imap/auth_gss.c @@ -102,11 +102,11 @@ static void print_gss_error(OM_uint32 err_maj, OM_uint32 err_min) /** * imap_auth_gss - GSS Authentication support - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_gss(struct ImapAccountData *adata, const char *method) { gss_buffer_desc request_buf, send_token; gss_buffer_t sec_token; @@ -121,14 +121,14 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) unsigned long buf_size; int rc; - if (!mutt_bit_isset(mdata->capabilities, AGSSAPI)) + if (!mutt_bit_isset(adata->capabilities, AGSSAPI)) return IMAP_AUTH_UNAVAIL; - if (mutt_account_getuser(&mdata->conn->account) < 0) + if (mutt_account_getuser(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; /* get an IMAP service ticket for the server */ - snprintf(buf1, sizeof(buf1), "imap@%s", mdata->conn->account.host); + snprintf(buf1, sizeof(buf1), "imap@%s", adata->conn->account.host); request_buf.value = buf1; request_buf.length = strlen(buf1); maj_stat = gss_import_name(&min_stat, &request_buf, gss_nt_service_name, &target_name); @@ -164,11 +164,11 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) /* now begin login */ mutt_message(_("Authenticating (GSSAPI)...")); - imap_cmd_start(mdata, "AUTHENTICATE GSSAPI"); + imap_cmd_start(adata, "AUTHENTICATE GSSAPI"); /* expect a null continuation response ("+") */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) @@ -183,13 +183,13 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); gss_release_buffer(&min_stat, &send_token); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); - mutt_socket_send(mdata->conn, buf1); + mutt_socket_send(adata->conn, buf1); while (maj_stat == GSS_S_CONTINUE_NEEDED) { /* Read server data */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) @@ -199,7 +199,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) goto bail; } - request_buf.length = mutt_b64_decode(mdata->buf + 2, buf2, sizeof(buf2)); + request_buf.length = mutt_b64_decode(adata->buf + 2, buf2, sizeof(buf2)); request_buf.value = buf2; sec_token = &request_buf; @@ -219,14 +219,14 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); gss_release_buffer(&min_stat, &send_token); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); - mutt_socket_send(mdata->conn, buf1); + mutt_socket_send(adata->conn, buf1); } gss_release_name(&min_stat, &target_name); /* get security flags and buffer size */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) @@ -234,7 +234,7 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) mutt_debug(1, "#2 Error receiving server response.\n"); goto bail; } - request_buf.length = mutt_b64_decode(mdata->buf + 2, buf2, sizeof(buf2)); + request_buf.length = mutt_b64_decode(adata->buf + 2, buf2, sizeof(buf2)); request_buf.value = buf2; maj_stat = gss_unwrap(&min_stat, context, &request_buf, &send_token, &cflags, &quality); @@ -271,9 +271,9 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) memcpy(buf1, &buf_size, 4); buf1[0] = GSS_AUTH_P_NONE; /* server decides if principal can log in as user */ - strncpy(buf1 + 4, mdata->conn->account.user, sizeof(buf1) - 4); + strncpy(buf1 + 4, adata->conn->account.user, sizeof(buf1) - 4); request_buf.value = buf1; - request_buf.length = 4 + strlen(mdata->conn->account.user); + request_buf.length = 4 + strlen(adata->conn->account.user); maj_stat = gss_wrap(&min_stat, context, 0, GSS_C_QOP_DEFAULT, &request_buf, &cflags, &send_token); if (maj_stat != GSS_S_COMPLETE) @@ -283,20 +283,20 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) } mutt_b64_encode(send_token.value, send_token.length, buf1, sizeof(buf1) - 2); - mutt_debug(2, "Requesting authorisation as %s\n", mdata->conn->account.user); + mutt_debug(2, "Requesting authorisation as %s\n", adata->conn->account.user); mutt_str_strcat(buf1, sizeof(buf1), "\r\n"); - mutt_socket_send(mdata->conn, buf1); + mutt_socket_send(adata->conn, buf1); /* Joy of victory or agony of defeat? */ do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc == IMAP_CMD_RESPOND) { mutt_debug(1, "Unexpected server continuation request.\n"); goto err_abort_cmd; } - if (imap_code(mdata->buf)) + if (imap_code(adata->buf)) { /* flush the security context */ mutt_debug(2, "Releasing GSS credentials\n"); @@ -316,9 +316,9 @@ enum ImapAuthRes imap_auth_gss(struct ImapMboxData *mdata, const char *method) goto bail; err_abort_cmd: - mutt_socket_send(mdata->conn, "*\r\n"); + mutt_socket_send(adata->conn, "*\r\n"); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); bail: diff --git a/imap/auth_login.c b/imap/auth_login.c index 8a8bcfb34..95ee619ea 100644 --- a/imap/auth_login.c +++ b/imap/auth_login.c @@ -38,40 +38,40 @@ /** * imap_auth_login - Plain LOGIN support - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_login(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_login(struct ImapAccountData *adata, const char *method) { char q_user[STRING], q_pass[STRING]; char buf[LONG_STRING]; int rc; - if (mutt_bit_isset(mdata->capabilities, LOGINDISABLED)) + if (mutt_bit_isset(adata->capabilities, LOGINDISABLED)) { mutt_message(_("LOGIN disabled on this server")); return IMAP_AUTH_UNAVAIL; } - if (mutt_account_getuser(&mdata->conn->account) < 0) + if (mutt_account_getuser(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - if (mutt_account_getpass(&mdata->conn->account) < 0) + if (mutt_account_getpass(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; mutt_message(_("Logging in...")); - imap_quote_string(q_user, sizeof(q_user), mdata->conn->account.user, false); - imap_quote_string(q_pass, sizeof(q_pass), mdata->conn->account.pass, false); + imap_quote_string(q_user, sizeof(q_user), adata->conn->account.user, false); + imap_quote_string(q_pass, sizeof(q_pass), adata->conn->account.pass, false); /* don't print the password unless we're at the ungodly debugging level * of 5 or higher */ if (DebugLevel < IMAP_LOG_PASS) - mutt_debug(2, "Sending LOGIN command for %s...\n", mdata->conn->account.user); + mutt_debug(2, "Sending LOGIN command for %s...\n", adata->conn->account.user); snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass); - rc = imap_exec(mdata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS); + rc = imap_exec(adata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS); if (!rc) { diff --git a/imap/auth_oauth.c b/imap/auth_oauth.c index 353cae778..1c6e75b01 100644 --- a/imap/auth_oauth.c +++ b/imap/auth_oauth.c @@ -40,11 +40,11 @@ /** * imap_auth_oauth - Authenticate an IMAP connection using OAUTHBEARER - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method (UNUSED) * @retval num Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_oauth(struct ImapAccountData *adata, const char *method) { char *ibuf = NULL; char *oauthbearer = NULL; @@ -52,8 +52,8 @@ enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method) int rc; /* For now, we only support SASL_IR also and over TLS */ - if (!mutt_bit_isset(mdata->capabilities, AUTH_OAUTHBEARER) || - !mutt_bit_isset(mdata->capabilities, SASL_IR) || !mdata->conn->ssf) + if (!mutt_bit_isset(adata->capabilities, AUTH_OAUTHBEARER) || + !mutt_bit_isset(adata->capabilities, SASL_IR) || !adata->conn->ssf) { return IMAP_AUTH_UNAVAIL; } @@ -61,7 +61,7 @@ enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method) mutt_message(_("Authenticating (OAUTHBEARER)...")); /* We get the access token from the imap_oauth_refresh_command */ - oauthbearer = mutt_account_getoauthbearer(&mdata->conn->account); + oauthbearer = mutt_account_getoauthbearer(&adata->conn->account); if (!oauthbearer) return IMAP_AUTH_FAILURE; @@ -72,7 +72,7 @@ enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method) /* This doesn't really contain a password, but the token is good for * an hour, so suppress it anyways. */ - rc = imap_exec(mdata, ibuf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS); + rc = imap_exec(adata, ibuf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS); FREE(&oauthbearer); FREE(&ibuf); @@ -82,8 +82,8 @@ enum ImapAuthRes imap_auth_oauth(struct ImapMboxData *mdata, const char *method) /* The error response was in SASL continuation, so continue the SASL * to cause a failure and exit SASL input. See RFC 7628 3.2.3 */ - mutt_socket_send(mdata->conn, "\001"); - rc = imap_exec(mdata, ibuf, IMAP_CMD_FAIL_OK); + mutt_socket_send(adata->conn, "\001"); + rc = imap_exec(adata, ibuf, IMAP_CMD_FAIL_OK); } if (!rc) diff --git a/imap/auth_plain.c b/imap/auth_plain.c index fcbb6afac..723f9b97a 100644 --- a/imap/auth_plain.c +++ b/imap/auth_plain.c @@ -38,53 +38,53 @@ /** * imap_auth_plain - SASL PLAIN support - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_plain(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_plain(struct ImapAccountData *adata, const char *method) { int rc = IMAP_CMD_CONTINUE; enum ImapAuthRes res = IMAP_AUTH_SUCCESS; static const char auth_plain_cmd[] = "AUTHENTICATE PLAIN"; char buf[STRING] = { 0 }; - if (mutt_account_getuser(&mdata->conn->account) < 0) + if (mutt_account_getuser(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - if (mutt_account_getpass(&mdata->conn->account) < 0) + if (mutt_account_getpass(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; mutt_message(_("Logging in...")); /* Prepare full AUTHENTICATE PLAIN message */ - mutt_sasl_plain_msg(buf, sizeof(buf), auth_plain_cmd, mdata->conn->account.user, - mdata->conn->account.user, mdata->conn->account.pass); + 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(mdata->capabilities, SASL_IR)) + if (mutt_bit_isset(adata->capabilities, SASL_IR)) { - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); } else { /* Split the message so we send AUTHENTICATE PLAIN first, and the * credentials after the first command continuation request */ buf[sizeof(auth_plain_cmd) - 1] = '\0'; - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); while (rc == IMAP_CMD_CONTINUE) { - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); } if (rc == IMAP_CMD_RESPOND) { mutt_str_strcat(buf + sizeof(auth_plain_cmd), sizeof(buf) - sizeof(auth_plain_cmd), "\r\n"); - mutt_socket_send(mdata->conn, buf + sizeof(auth_plain_cmd)); + mutt_socket_send(adata->conn, buf + sizeof(auth_plain_cmd)); } } while (rc == IMAP_CMD_CONTINUE) { - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); } if (rc == IMAP_CMD_BAD) diff --git a/imap/auth_sasl.c b/imap/auth_sasl.c index c56c09114..de760db52 100644 --- a/imap/auth_sasl.c +++ b/imap/auth_sasl.c @@ -42,11 +42,11 @@ /** * imap_auth_sasl - Default authenticator if available - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param method Name of this authentication method * @retval enum Result, e.g. #IMAP_AUTH_SUCCESS */ -enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) +enum ImapAuthRes imap_auth_sasl(struct ImapAccountData *adata, const char *method) { sasl_conn_t *saslconn = NULL; sasl_interact_t *interaction = NULL; @@ -58,7 +58,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) unsigned int len = 0, olen = 0; bool client_start; - if (mutt_sasl_client_new(mdata->conn, &saslconn) < 0) + if (mutt_sasl_client_new(adata->conn, &saslconn) < 0) { mutt_debug(1, "Error allocating SASL connection.\n"); return IMAP_AUTH_FAILURE; @@ -69,25 +69,25 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) /* If the user hasn't specified a method, use any available */ if (!method) { - method = mdata->capstr; + method = adata->capstr; /* hack for SASL ANONYMOUS support: * 1. Fetch username. If it's "" or "anonymous" then * 2. attempt sasl_client_start with only "AUTH=ANONYMOUS" capability * 3. if sasl_client_start fails, fall through... */ - if (mutt_account_getuser(&mdata->conn->account) < 0) + if (mutt_account_getuser(&adata->conn->account) < 0) return IMAP_AUTH_FAILURE; - if (mutt_bit_isset(mdata->capabilities, AUTH_ANON) && - (!mdata->conn->account.user[0] || - (mutt_str_strncmp(mdata->conn->account.user, "anonymous", 9) == 0))) + if (mutt_bit_isset(adata->capabilities, AUTH_ANON) && + (!adata->conn->account.user[0] || + (mutt_str_strncmp(adata->conn->account.user, "anonymous", 9) == 0))) { rc = sasl_client_start(saslconn, "AUTH=ANONYMOUS", NULL, &pc, &olen, &mech); } } else if ((mutt_str_strcasecmp("login", method) == 0) && - !strstr(NONULL(mdata->capstr), "AUTH=LOGIN")) + !strstr(NONULL(adata->capstr), "AUTH=LOGIN")) { /* do not use SASL login for regular IMAP login (#3556) */ return IMAP_AUTH_UNAVAIL; @@ -126,7 +126,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) buf = mutt_mem_malloc(bufsize); snprintf(buf, bufsize, "AUTHENTICATE %s", mech); - if (mutt_bit_isset(mdata->capabilities, SASL_IR) && client_start) + if (mutt_bit_isset(adata->capabilities, SASL_IR) && client_start) { len = mutt_str_strlen(buf); buf[len++] = ' '; @@ -138,14 +138,14 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) client_start = false; olen = 0; } - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); irc = IMAP_CMD_CONTINUE; /* looping protocol */ while (rc == SASL_CONTINUE || olen > 0) { do - irc = imap_cmd_step(mdata); + irc = imap_cmd_step(adata); while (irc == IMAP_CMD_CONTINUE); if (irc == IMAP_CMD_BAD || irc == IMAP_CMD_NO) @@ -154,14 +154,14 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) if (irc == IMAP_CMD_RESPOND) { /* Exchange incorrectly returns +\r\n instead of + \r\n */ - if (mdata->buf[1] == '\0') + if (adata->buf[1] == '\0') { buf[0] = '\0'; len = 0; } else { - len = strlen(mdata->buf + 2); + len = strlen(adata->buf + 2); if (len > bufsize) { bufsize = len; @@ -169,7 +169,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) } /* For sasl_decode64, the fourth parameter, outmax, doesn't * include space for the trailing null */ - if (sasl_decode64(mdata->buf + 2, len, buf, bufsize - 1, &len) != SASL_OK) + if (sasl_decode64(adata->buf + 2, len, buf, bufsize - 1, &len) != SASL_OK) { mutt_debug(1, "error base64-decoding server response.\n"); goto bail; @@ -210,13 +210,13 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) if (irc == IMAP_CMD_RESPOND) { mutt_str_strfcpy(buf + olen, "\r\n", bufsize - olen); - mutt_socket_send(mdata->conn, buf); + mutt_socket_send(adata->conn, buf); } /* If SASL has errored out, send an abort string to the server */ if (rc < 0) { - mutt_socket_send(mdata->conn, "*\r\n"); + mutt_socket_send(adata->conn, "*\r\n"); mutt_debug(1, "sasl_client_step error %d\n", rc); } @@ -225,7 +225,7 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) while (irc != IMAP_CMD_OK) { - irc = imap_cmd_step(mdata); + irc = imap_cmd_step(adata); if (irc != IMAP_CMD_CONTINUE) break; } @@ -233,9 +233,9 @@ enum ImapAuthRes imap_auth_sasl(struct ImapMboxData *mdata, const char *method) if (rc != SASL_OK) goto bail; - if (imap_code(mdata->buf)) + if (imap_code(adata->buf)) { - mutt_sasl_setup_conn(mdata->conn, saslconn); + mutt_sasl_setup_conn(adata->conn, saslconn); FREE(&buf); return IMAP_AUTH_SUCCESS; } diff --git a/imap/browse.c b/imap/browse.c index b77c7326e..6db41c61f 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -135,14 +135,14 @@ static void add_folder(char delim, char *folder, bool noselect, bool noinferiors /** * browse_add_list_result - Add entries to the folder browser - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param cmd Command string from server * @param state Browser state to add to * @param isparent Is this a shortcut for the parent directory? * @retval 0 Success * @retval -1 Failure */ -static int browse_add_list_result(struct ImapMboxData *mdata, const char *cmd, +static int browse_add_list_result(struct ImapAccountData *adata, const char *cmd, struct BrowserState *state, bool isparent) { struct ImapList list; @@ -155,13 +155,13 @@ static int browse_add_list_result(struct ImapMboxData *mdata, const char *cmd, return -1; } - imap_cmd_start(mdata, cmd); - mdata->cmdtype = IMAP_CT_LIST; - mdata->cmddata = &list; + imap_cmd_start(adata, cmd); + adata->cmdtype = IMAP_CT_LIST; + adata->cmddata = &list; do { list.name = NULL; - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc == IMAP_CMD_CONTINUE && list.name) { @@ -173,7 +173,7 @@ static int browse_add_list_result(struct ImapMboxData *mdata, const char *cmd, add_folder(list.delim, list.name, list.noselect, list.noinferiors, state, isparent); } } while (rc == IMAP_CMD_CONTINUE); - mdata->cmddata = NULL; + adata->cmddata = NULL; FREE(&mx.mbox); return (rc == IMAP_CMD_OK) ? 0 : -1; @@ -190,7 +190,7 @@ static int browse_add_list_result(struct ImapMboxData *mdata, const char *cmd, */ int imap_browse(char *path, struct BrowserState *state) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct ImapList list; char buf[PATH_MAX]; char mbox[PATH_MAX]; @@ -212,8 +212,8 @@ int imap_browse(char *path, struct BrowserState *state) ImapCheckSubscribed = false; mutt_str_strfcpy(list_cmd, ImapListSubscribed ? "LSUB" : "LIST", sizeof(list_cmd)); - mdata = imap_conn_find(&(mx.account), 0); - if (!mdata) + adata = imap_conn_find(&(mx.account), 0); + if (!adata) goto fail; mutt_message(_("Getting folder list...")); @@ -221,7 +221,7 @@ int imap_browse(char *path, struct BrowserState *state) /* skip check for parents when at the root */ if (mx.mbox && mx.mbox[0] != '\0') { - imap_fix_path(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox)); n = mutt_str_strlen(mbox); } else @@ -237,15 +237,15 @@ int imap_browse(char *path, struct BrowserState *state) /* if our target exists and has inferiors, enter it if we * aren't already going to */ - imap_munge_mbox_name(mdata, munged_mbox, sizeof(munged_mbox), mbox); + imap_munge_mbox_name(adata, munged_mbox, sizeof(munged_mbox), mbox); snprintf(buf, sizeof(buf), "%s \"\" %s", list_cmd, munged_mbox); - imap_cmd_start(mdata, buf); - mdata->cmdtype = IMAP_CT_LIST; - mdata->cmddata = &list; + imap_cmd_start(adata, buf); + adata->cmdtype = IMAP_CT_LIST; + adata->cmddata = &list; do { list.name = 0; - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc == IMAP_CMD_CONTINUE && list.name) { if (!list.noinferiors && list.name[0] && @@ -256,7 +256,7 @@ int imap_browse(char *path, struct BrowserState *state) } } } while (rc == IMAP_CMD_CONTINUE); - mdata->cmddata = NULL; + adata->cmddata = NULL; /* if we're descending a folder, mark it as current in browser_state */ if (mbox[n - 1] == list.delim) @@ -305,9 +305,9 @@ int imap_browse(char *path, struct BrowserState *state) { char relpath[2]; /* folder may be "/" */ - snprintf(relpath, sizeof(relpath), "%c", n < 0 ? '\0' : mdata->delim); + snprintf(relpath, sizeof(relpath), "%c", n < 0 ? '\0' : adata->delim); if (showparents) - add_folder(mdata->delim, relpath, true, false, state, true); + add_folder(adata->delim, relpath, true, false, state, true); if (!state->folder) { imap_qualify_path(buf, sizeof(buf), &mx, relpath); @@ -325,10 +325,10 @@ int imap_browse(char *path, struct BrowserState *state) mutt_debug(3, "Quoting mailbox scan: %s -> ", mbox); snprintf(buf, sizeof(buf), "%s%%", mbox); - imap_munge_mbox_name(mdata, munged_mbox, sizeof(munged_mbox), buf); + imap_munge_mbox_name(adata, munged_mbox, sizeof(munged_mbox), buf); mutt_debug(3, "%s\n", munged_mbox); snprintf(buf, sizeof(buf), "%s \"\" %s", list_cmd, munged_mbox); - if (browse_add_list_result(mdata, buf, state, false)) + if (browse_add_list_result(adata, buf, state, false)) goto fail; if (state->entrylen == 0) @@ -362,7 +362,7 @@ fail: */ int imap_mailbox_create(const char *folder) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct ImapMbox mx; char buf[PATH_MAX]; short n; @@ -373,8 +373,8 @@ int imap_mailbox_create(const char *folder) return -1; } - mdata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); - if (!mdata) + adata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!adata) { mutt_debug(1, "Couldn't find open connection to %s\n", mx.account.host); goto fail; @@ -384,9 +384,9 @@ int imap_mailbox_create(const char *folder) /* append a delimiter if necessary */ n = mutt_str_strlen(buf); - if (n && (n < sizeof(buf) - 1) && (buf[n - 1] != mdata->delim)) + if (n && (n < sizeof(buf) - 1) && (buf[n - 1] != adata->delim)) { - buf[n++] = mdata->delim; + buf[n++] = adata->delim; buf[n] = '\0'; } @@ -399,7 +399,7 @@ int imap_mailbox_create(const char *folder) goto fail; } - if (imap_create_mailbox(mdata, buf) < 0) + if (imap_create_mailbox(adata, buf) < 0) goto fail; mutt_message(_("Mailbox created")); @@ -423,7 +423,7 @@ fail: */ int imap_mailbox_rename(const char *mailbox) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct ImapMbox mx; char buf[PATH_MAX]; char newname[PATH_MAX]; @@ -434,8 +434,8 @@ int imap_mailbox_rename(const char *mailbox) return -1; } - mdata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); - if (!mdata) + adata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!adata) { mutt_debug(1, "Couldn't find open connection to %s\n", mx.account.host); goto fail; @@ -459,11 +459,11 @@ int imap_mailbox_rename(const char *mailbox) goto fail; } - imap_fix_path(mdata, newname, buf, sizeof(buf)); + imap_fix_path(adata, newname, buf, sizeof(buf)); - if (imap_rename_mailbox(mdata, &mx, buf) < 0) + if (imap_rename_mailbox(adata, &mx, buf) < 0) { - mutt_error(_("Rename failed: %s"), imap_get_qualifier(mdata->buf)); + mutt_error(_("Rename failed: %s"), imap_get_qualifier(adata->buf)); goto fail; } diff --git a/imap/command.c b/imap/command.c index 3c9a379b3..ccacd751b 100644 --- a/imap/command.c +++ b/imap/command.c @@ -78,12 +78,12 @@ static const char *const Capabilities[] = { /** * cmd_queue_full - Is the IMAP command queue full? - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval true Queue is full */ -static bool cmd_queue_full(struct ImapMboxData *mdata) +static bool cmd_queue_full(struct ImapAccountData *adata) { - if ((mdata->nextcmd + 1) % mdata->cmdslots == mdata->lastcmd) + if ((adata->nextcmd + 1) % adata->cmdslots == adata->lastcmd) return true; return false; @@ -91,26 +91,26 @@ static bool cmd_queue_full(struct ImapMboxData *mdata) /** * cmd_new - Create and queue a new command control block - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval NULL if the pipeline is full * @retval ptr New command */ -static struct ImapCommand *cmd_new(struct ImapMboxData *mdata) +static struct ImapCommand *cmd_new(struct ImapAccountData *adata) { struct ImapCommand *cmd = NULL; - if (cmd_queue_full(mdata)) + if (cmd_queue_full(adata)) { mutt_debug(3, "IMAP command queue full\n"); return NULL; } - cmd = mdata->cmds + mdata->nextcmd; - mdata->nextcmd = (mdata->nextcmd + 1) % mdata->cmdslots; + cmd = adata->cmds + adata->nextcmd; + adata->nextcmd = (adata->nextcmd + 1) % adata->cmdslots; - snprintf(cmd->seq, sizeof(cmd->seq), "a%04u", mdata->seqno++); - if (mdata->seqno > 9999) - mdata->seqno = 0; + snprintf(cmd->seq, sizeof(cmd->seq), "a%04u", adata->seqno++); + if (adata->seqno > 9999) + adata->seqno = 0; cmd->state = IMAP_CMD_NEW; @@ -119,7 +119,7 @@ static struct ImapCommand *cmd_new(struct ImapMboxData *mdata) /** * cmd_queue - Add a IMAP command to the queue - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param cmdstr Command string * @param flags Server flags, e.g. #IMAP_CMD_POLL * @retval 0 Success @@ -127,89 +127,89 @@ static struct ImapCommand *cmd_new(struct ImapMboxData *mdata) * * If the queue is full, attempts to drain it. */ -static int cmd_queue(struct ImapMboxData *mdata, const char *cmdstr, int flags) +static int cmd_queue(struct ImapAccountData *adata, const char *cmdstr, int flags) { - if (cmd_queue_full(mdata)) + if (cmd_queue_full(adata)) { mutt_debug(3, "Draining IMAP command pipeline\n"); - const int rc = imap_exec(mdata, NULL, IMAP_CMD_FAIL_OK | (flags & IMAP_CMD_POLL)); + const int rc = imap_exec(adata, NULL, IMAP_CMD_FAIL_OK | (flags & IMAP_CMD_POLL)); if (rc < 0 && rc != -2) return rc; } - struct ImapCommand *cmd = cmd_new(mdata); + struct ImapCommand *cmd = cmd_new(adata); if (!cmd) return IMAP_CMD_BAD; - if (mutt_buffer_printf(mdata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0) + if (mutt_buffer_printf(adata->cmdbuf, "%s %s\r\n", cmd->seq, cmdstr) < 0) return IMAP_CMD_BAD; return 0; } /** - * cmd_handle_fatal - When ImapMboxData is in fatal state, do what we can - * @param mdata Imap Mailbox data + * cmd_handle_fatal - When ImapAccountData is in fatal state, do what we can + * @param adata Imap Account data */ -static void cmd_handle_fatal(struct ImapMboxData *mdata) +static void cmd_handle_fatal(struct ImapAccountData *adata) { - mdata->status = IMAP_FATAL; + adata->status = IMAP_FATAL; - if ((mdata->state >= IMAP_SELECTED) && (mdata->reopen & IMAP_REOPEN_ALLOW)) + if ((adata->state >= IMAP_SELECTED) && (adata->reopen & IMAP_REOPEN_ALLOW)) { - mx_fastclose_mailbox(mdata->ctx); - mutt_socket_close(mdata->conn); - mutt_error(_("Mailbox %s@%s closed"), mdata->conn->account.login, - mdata->conn->account.host); - mdata->state = IMAP_DISCONNECTED; + mx_fastclose_mailbox(adata->ctx); + mutt_socket_close(adata->conn); + mutt_error(_("Mailbox %s@%s closed"), adata->conn->account.login, + adata->conn->account.host); + adata->state = IMAP_DISCONNECTED; } - imap_close_connection(mdata); - if (!mdata->recovering) + imap_close_connection(adata); + if (!adata->recovering) { - mdata->recovering = true; - if (imap_conn_find(&mdata->conn->account, 0)) + adata->recovering = true; + if (imap_conn_find(&adata->conn->account, 0)) mutt_clear_error(); - mdata->recovering = false; + adata->recovering = false; } } /** * cmd_start - Start a new IMAP command - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param cmdstr Command string * @param flags Command flags, e.g. #IMAP_CMD_QUEUE * @retval 0 Success * @retval <0 Failure, e.g. #IMAP_CMD_BAD */ -static int cmd_start(struct ImapMboxData *mdata, const char *cmdstr, int flags) +static int cmd_start(struct ImapAccountData *adata, const char *cmdstr, int flags) { int rc; - if (mdata->status == IMAP_FATAL) + if (adata->status == IMAP_FATAL) { - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return -1; } - if (cmdstr && ((rc = cmd_queue(mdata, cmdstr, flags)) < 0)) + if (cmdstr && ((rc = cmd_queue(adata, cmdstr, flags)) < 0)) return rc; if (flags & IMAP_CMD_QUEUE) return 0; - if (mdata->cmdbuf->dptr == mdata->cmdbuf->data) + if (adata->cmdbuf->dptr == adata->cmdbuf->data) return IMAP_CMD_BAD; - rc = mutt_socket_send_d(mdata->conn, mdata->cmdbuf->data, + rc = mutt_socket_send_d(adata->conn, adata->cmdbuf->data, (flags & IMAP_CMD_PASS) ? IMAP_LOG_PASS : IMAP_LOG_CMD); - mdata->cmdbuf->dptr = mdata->cmdbuf->data; + adata->cmdbuf->dptr = adata->cmdbuf->data; /* unidle when command queue is flushed */ - if (mdata->state == IMAP_IDLE) - mdata->state = IMAP_SELECTED; + if (adata->state == IMAP_IDLE) + adata->state = IMAP_SELECTED; return (rc < 0) ? IMAP_CMD_BAD : 0; } @@ -234,23 +234,23 @@ static int cmd_status(const char *s) /** * cmd_parse_expunge - Parse expunge command - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s String containing MSN of message to expunge * - * cmd_parse_expunge: mark headers with new sequence ID and mark mdata to be + * cmd_parse_expunge: mark headers with new sequence ID and mark adata to be * reopened at our earliest convenience */ -static void cmd_parse_expunge(struct ImapMboxData *mdata, const char *s) +static void cmd_parse_expunge(struct ImapAccountData *adata, const char *s) { unsigned int exp_msn; struct Email *e = NULL; mutt_debug(2, "Handling EXPUNGE\n"); - if (mutt_str_atoui(s, &exp_msn) < 0 || exp_msn < 1 || exp_msn > mdata->max_msn) + if (mutt_str_atoui(s, &exp_msn) < 0 || exp_msn < 1 || exp_msn > adata->max_msn) return; - e = mdata->msn_index[exp_msn - 1]; + e = adata->msn_index[exp_msn - 1]; if (e) { /* imap_expunge_mailbox() will rewrite e->index. @@ -261,29 +261,29 @@ static void cmd_parse_expunge(struct ImapMboxData *mdata, const char *s) } /* decrement seqno of those above. */ - for (unsigned int cur = exp_msn; cur < mdata->max_msn; cur++) + for (unsigned int cur = exp_msn; cur < adata->max_msn; cur++) { - e = mdata->msn_index[cur]; + e = adata->msn_index[cur]; if (e) IMAP_EDATA(e)->msn--; - mdata->msn_index[cur - 1] = e; + adata->msn_index[cur - 1] = e; } - mdata->msn_index[mdata->max_msn - 1] = NULL; - mdata->max_msn--; + adata->msn_index[adata->max_msn - 1] = NULL; + adata->max_msn--; - mdata->reopen |= IMAP_EXPUNGE_PENDING; + adata->reopen |= IMAP_EXPUNGE_PENDING; } /** * cmd_parse_vanished - Parse vanished command - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s String containing MSN of message to expunge * * Handle VANISHED (RFC7162), which is like expunge, but passes a seqset of UIDs. * An optional (EARLIER) argument specifies not to decrement subsequent MSNs. */ -static void cmd_parse_vanished(struct ImapMboxData *mdata, char *s) +static void cmd_parse_vanished(struct ImapAccountData *adata, char *s) { bool earlier = false; int rc; @@ -317,7 +317,7 @@ static void cmd_parse_vanished(struct ImapMboxData *mdata, char *s) while ((rc = mutt_seqset_iterator_next(iter, &uid)) == 0) { - struct Email *e = mutt_hash_int_find(mdata->uid_hash, uid); + struct Email *e = mutt_hash_int_find(adata->uid_hash, uid); if (!e) continue; @@ -329,53 +329,53 @@ static void cmd_parse_vanished(struct ImapMboxData *mdata, char *s) e->index = INT_MAX; IMAP_EDATA(e)->msn = 0; - if ((exp_msn < 1) || (exp_msn > mdata->max_msn)) + if ((exp_msn < 1) || (exp_msn > adata->max_msn)) { mutt_debug(1, "VANISHED: msn for UID %u is incorrect.\n", uid); continue; } - if (mdata->msn_index[exp_msn - 1] != e) + if (adata->msn_index[exp_msn - 1] != e) { mutt_debug(1, "VANISHED: msn_index for UID %u is incorrect.\n", uid); continue; } - mdata->msn_index[exp_msn - 1] = NULL; + adata->msn_index[exp_msn - 1] = NULL; if (!earlier) { /* decrement seqno of those above. */ - for (unsigned int cur = exp_msn; cur < mdata->max_msn; cur++) + for (unsigned int cur = exp_msn; cur < adata->max_msn; cur++) { - e = mdata->msn_index[cur]; + e = adata->msn_index[cur]; if (e) IMAP_EDATA(e)->msn--; - mdata->msn_index[cur - 1] = e; + adata->msn_index[cur - 1] = e; } - mdata->msn_index[mdata->max_msn - 1] = NULL; - mdata->max_msn--; + adata->msn_index[adata->max_msn - 1] = NULL; + adata->max_msn--; } } if (rc < 0) mutt_debug(1, "VANISHED: illegal seqset %s\n", s); - mdata->reopen |= IMAP_EXPUNGE_PENDING; + adata->reopen |= IMAP_EXPUNGE_PENDING; mutt_seqset_iterator_free(&iter); } /** - * cmd_parse_fetch - Load fetch response into ImapMboxData - * @param mdata Imap Mailbox data + * cmd_parse_fetch - Load fetch response into ImapAccountData + * @param adata Imap Account data * @param s String containing MSN of message to fetch * * Currently only handles unanticipated FETCH responses, and only FLAGS data. * We get these if another client has changed flags for a mailbox we've * selected. Of course, a lot of code here duplicates code in message.c. */ -static void cmd_parse_fetch(struct ImapMboxData *mdata, char *s) +static void cmd_parse_fetch(struct ImapAccountData *adata, char *s) { unsigned int msn, uid; struct Email *e = NULL; @@ -391,13 +391,13 @@ static void cmd_parse_fetch(struct ImapMboxData *mdata, char *s) return; } - if ((msn < 1) || (msn > mdata->max_msn)) + if ((msn < 1) || (msn > adata->max_msn)) { mutt_debug(3, "Skipping FETCH response - MSN %u out of range\n", msn); return; } - e = mdata->msn_index[msn - 1]; + e = adata->msn_index[msn - 1]; if (!e || !e->active) { mutt_debug(3, "Skipping FETCH response - MSN %u not in msn_index\n", msn); @@ -494,24 +494,24 @@ static void cmd_parse_fetch(struct ImapMboxData *mdata, char *s) if (flags) { - imap_set_flags(mdata, e, flags, &server_changes); + imap_set_flags(adata, e, flags, &server_changes); if (server_changes) { /* If server flags could conflict with mutt's flags, reopen the mailbox. */ if (e->changed) - mdata->reopen |= IMAP_EXPUNGE_PENDING; + adata->reopen |= IMAP_EXPUNGE_PENDING; else - mdata->check_status = IMAP_FLAGS_PENDING; + adata->check_status = IMAP_FLAGS_PENDING; } } } /** * cmd_parse_capability - set capability bits according to CAPABILITY response - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with capabilities */ -static void cmd_parse_capability(struct ImapMboxData *mdata, char *s) +static void cmd_parse_capability(struct ImapAccountData *adata, char *s) { mutt_debug(3, "Handling CAPABILITY\n"); @@ -519,10 +519,10 @@ static void cmd_parse_capability(struct ImapMboxData *mdata, char *s) char *bracket = strchr(s, ']'); if (bracket) *bracket = '\0'; - FREE(&mdata->capstr); - mdata->capstr = mutt_str_strdup(s); + FREE(&adata->capstr); + adata->capstr = mutt_str_strdup(s); - memset(mdata->capabilities, 0, sizeof(mdata->capabilities)); + memset(adata->capabilities, 0, sizeof(adata->capabilities)); while (*s) { @@ -530,7 +530,7 @@ static void cmd_parse_capability(struct ImapMboxData *mdata, char *s) { if (mutt_str_word_casecmp(Capabilities[i], s) == 0) { - mutt_bit_set(mdata->capabilities, i); + mutt_bit_set(adata->capabilities, i); mutt_debug(4, " Found capability \"%s\": %d\n", Capabilities[i], i); break; } @@ -541,18 +541,18 @@ static void cmd_parse_capability(struct ImapMboxData *mdata, char *s) /** * cmd_parse_list - Parse a server LIST command (list mailboxes) - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with folder list */ -static void cmd_parse_list(struct ImapMboxData *mdata, char *s) +static void cmd_parse_list(struct ImapAccountData *adata, char *s) { struct ImapList *list = NULL; struct ImapList lb; char delimbuf[5]; /* worst case: "\\"\0 */ unsigned int litlen; - if (mdata->cmddata && mdata->cmdtype == IMAP_CT_LIST) - list = mdata->cmddata; + if (adata->cmddata && adata->cmdtype == IMAP_CT_LIST) + list = adata->cmddata; else list = &lb; @@ -595,32 +595,32 @@ static void cmd_parse_list(struct ImapMboxData *mdata, char *s) /* Notes often responds with literals here. We need a real tokenizer. */ if (imap_get_literal_count(s, &litlen) == 0) { - if (imap_cmd_step(mdata) != IMAP_CMD_CONTINUE) + if (imap_cmd_step(adata) != IMAP_CMD_CONTINUE) { - mdata->status = IMAP_FATAL; + adata->status = IMAP_FATAL; return; } - list->name = mdata->buf; + list->name = adata->buf; } else { - imap_unmunge_mbox_name(mdata, s); + imap_unmunge_mbox_name(adata, s); list->name = s; } if (list->name[0] == '\0') { - mdata->delim = list->delim; - mutt_debug(3, "Root delimiter: %c\n", mdata->delim); + adata->delim = list->delim; + mutt_debug(3, "Root delimiter: %c\n", adata->delim); } } /** * cmd_parse_lsub - Parse a server LSUB (list subscribed mailboxes) - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with folder list */ -static void cmd_parse_lsub(struct ImapMboxData *mdata, char *s) +static void cmd_parse_lsub(struct ImapAccountData *adata, char *s) { char buf[STRING]; char errstr[STRING]; @@ -628,20 +628,20 @@ static void cmd_parse_lsub(struct ImapMboxData *mdata, char *s) struct Url url; struct ImapList list; - if (mdata->cmddata && mdata->cmdtype == IMAP_CT_LIST) + if (adata->cmddata && adata->cmdtype == IMAP_CT_LIST) { /* caller will handle response itself */ - cmd_parse_list(mdata, s); + cmd_parse_list(adata, s); return; } if (!ImapCheckSubscribed) return; - mdata->cmdtype = IMAP_CT_LIST; - mdata->cmddata = &list; - cmd_parse_list(mdata, s); - mdata->cmddata = NULL; + adata->cmdtype = IMAP_CT_LIST; + adata->cmddata = &list; + cmd_parse_list(adata, s); + adata->cmddata = NULL; /* noselect is for a gmail quirk (#3445) */ if (!list.name || list.noselect) return; @@ -649,7 +649,7 @@ static void cmd_parse_lsub(struct ImapMboxData *mdata, char *s) mutt_debug(3, "Subscribing to %s\n", list.name); mutt_str_strfcpy(buf, "mailboxes \"", sizeof(buf)); - mutt_account_tourl(&mdata->conn->account, &url); + mutt_account_tourl(&adata->conn->account, &url); /* escape \ and " */ imap_quote_string(errstr, sizeof(errstr), list.name, true); url.path = errstr + 1; @@ -669,10 +669,10 @@ static void cmd_parse_lsub(struct ImapMboxData *mdata, char *s) /** * cmd_parse_myrights - Set rights bits according to MYRIGHTS response - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with rights info */ -static void cmd_parse_myrights(struct ImapMboxData *mdata, const char *s) +static void cmd_parse_myrights(struct ImapAccountData *adata, const char *s) { mutt_debug(2, "Handling MYRIGHTS\n"); @@ -680,54 +680,54 @@ static void cmd_parse_myrights(struct ImapMboxData *mdata, const char *s) s = imap_next_word((char *) s); /* zero out current rights set */ - memset(mdata->ctx->mailbox->rights, 0, sizeof(mdata->ctx->mailbox->rights)); + memset(adata->ctx->mailbox->rights, 0, sizeof(adata->ctx->mailbox->rights)); while (*s && !isspace((unsigned char) *s)) { switch (*s) { case 'a': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_ADMIN); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_ADMIN); break; case 'e': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); break; case 'i': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_INSERT); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_INSERT); break; case 'k': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_CREATE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_CREATE); break; case 'l': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); break; case 'p': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_POST); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_POST); break; case 'r': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_READ); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_READ); break; case 's': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_SEEN); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_SEEN); break; case 't': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_DELETE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_DELETE); break; case 'w': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_WRITE); break; case 'x': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_DELMX); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_DELMX); break; /* obsolete rights */ case 'c': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_CREATE); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_DELMX); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_CREATE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_DELMX); break; case 'd': - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_DELETE); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_DELETE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_EXPUNGE); break; default: mutt_debug(1, "Unknown right: %c\n", *s); @@ -738,10 +738,10 @@ static void cmd_parse_myrights(struct ImapMboxData *mdata, const char *s) /** * cmd_parse_search - store SEARCH response for later use - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with search results */ -static void cmd_parse_search(struct ImapMboxData *mdata, const char *s) +static void cmd_parse_search(struct ImapAccountData *adata, const char *s) { unsigned int uid; struct Email *e = NULL; @@ -752,7 +752,7 @@ static void cmd_parse_search(struct ImapMboxData *mdata, const char *s) { if (mutt_str_atoui(s, &uid) < 0) continue; - e = mutt_hash_int_find(mdata->uid_hash, uid); + e = mutt_hash_int_find(adata->uid_hash, uid); if (e) e->matched = true; } @@ -760,13 +760,13 @@ static void cmd_parse_search(struct ImapMboxData *mdata, const char *s) /** * cmd_parse_status - Parse status from server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string with status info * * first cut: just do mailbox update. Later we may wish to cache all mailbox * information, even that not desired by mailbox */ -static void cmd_parse_status(struct ImapMboxData *mdata, char *s) +static void cmd_parse_status(struct ImapAccountData *adata, char *s) { char *value = NULL; struct ImapMbox mx; @@ -781,19 +781,19 @@ static void cmd_parse_status(struct ImapMboxData *mdata, char *s) /* We need a real tokenizer. */ if (imap_get_literal_count(mailbox, &litlen) == 0) { - if (imap_cmd_step(mdata) != IMAP_CMD_CONTINUE) + if (imap_cmd_step(adata) != IMAP_CMD_CONTINUE) { - mdata->status = IMAP_FATAL; + adata->status = IMAP_FATAL; return; } - if (strlen(mdata->buf) < litlen) + if (strlen(adata->buf) < litlen) { mutt_debug(1, "Error parsing STATUS mailbox\n"); return; } - mailbox = mdata->buf; + mailbox = adata->buf; s = mailbox + litlen; *s = '\0'; s++; @@ -803,10 +803,10 @@ static void cmd_parse_status(struct ImapMboxData *mdata, char *s) { s = imap_next_word(mailbox); *(s - 1) = '\0'; - imap_unmunge_mbox_name(mdata, mailbox); + imap_unmunge_mbox_name(adata, mailbox); } - status = imap_mboxcache_get(mdata, mailbox, 1); + status = imap_mboxcache_get(adata, mailbox, 1); olduv = status->uidvalidity; oldun = status->uidnext; @@ -851,9 +851,9 @@ static void cmd_parse_status(struct ImapMboxData *mdata, char *s) status->messages, status->recent, status->unseen); /* caller is prepared to handle the result herself */ - if (mdata->cmddata && mdata->cmdtype == IMAP_CT_STATUS) + if (adata->cmddata && adata->cmdtype == IMAP_CT_STATUS) { - memcpy(mdata->cmddata, status, sizeof(struct ImapStatus)); + memcpy(adata->cmddata, status, sizeof(struct ImapStatus)); return; } @@ -872,12 +872,12 @@ static void cmd_parse_status(struct ImapMboxData *mdata, char *s) continue; } - if (imap_account_match(&mdata->conn->account, &mx.account)) + if (imap_account_match(&adata->conn->account, &mx.account)) { if (mx.mbox) { value = mutt_str_strdup(mx.mbox); - imap_fix_path(mdata, mx.mbox, value, mutt_str_strlen(value) + 1); + imap_fix_path(adata, mx.mbox, value, mutt_str_strlen(value) + 1); FREE(&mx.mbox); } else @@ -938,10 +938,10 @@ static void cmd_parse_status(struct ImapMboxData *mdata, char *s) /** * cmd_parse_enabled - Record what the server has enabled - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Command string containing acceptable encodings */ -static void cmd_parse_enabled(struct ImapMboxData *mdata, const char *s) +static void cmd_parse_enabled(struct ImapAccountData *adata, const char *s) { mutt_debug(2, "Handling ENABLED\n"); @@ -950,26 +950,26 @@ static void cmd_parse_enabled(struct ImapMboxData *mdata, const char *s) if ((mutt_str_strncasecmp(s, "UTF8=ACCEPT", 11) == 0) || (mutt_str_strncasecmp(s, "UTF8=ONLY", 9) == 0)) { - mdata->unicode = true; + adata->unicode = true; } if (mutt_str_strncasecmp(s, "QRESYNC", 7) == 0) - mdata->qresync = true; + adata->qresync = true; } } /** * cmd_handle_untagged - fallback parser for otherwise unhandled messages - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval -1 Failure */ -static int cmd_handle_untagged(struct ImapMboxData *mdata) +static int cmd_handle_untagged(struct ImapAccountData *adata) { unsigned int count = 0; - char *s = imap_next_word(mdata->buf); + char *s = imap_next_word(adata->buf); char *pn = imap_next_word(s); - if ((mdata->state >= IMAP_SELECTED) && isdigit((unsigned char) *s)) + if ((adata->state >= IMAP_SELECTED) && isdigit((unsigned char) *s)) { pn = s; s = imap_next_word(s); @@ -987,7 +987,7 @@ static int cmd_handle_untagged(struct ImapMboxData *mdata) mutt_debug(1, "Malformed EXISTS: '%s'\n", pn); } - if (!(mdata->reopen & IMAP_EXPUNGE_PENDING) && count < mdata->max_msn) + if (!(adata->reopen & IMAP_EXPUNGE_PENDING) && count < adata->max_msn) { /* Notes 6.0.3 has a tendency to report fewer messages exist than * it should. */ @@ -996,57 +996,57 @@ static int cmd_handle_untagged(struct ImapMboxData *mdata) } /* at least the InterChange server sends EXISTS messages freely, * even when there is no new mail */ - else if (count == mdata->max_msn) + else if (count == adata->max_msn) mutt_debug(3, "superfluous EXISTS message.\n"); else { - if (!(mdata->reopen & IMAP_EXPUNGE_PENDING)) + if (!(adata->reopen & IMAP_EXPUNGE_PENDING)) { - mutt_debug(2, "New mail in %s - %d messages total.\n", mdata->mbox_name, count); - mdata->reopen |= IMAP_NEWMAIL_PENDING; + mutt_debug(2, "New mail in %s - %d messages total.\n", adata->mbox_name, count); + adata->reopen |= IMAP_NEWMAIL_PENDING; } - mdata->new_mail_count = count; + adata->new_mail_count = count; } } /* pn vs. s: need initial seqno */ else if (mutt_str_strncasecmp("EXPUNGE", s, 7) == 0) - cmd_parse_expunge(mdata, pn); + cmd_parse_expunge(adata, pn); else if (mutt_str_strncasecmp("FETCH", s, 5) == 0) - cmd_parse_fetch(mdata, pn); + cmd_parse_fetch(adata, pn); } - else if ((mdata->state >= IMAP_SELECTED) && (mutt_str_strncasecmp("VANISHED", s, 8) == 0)) - cmd_parse_vanished(mdata, pn); + else if ((adata->state >= IMAP_SELECTED) && (mutt_str_strncasecmp("VANISHED", s, 8) == 0)) + cmd_parse_vanished(adata, pn); else if (mutt_str_strncasecmp("CAPABILITY", s, 10) == 0) - cmd_parse_capability(mdata, s); + cmd_parse_capability(adata, s); else if (mutt_str_strncasecmp("OK [CAPABILITY", s, 14) == 0) - cmd_parse_capability(mdata, pn); + cmd_parse_capability(adata, pn); else if (mutt_str_strncasecmp("OK [CAPABILITY", pn, 14) == 0) - cmd_parse_capability(mdata, imap_next_word(pn)); + cmd_parse_capability(adata, imap_next_word(pn)); else if (mutt_str_strncasecmp("LIST", s, 4) == 0) - cmd_parse_list(mdata, s); + cmd_parse_list(adata, s); else if (mutt_str_strncasecmp("LSUB", s, 4) == 0) - cmd_parse_lsub(mdata, s); + cmd_parse_lsub(adata, s); else if (mutt_str_strncasecmp("MYRIGHTS", s, 8) == 0) - cmd_parse_myrights(mdata, s); + cmd_parse_myrights(adata, s); else if (mutt_str_strncasecmp("SEARCH", s, 6) == 0) - cmd_parse_search(mdata, s); + cmd_parse_search(adata, s); else if (mutt_str_strncasecmp("STATUS", s, 6) == 0) - cmd_parse_status(mdata, s); + cmd_parse_status(adata, s); else if (mutt_str_strncasecmp("ENABLED", s, 7) == 0) - cmd_parse_enabled(mdata, s); + cmd_parse_enabled(adata, s); else if (mutt_str_strncasecmp("BYE", s, 3) == 0) { mutt_debug(2, "Handling BYE\n"); /* check if we're logging out */ - if (mdata->status == IMAP_BYE) + if (adata->status == IMAP_BYE) return 0; /* server shut down our connection */ s += 3; SKIPWS(s); mutt_error("%s", s); - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return -1; } @@ -1063,28 +1063,28 @@ static int cmd_handle_untagged(struct ImapMboxData *mdata) /** * imap_cmd_start - Given an IMAP command, send it to the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param cmdstr Command string to send * @retval 0 Success * @retval <0 Failure, e.g. #IMAP_CMD_BAD * * If cmdstr is NULL, sends queued commands. */ -int imap_cmd_start(struct ImapMboxData *mdata, const char *cmdstr) +int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr) { - return cmd_start(mdata, cmdstr, 0); + return cmd_start(adata, cmdstr, 0); } /** * imap_cmd_step - Reads server responses from an IMAP command - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval <0 Failure, e.g. #IMAP_CMD_BAD * * detects tagged completion response, handles untagged messages, can read * arbitrarily large strings (using malloc, so don't make it _too_ large!). */ -int imap_cmd_step(struct ImapMboxData *mdata) +int imap_cmd_step(struct ImapAccountData *adata) { size_t len = 0; int c; @@ -1092,9 +1092,9 @@ int imap_cmd_step(struct ImapMboxData *mdata) int stillrunning = 0; struct ImapCommand *cmd = NULL; - if (mdata->status == IMAP_FATAL) + if (adata->status == IMAP_FATAL) { - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return IMAP_CMD_BAD; } @@ -1102,21 +1102,21 @@ int imap_cmd_step(struct ImapMboxData *mdata) * line */ do { - if (len == mdata->blen) + if (len == adata->blen) { - mutt_mem_realloc(&mdata->buf, mdata->blen + IMAP_CMD_BUFSIZE); - mdata->blen = mdata->blen + IMAP_CMD_BUFSIZE; - mutt_debug(3, "grew buffer to %u bytes\n", mdata->blen); + mutt_mem_realloc(&adata->buf, adata->blen + IMAP_CMD_BUFSIZE); + adata->blen = adata->blen + IMAP_CMD_BUFSIZE; + mutt_debug(3, "grew buffer to %u bytes\n", adata->blen); } /* back up over '\0' */ if (len) len--; - c = mutt_socket_readln(mdata->buf + len, mdata->blen - len, mdata->conn); + c = mutt_socket_readln(adata->buf + len, adata->blen - len, adata->conn); if (c <= 0) { mutt_debug(1, "Error reading server response.\n"); - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return IMAP_CMD_BAD; } @@ -1125,28 +1125,28 @@ int imap_cmd_step(struct ImapMboxData *mdata) /* if we've read all the way to the end of the buffer, we haven't read a * full line (mutt_socket_readln strips the \r, so we always have at least * one character free when we've read a full line) */ - while (len == mdata->blen); + while (len == adata->blen); /* don't let one large string make cmd->buf hog memory forever */ - if ((mdata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) + if ((adata->blen > IMAP_CMD_BUFSIZE) && (len <= IMAP_CMD_BUFSIZE)) { - mutt_mem_realloc(&mdata->buf, IMAP_CMD_BUFSIZE); - mdata->blen = IMAP_CMD_BUFSIZE; - mutt_debug(3, "shrank buffer to %u bytes\n", mdata->blen); + mutt_mem_realloc(&adata->buf, IMAP_CMD_BUFSIZE); + adata->blen = IMAP_CMD_BUFSIZE; + mutt_debug(3, "shrank buffer to %u bytes\n", adata->blen); } - mdata->lastread = time(NULL); + adata->lastread = time(NULL); /* handle untagged messages. The caller still gets its shot afterwards. */ - if (((mutt_str_strncmp(mdata->buf, "* ", 2) == 0) || - (mutt_str_strncmp(imap_next_word(mdata->buf), "OK [", 4) == 0)) && - cmd_handle_untagged(mdata)) + if (((mutt_str_strncmp(adata->buf, "* ", 2) == 0) || + (mutt_str_strncmp(imap_next_word(adata->buf), "OK [", 4) == 0)) && + cmd_handle_untagged(adata)) { return IMAP_CMD_BAD; } /* server demands a continuation response from us */ - if (mdata->buf[0] == '+') + if (adata->buf[0] == '+') return IMAP_CMD_RESPOND; /* Look for tagged command completions. @@ -1156,24 +1156,24 @@ int imap_cmd_step(struct ImapMboxData *mdata) * completions. * (e.g. FETCH->set_flag->set_header_color->~h pattern match.) * - * Other callers don't even create an mdata->cmds entry. + * Other callers don't even create an adata->cmds entry. * * For both these cases, we default to returning OK */ rc = IMAP_CMD_OK; - c = mdata->lastcmd; + c = adata->lastcmd; do { - cmd = &mdata->cmds[c]; + cmd = &adata->cmds[c]; if (cmd->state == IMAP_CMD_NEW) { - if (mutt_str_strncmp(mdata->buf, cmd->seq, SEQLEN) == 0) + if (mutt_str_strncmp(adata->buf, cmd->seq, SEQLEN) == 0) { if (!stillrunning) { /* first command in queue has finished - move queue pointer up */ - mdata->lastcmd = (mdata->lastcmd + 1) % mdata->cmdslots; + adata->lastcmd = (adata->lastcmd + 1) % adata->cmdslots; } - cmd->state = cmd_status(mdata->buf); + cmd->state = cmd_status(adata->buf); /* bogus - we don't know which command result to return here. Caller * should provide a tag. */ rc = cmd->state; @@ -1182,15 +1182,15 @@ int imap_cmd_step(struct ImapMboxData *mdata) stillrunning++; } - c = (c + 1) % mdata->cmdslots; - } while (c != mdata->nextcmd); + c = (c + 1) % adata->cmdslots; + } while (c != adata->nextcmd); if (stillrunning) rc = IMAP_CMD_CONTINUE; else { mutt_debug(3, "IMAP queue drained\n"); - imap_cmd_finish(mdata); + imap_cmd_finish(adata); } return rc; @@ -1209,14 +1209,14 @@ bool imap_code(const char *s) /** * imap_cmd_trailer - Extra information after tagged command response if any - * @param mdata Imap Mailbox data - * @retval ptr Extra command information (pointer into mdata->buf) + * @param adata Imap Account data + * @retval ptr Extra command information (pointer into adata->buf) * @retval "" Error (static string) */ -const char *imap_cmd_trailer(struct ImapMboxData *mdata) +const char *imap_cmd_trailer(struct ImapAccountData *adata) { static const char *notrailer = ""; - const char *s = mdata->buf; + const char *s = adata->buf; if (!s) { @@ -1229,7 +1229,7 @@ const char *imap_cmd_trailer(struct ImapMboxData *mdata) (mutt_str_strncasecmp(s, "NO", 2) != 0) && (mutt_str_strncasecmp(s, "BAD", 3) != 0))) { - mutt_debug(2, "not a command completion: %s\n", mdata->buf); + mutt_debug(2, "not a command completion: %s\n", adata->buf); return notrailer; } @@ -1242,7 +1242,7 @@ const char *imap_cmd_trailer(struct ImapMboxData *mdata) /** * imap_exec - Execute a command and wait for the response from the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param cmdstr Command to execute * @param flags Flags (see below) * @retval 0 Success @@ -1258,14 +1258,14 @@ const char *imap_cmd_trailer(struct ImapMboxData *mdata) * * IMAP_CMD_QUEUE: only queue command, do not execute. * * IMAP_CMD_POLL: poll the socket for a response before running imap_cmd_step. */ -int imap_exec(struct ImapMboxData *mdata, const char *cmdstr, int flags) +int imap_exec(struct ImapAccountData *adata, const char *cmdstr, int flags) { int rc; - rc = cmd_start(mdata, cmdstr, flags); + rc = cmd_start(adata, cmdstr, flags); if (rc < 0) { - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return -1; } @@ -1273,17 +1273,17 @@ int imap_exec(struct ImapMboxData *mdata, const char *cmdstr, int flags) return 0; if ((flags & IMAP_CMD_POLL) && (ImapPollTimeout > 0) && - (mutt_socket_poll(mdata->conn, ImapPollTimeout)) == 0) + (mutt_socket_poll(adata->conn, ImapPollTimeout)) == 0) { - mutt_error(_("Connection to %s timed out"), mdata->conn->account.host); - cmd_handle_fatal(mdata); + mutt_error(_("Connection to %s timed out"), adata->conn->account.host); + cmd_handle_fatal(adata); return -1; } /* Allow interruptions, particularly useful if there are network problems. */ mutt_sig_allow_interrupt(1); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); mutt_sig_allow_interrupt(0); @@ -1292,10 +1292,10 @@ int imap_exec(struct ImapMboxData *mdata, const char *cmdstr, int flags) if (rc != IMAP_CMD_OK) { - if ((flags & IMAP_CMD_FAIL_OK) && mdata->status != IMAP_FATAL) + if ((flags & IMAP_CMD_FAIL_OK) && adata->status != IMAP_FATAL) return -2; - mutt_debug(1, "command failed: %s\n", mdata->buf); + mutt_debug(1, "command failed: %s\n", adata->buf); return -1; } @@ -1304,86 +1304,86 @@ int imap_exec(struct ImapMboxData *mdata, const char *cmdstr, int flags) /** * imap_cmd_finish - Attempt to perform cleanup - * @param mdata Imap Mailbox data + * @param adata Imap Account data * * Attempts to perform cleanup (eg fetch new mail if detected, do expunge). * Called automatically by imap_cmd_step(), but may be called at any time. * Called by imap_check_mailbox() just before the index is refreshed, for * instance. */ -void imap_cmd_finish(struct ImapMboxData *mdata) +void imap_cmd_finish(struct ImapAccountData *adata) { - if (mdata->status == IMAP_FATAL) + if (adata->status == IMAP_FATAL) { - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return; } - if (!(mdata->state >= IMAP_SELECTED) || mdata->ctx->mailbox->closing) + if (!(adata->state >= IMAP_SELECTED) || adata->ctx->mailbox->closing) return; - if (mdata->reopen & IMAP_REOPEN_ALLOW) + if (adata->reopen & IMAP_REOPEN_ALLOW) { - unsigned int count = mdata->new_mail_count; + unsigned int count = adata->new_mail_count; - if (!(mdata->reopen & IMAP_EXPUNGE_PENDING) && - (mdata->reopen & IMAP_NEWMAIL_PENDING) && count > mdata->max_msn) + if (!(adata->reopen & IMAP_EXPUNGE_PENDING) && + (adata->reopen & IMAP_NEWMAIL_PENDING) && count > adata->max_msn) { /* read new mail messages */ mutt_debug(2, "Fetching new mail\n"); /* check_status: curs_main uses imap_check_mailbox to detect * whether the index needs updating */ - mdata->check_status = IMAP_NEWMAIL_PENDING; - imap_read_headers(mdata, mdata->max_msn + 1, count, false); + adata->check_status = IMAP_NEWMAIL_PENDING; + imap_read_headers(adata, adata->max_msn + 1, count, false); } - else if (mdata->reopen & IMAP_EXPUNGE_PENDING) + else if (adata->reopen & IMAP_EXPUNGE_PENDING) { mutt_debug(2, "Expunging mailbox\n"); - imap_expunge_mailbox(mdata); + imap_expunge_mailbox(adata); /* Detect whether we've gotten unexpected EXPUNGE messages */ - if ((mdata->reopen & IMAP_EXPUNGE_PENDING) && !(mdata->reopen & IMAP_EXPUNGE_EXPECTED)) - mdata->check_status = IMAP_EXPUNGE_PENDING; - mdata->reopen &= + if ((adata->reopen & IMAP_EXPUNGE_PENDING) && !(adata->reopen & IMAP_EXPUNGE_EXPECTED)) + adata->check_status = IMAP_EXPUNGE_PENDING; + adata->reopen &= ~(IMAP_EXPUNGE_PENDING | IMAP_NEWMAIL_PENDING | IMAP_EXPUNGE_EXPECTED); } } - mdata->status = 0; + adata->status = 0; } /** * imap_cmd_idle - Enter the IDLE state - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval <0 Failure, e.g. #IMAP_CMD_BAD */ -int imap_cmd_idle(struct ImapMboxData *mdata) +int imap_cmd_idle(struct ImapAccountData *adata) { int rc; - if (cmd_start(mdata, "IDLE", IMAP_CMD_POLL) < 0) + if (cmd_start(adata, "IDLE", IMAP_CMD_POLL) < 0) { - cmd_handle_fatal(mdata); + cmd_handle_fatal(adata); return -1; } - if ((ImapPollTimeout > 0) && (mutt_socket_poll(mdata->conn, ImapPollTimeout)) == 0) + if ((ImapPollTimeout > 0) && (mutt_socket_poll(adata->conn, ImapPollTimeout)) == 0) { - mutt_error(_("Connection to %s timed out"), mdata->conn->account.host); - cmd_handle_fatal(mdata); + mutt_error(_("Connection to %s timed out"), adata->conn->account.host); + cmd_handle_fatal(adata); return -1; } do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc == IMAP_CMD_RESPOND) { /* successfully entered IDLE state */ - mdata->state = IMAP_IDLE; + adata->state = IMAP_IDLE; /* queue automatic exit when next command is issued */ - mutt_buffer_printf(mdata->cmdbuf, "DONE\r\n"); + mutt_buffer_printf(adata->cmdbuf, "DONE\r\n"); rc = IMAP_CMD_OK; } if (rc != IMAP_CMD_OK) diff --git a/imap/imap.c b/imap/imap.c index 545f70e39..90758736f 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -70,20 +70,20 @@ bool ImapIdle; ///< Config: (imap) Use the IMAP IDLE extension to check for new /** * check_capabilities - Make sure we can log in to this server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval -1 Failure */ -static int check_capabilities(struct ImapMboxData *mdata) +static int check_capabilities(struct ImapAccountData *adata) { - if (imap_exec(mdata, "CAPABILITY", 0) != 0) + if (imap_exec(adata, "CAPABILITY", 0) != 0) { - imap_error("check_capabilities", mdata->buf); + imap_error("check_capabilities", adata->buf); return -1; } - if (!(mutt_bit_isset(mdata->capabilities, IMAP4) || - mutt_bit_isset(mdata->capabilities, IMAP4REV1))) + if (!(mutt_bit_isset(adata->capabilities, IMAP4) || + mutt_bit_isset(adata->capabilities, IMAP4REV1))) { mutt_error( _("This IMAP server is ancient. NeoMutt does not work with it.")); @@ -149,24 +149,24 @@ static char *get_flags(struct ListHead *hflags, char *s) /** * set_flag - append str to flags if we currently have permission according to aclbit - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[in] aclbit Permissions, e.g. #MUTT_ACL_WRITE * @param[in] flag Does the email have the flag set? * @param[in] str Server flag name * @param[out] flags Buffer for server command * @param[in] flsize Length of buffer */ -static void set_flag(struct ImapMboxData *mdata, int aclbit, int flag, +static void set_flag(struct ImapAccountData *adata, int aclbit, int flag, const char *str, char *flags, size_t flsize) { - if (mutt_bit_isset(mdata->ctx->mailbox->rights, aclbit)) - if (flag && imap_has_flag(&mdata->flags, str)) + if (mutt_bit_isset(adata->ctx->mailbox->rights, aclbit)) + if (flag && imap_has_flag(&adata->flags, str)) mutt_str_strcat(flags, flsize, str); } /** * make_msg_set - Make a message set - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[in] buf Buffer to store message set * @param[in] flag Flags to match, e.g. #MUTT_DELETED * @param[in] changed Matched messages that have been altered @@ -177,16 +177,16 @@ static void set_flag(struct ImapMboxData *mdata, int aclbit, int flag, * @note Headers must be in SORT_ORDER. See imap_exec_msgset() for args. * Pos is an opaque pointer a la strtok(). It should be 0 at first call. */ -static int make_msg_set(struct ImapMboxData *mdata, struct Buffer *buf, +static int make_msg_set(struct ImapAccountData *adata, struct Buffer *buf, int flag, bool changed, bool invert, int *pos) { int count = 0; /* number of messages in message set */ unsigned int setstart = 0; /* start of current message range */ int n; bool started = false; - struct Email **emails = mdata->ctx->mailbox->hdrs; + struct Email **emails = adata->ctx->mailbox->hdrs; - for (n = *pos; n < mdata->ctx->mailbox->msg_count && buf->dptr - buf->data < IMAP_MAX_CMDLEN; + for (n = *pos; n < adata->ctx->mailbox->msg_count && buf->dptr - buf->data < IMAP_MAX_CMDLEN; n++) { bool match = false; /* whether current message matches flag condition */ @@ -241,12 +241,12 @@ static int make_msg_set(struct ImapMboxData *mdata, struct Buffer *buf, mutt_buffer_printf(buf, ",%u", IMAP_EDATA(emails[n])->uid); } /* tie up if the last message also matches */ - else if (n == mdata->ctx->mailbox->msg_count - 1) + else if (n == adata->ctx->mailbox->msg_count - 1) mutt_buffer_printf(buf, ":%u", IMAP_EDATA(emails[n])->uid); } /* End current set if message doesn't match or we've reached the end * of the mailbox via inactive messages following the last match. */ - else if (setstart && (emails[n]->active || n == mdata->ctx->mailbox->msg_count - 1)) + else if (setstart && (emails[n]->active || n == adata->ctx->mailbox->msg_count - 1)) { if (IMAP_EDATA(emails[n - 1])->uid > setstart) mutt_buffer_printf(buf, ":%u", IMAP_EDATA(emails[n - 1])->uid); @@ -285,36 +285,36 @@ static bool compare_flags_for_copy(struct Email *e) /** * sync_helper - Sync flag changes to the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param right ACL, e.g. #MUTT_ACL_DELETE * @param flag Mutt flag, e.g. MUTT_DELETED * @param name Name of server flag * @retval >=0 Success, number of messages * @retval -1 Failure */ -static int sync_helper(struct ImapMboxData *mdata, int right, int flag, const char *name) +static int sync_helper(struct ImapAccountData *adata, int right, int flag, const char *name) { int count = 0; int rc; char buf[LONG_STRING]; - if (!mdata->ctx) + if (!adata->ctx) return -1; - if (!mutt_bit_isset(mdata->ctx->mailbox->rights, right)) + if (!mutt_bit_isset(adata->ctx->mailbox->rights, right)) return 0; - if (right == MUTT_ACL_WRITE && !imap_has_flag(&mdata->flags, name)) + if (right == MUTT_ACL_WRITE && !imap_has_flag(&adata->flags, name)) return 0; snprintf(buf, sizeof(buf), "+FLAGS.SILENT (%s)", name); - rc = imap_exec_msgset(mdata, "UID STORE", buf, flag, true, false); + rc = imap_exec_msgset(adata, "UID STORE", buf, flag, true, false); if (rc < 0) return rc; count += rc; buf[0] = '-'; - rc = imap_exec_msgset(mdata, "UID STORE", buf, flag, true, true); + rc = imap_exec_msgset(adata, "UID STORE", buf, flag, true, true); if (rc < 0) return rc; count += rc; @@ -331,10 +331,10 @@ static int sync_helper(struct ImapMboxData *mdata, int right, int flag, const ch * @retval 0 Success * @retval -1 Failure * - * Split up a mailbox URI. The connection info is stored in the ImapMboxData and + * Split up a mailbox URI. The connection info is stored in the ImapAccountData and * the mailbox name is stored in buf. */ -static int get_mailbox(const char *path, struct ImapMboxData **hidata, char *buf, size_t buflen) +static int get_mailbox(const char *path, struct ImapAccountData **hidata, char *buf, size_t buflen) { struct ImapMbox mx; @@ -490,8 +490,8 @@ static int compile_search(struct Mailbox *mailbox, const struct Pattern *pat, break; case MUTT_SERVERSEARCH: { - struct ImapMboxData *mdata = mailbox->data; - if (!mutt_bit_isset(mdata->capabilities, X_GM_EXT1)) + struct ImapAccountData *adata = mailbox->data; + if (!mutt_bit_isset(adata->capabilities, X_GM_EXT1)) { mutt_error(_("Server-side custom search not supported: %s"), pat->p.str); return -1; @@ -598,7 +598,7 @@ static int complete_hosts(char *buf, size_t buflen) */ int imap_access(const char *path) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct ImapMbox mx; char buf[LONG_STRING * 2]; char mailbox[LONG_STRING]; @@ -608,36 +608,36 @@ int imap_access(const char *path) if (imap_parse_path(path, &mx)) return -1; - mdata = imap_conn_find(&mx.account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0); - if (!mdata) + adata = imap_conn_find(&mx.account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0); + if (!adata) { FREE(&mx.mbox); return -1; } - imap_fix_path(mdata, mx.mbox, mailbox, sizeof(mailbox)); + imap_fix_path(adata, mx.mbox, mailbox, sizeof(mailbox)); if (!*mailbox) mutt_str_strfcpy(mailbox, "INBOX", sizeof(mailbox)); /* we may already be in the folder we're checking */ - if (mutt_str_strcmp(mdata->mbox_name, mx.mbox) == 0) + if (mutt_str_strcmp(adata->mbox_name, mx.mbox) == 0) { FREE(&mx.mbox); return 0; } FREE(&mx.mbox); - if (imap_mboxcache_get(mdata, mailbox, false)) + if (imap_mboxcache_get(adata, mailbox, false)) { mutt_debug(3, "found %s in cache\n", mailbox); return 0; } - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), mailbox); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), mailbox); - if (mutt_bit_isset(mdata->capabilities, IMAP4REV1)) + if (mutt_bit_isset(adata->capabilities, IMAP4REV1)) snprintf(buf, sizeof(buf), "STATUS %s (UIDVALIDITY)", mbox); - else if (mutt_bit_isset(mdata->capabilities, STATUS)) + else if (mutt_bit_isset(adata->capabilities, STATUS)) snprintf(buf, sizeof(buf), "STATUS %s (UID-VALIDITY)", mbox); else { @@ -645,7 +645,7 @@ int imap_access(const char *path) return -1; } - rc = imap_exec(mdata, buf, IMAP_CMD_FAIL_OK); + rc = imap_exec(adata, buf, IMAP_CMD_FAIL_OK); if (rc < 0) { mutt_debug(1, "Can't check STATUS of %s\n", mbox); @@ -657,21 +657,21 @@ int imap_access(const char *path) /** * imap_create_mailbox - Create a new mailbox - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param mailbox Mailbox to create * @retval 0 Success * @retval -1 Failure */ -int imap_create_mailbox(struct ImapMboxData *mdata, char *mailbox) +int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox) { char buf[LONG_STRING * 2], mbox[LONG_STRING]; - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), mailbox); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), mailbox); snprintf(buf, sizeof(buf), "CREATE %s", mbox); - if (imap_exec(mdata, buf, 0) != 0) + if (imap_exec(adata, buf, 0) != 0) { - mutt_error(_("CREATE failed: %s"), imap_cmd_trailer(mdata)); + mutt_error(_("CREATE failed: %s"), imap_cmd_trailer(adata)); return -1; } @@ -680,25 +680,25 @@ int imap_create_mailbox(struct ImapMboxData *mdata, char *mailbox) /** * imap_rename_mailbox - Rename a mailbox - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param mx Existing mailbox * @param newname New name for mailbox * @retval 0 Success * @retval -1 Failure */ -int imap_rename_mailbox(struct ImapMboxData *mdata, struct ImapMbox *mx, const char *newname) +int imap_rename_mailbox(struct ImapAccountData *adata, struct ImapMbox *mx, const char *newname) { char oldmbox[LONG_STRING]; char newmbox[LONG_STRING]; int rc = 0; - imap_munge_mbox_name(mdata, oldmbox, sizeof(oldmbox), mx->mbox); - imap_munge_mbox_name(mdata, newmbox, sizeof(newmbox), newname); + imap_munge_mbox_name(adata, oldmbox, sizeof(oldmbox), mx->mbox); + imap_munge_mbox_name(adata, newmbox, sizeof(newmbox), newname); struct Buffer *b = mutt_buffer_alloc(LONG_STRING); mutt_buffer_printf(b, "RENAME %s %s", oldmbox, newmbox); - if (imap_exec(mdata, b->data, 0) != 0) + if (imap_exec(adata, b->data, 0) != 0) rc = -1; mutt_buffer_free(&b); @@ -716,12 +716,12 @@ int imap_rename_mailbox(struct ImapMboxData *mdata, struct ImapMbox *mx, const c int imap_delete_mailbox(struct Mailbox *mailbox, struct ImapMbox *mx) { char buf[PATH_MAX], mbox[PATH_MAX]; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; if (!mailbox || !mailbox->data) { - mdata = imap_conn_find(&mx->account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0); - if (!mdata) + adata = imap_conn_find(&mx->account, ImapPassive ? MUTT_IMAP_CONN_NONEW : 0); + if (!adata) { FREE(&mx->mbox); return -1; @@ -729,13 +729,13 @@ int imap_delete_mailbox(struct Mailbox *mailbox, struct ImapMbox *mx) } else { - mdata = mailbox->data; + adata = mailbox->data; } - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), mx->mbox); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), mx->mbox); snprintf(buf, sizeof(buf), "DELETE %s", mbox); - if (imap_exec(mdata, buf, 0) != 0) + if (imap_exec(adata, buf, 0) != 0) return -1; return 0; @@ -756,7 +756,7 @@ void imap_logout_all(void) { TAILQ_REMOVE(head, np, entries); mutt_message(_("Closing connection to %s..."), np->account.host); - imap_logout((struct ImapMboxData **) (void *) &np->data); + imap_logout((struct ImapAccountData **) (void *) &np->data); mutt_clear_error(); mutt_socket_free(np); } @@ -766,7 +766,7 @@ void imap_logout_all(void) /** * imap_read_literal - Read bytes bytes from server into file * @param fp File handle for email file - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param bytes Number of bytes to read * @param pbar Progress bar * @retval 0 Success @@ -777,7 +777,7 @@ void imap_logout_all(void) * @note Strips `\r` from `\r\n`. * Apparently even literals use `\r\n`-terminated strings ?! */ -int imap_read_literal(FILE *fp, struct ImapMboxData *mdata, unsigned long bytes, +int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *pbar) { char c; @@ -791,10 +791,10 @@ int imap_read_literal(FILE *fp, struct ImapMboxData *mdata, unsigned long bytes, for (unsigned long pos = 0; pos < bytes; pos++) { - if (mutt_socket_readchar(mdata->conn, &c) != 1) + if (mutt_socket_readchar(adata->conn, &c) != 1) { mutt_debug(1, "error during read, %ld bytes read\n", pos); - mdata->status = IMAP_FATAL; + adata->status = IMAP_FATAL; mutt_buffer_free(&buf); return -1; @@ -829,52 +829,52 @@ int imap_read_literal(FILE *fp, struct ImapMboxData *mdata, unsigned long bytes, /** * imap_expunge_mailbox - Purge messages from the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * * Purge IMAP portion of expunged messages from the context. Must not be done * while something has a handle on any headers (eg inside pager or editor). * That is, check IMAP_REOPEN_ALLOW. */ -void imap_expunge_mailbox(struct ImapMboxData *mdata) +void imap_expunge_mailbox(struct ImapAccountData *adata) { struct Email *e = NULL; int cacheno; short old_sort; #ifdef USE_HCACHE - mdata->hcache = imap_hcache_open(mdata, NULL); + adata->hcache = imap_hcache_open(adata, NULL); #endif old_sort = Sort; Sort = SORT_ORDER; - mutt_sort_headers(mdata->ctx, false); + mutt_sort_headers(adata->ctx, false); - for (int i = 0; i < mdata->ctx->mailbox->msg_count; i++) + for (int i = 0; i < adata->ctx->mailbox->msg_count; i++) { - e = mdata->ctx->mailbox->hdrs[i]; + e = adata->ctx->mailbox->hdrs[i]; if (e->index == INT_MAX) { mutt_debug(2, "Expunging message UID %u.\n", IMAP_EDATA(e)->uid); e->active = false; - mdata->ctx->mailbox->size -= e->content->length; + adata->ctx->mailbox->size -= e->content->length; - imap_cache_del(mdata, e); + imap_cache_del(adata, e); #ifdef USE_HCACHE - imap_hcache_del(mdata, IMAP_EDATA(e)->uid); + imap_hcache_del(adata, IMAP_EDATA(e)->uid); #endif /* free cached body from disk, if necessary */ cacheno = IMAP_EDATA(e)->uid % IMAP_CACHE_LEN; - if (mdata->cache[cacheno].uid == IMAP_EDATA(e)->uid && - mdata->cache[cacheno].path) + if (adata->cache[cacheno].uid == IMAP_EDATA(e)->uid && + adata->cache[cacheno].path) { - unlink(mdata->cache[cacheno].path); - FREE(&mdata->cache[cacheno].path); + unlink(adata->cache[cacheno].path); + FREE(&adata->cache[cacheno].path); } - mutt_hash_int_delete(mdata->uid_hash, IMAP_EDATA(e)->uid, e); + mutt_hash_int_delete(adata->uid_hash, IMAP_EDATA(e)->uid, e); imap_free_emaildata((void **) &e->data); } @@ -902,14 +902,14 @@ void imap_expunge_mailbox(struct ImapMboxData *mdata) } #ifdef USE_HCACHE - imap_hcache_close(mdata); + imap_hcache_close(adata); #endif /* We may be called on to expunge at any time. We can't rely on the caller * to always know to rethread */ - mx_update_tables(mdata->ctx, false); + mx_update_tables(adata->ctx, false); Sort = old_sort; - mutt_sort_headers(mdata->ctx, true); + mutt_sort_headers(adata->ctx, true); } /** @@ -922,11 +922,11 @@ void imap_expunge_mailbox(struct ImapMboxData *mdata) * Find an open IMAP connection matching account, or open a new one if none can * be found. */ -struct ImapMboxData *imap_conn_find(const struct ConnAccount *account, int flags) +struct ImapAccountData *imap_conn_find(const struct ConnAccount *account, int flags) { struct Connection *conn = NULL; struct ConnAccount *creds = NULL; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; bool new = false; while ((conn = mutt_conn_find(conn, account))) @@ -936,21 +936,21 @@ struct ImapMboxData *imap_conn_find(const struct ConnAccount *account, int flags else memcpy(&conn->account, creds, sizeof(struct ConnAccount)); - mdata = conn->data; + adata = conn->data; if (flags & MUTT_IMAP_CONN_NONEW) { - if (!mdata) + if (!adata) { /* This should only happen if we've come to the end of the list */ mutt_socket_free(conn); return NULL; } - else if (mdata->state < IMAP_AUTHENTICATED) + else if (adata->state < IMAP_AUTHENTICATED) continue; } - if (flags & MUTT_IMAP_CONN_NOSELECT && mdata && mdata->state >= IMAP_SELECTED) + if (flags & MUTT_IMAP_CONN_NOSELECT && adata && adata->state >= IMAP_SELECTED) continue; - if (mdata && mdata->status == IMAP_FATAL) + if (adata && adata->status == IMAP_FATAL) continue; break; } @@ -958,93 +958,93 @@ struct ImapMboxData *imap_conn_find(const struct ConnAccount *account, int flags return NULL; /* this happens when the initial connection fails */ /* The current connection is a new connection */ - if (!mdata) + if (!adata) { /* The current connection is a new connection */ - mdata = imap_mdata_new(); - conn->data = mdata; - mdata->conn = conn; + adata = imap_adata_new(); + conn->data = adata; + adata->conn = conn; new = true; } - if (mdata->state == IMAP_DISCONNECTED) - imap_open_connection(mdata); - if (mdata->state == IMAP_CONNECTED) + if (adata->state == IMAP_DISCONNECTED) + imap_open_connection(adata); + if (adata->state == IMAP_CONNECTED) { - if (imap_authenticate(mdata) == IMAP_AUTH_SUCCESS) + if (imap_authenticate(adata) == IMAP_AUTH_SUCCESS) { - mdata->state = IMAP_AUTHENTICATED; - FREE(&mdata->capstr); + adata->state = IMAP_AUTHENTICATED; + FREE(&adata->capstr); new = true; - if (mdata->conn->ssf) - mutt_debug(2, "Communication encrypted at %d bits\n", mdata->conn->ssf); + if (adata->conn->ssf) + mutt_debug(2, "Communication encrypted at %d bits\n", adata->conn->ssf); } else - mutt_account_unsetpass(&mdata->conn->account); + mutt_account_unsetpass(&adata->conn->account); } - if (new && mdata->state == IMAP_AUTHENTICATED) + if (new && adata->state == IMAP_AUTHENTICATED) { /* capabilities may have changed */ - imap_exec(mdata, "CAPABILITY", IMAP_CMD_QUEUE); + imap_exec(adata, "CAPABILITY", IMAP_CMD_QUEUE); /* enable RFC6855, if the server supports that */ - if (mutt_bit_isset(mdata->capabilities, ENABLE)) - imap_exec(mdata, "ENABLE UTF8=ACCEPT", IMAP_CMD_QUEUE); + if (mutt_bit_isset(adata->capabilities, 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(mdata->capabilities, QRESYNC)) + if (mutt_bit_isset(adata->capabilities, QRESYNC)) { - mutt_bit_set(mdata->capabilities, CONDSTORE); + mutt_bit_set(adata->capabilities, CONDSTORE); if (ImapQResync) - imap_exec(mdata, "ENABLE QRESYNC", IMAP_CMD_QUEUE); + imap_exec(adata, "ENABLE QRESYNC", IMAP_CMD_QUEUE); } /* get root delimiter, '/' as default */ - mdata->delim = '/'; - imap_exec(mdata, "LIST \"\" \"\"", IMAP_CMD_QUEUE); + adata->delim = '/'; + imap_exec(adata, "LIST \"\" \"\"", IMAP_CMD_QUEUE); /* we may need the root delimiter before we open a mailbox */ - imap_exec(mdata, NULL, IMAP_CMD_FAIL_OK); + imap_exec(adata, NULL, IMAP_CMD_FAIL_OK); } - if (mdata->state < IMAP_AUTHENTICATED) + if (adata->state < IMAP_AUTHENTICATED) return NULL; - return mdata; + return adata; } /** * imap_open_connection - Open an IMAP connection - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval -1 Failure */ -int imap_open_connection(struct ImapMboxData *mdata) +int imap_open_connection(struct ImapAccountData *adata) { char buf[LONG_STRING]; - if (mutt_socket_open(mdata->conn) < 0) + if (mutt_socket_open(adata->conn) < 0) return -1; - mdata->state = IMAP_CONNECTED; + adata->state = IMAP_CONNECTED; - if (imap_cmd_step(mdata) != IMAP_CMD_OK) + if (imap_cmd_step(adata) != IMAP_CMD_OK) { - imap_close_connection(mdata); + imap_close_connection(adata); return -1; } - if (mutt_str_strncasecmp("* OK", mdata->buf, 4) == 0) + if (mutt_str_strncasecmp("* OK", adata->buf, 4) == 0) { - if ((mutt_str_strncasecmp("* OK [CAPABILITY", mdata->buf, 16) != 0) && - check_capabilities(mdata)) + if ((mutt_str_strncasecmp("* OK [CAPABILITY", adata->buf, 16) != 0) && + check_capabilities(adata)) { goto bail; } #ifdef USE_SSL /* Attempt STARTTLS if available and desired. */ - if (!mdata->conn->ssf && (SslForceTls || mutt_bit_isset(mdata->capabilities, STARTTLS))) + if (!adata->conn->ssf && (SslForceTls || mutt_bit_isset(adata->capabilities, STARTTLS))) { int rc; @@ -1057,12 +1057,12 @@ int imap_open_connection(struct ImapMboxData *mdata) } if (rc == MUTT_YES) { - rc = imap_exec(mdata, "STARTTLS", IMAP_CMD_FAIL_OK); + rc = imap_exec(adata, "STARTTLS", IMAP_CMD_FAIL_OK); if (rc == -1) goto bail; if (rc != -2) { - if (mutt_ssl_starttls(mdata->conn)) + if (mutt_ssl_starttls(adata->conn)) { mutt_error(_("Could not negotiate TLS connection")); goto err_close_conn; @@ -1070,26 +1070,26 @@ int imap_open_connection(struct ImapMboxData *mdata) else { /* RFC2595 demands we recheck CAPABILITY after TLS completes. */ - if (imap_exec(mdata, "CAPABILITY", 0)) + if (imap_exec(adata, "CAPABILITY", 0)) goto bail; } } } } - if (SslForceTls && !mdata->conn->ssf) + if (SslForceTls && !adata->conn->ssf) { mutt_error(_("Encrypted connection unavailable")); goto err_close_conn; } #endif } - else if (mutt_str_strncasecmp("* PREAUTH", mdata->buf, 9) == 0) + else if (mutt_str_strncasecmp("* PREAUTH", adata->buf, 9) == 0) { - mdata->state = IMAP_AUTHENTICATED; - if (check_capabilities(mdata) != 0) + adata->state = IMAP_AUTHENTICATED; + if (check_capabilities(adata) != 0) goto bail; - FREE(&mdata->capstr); + FREE(&adata->capstr); } else { @@ -1101,49 +1101,49 @@ int imap_open_connection(struct ImapMboxData *mdata) #ifdef USE_SSL err_close_conn: - imap_close_connection(mdata); + imap_close_connection(adata); #endif bail: - FREE(&mdata->capstr); + FREE(&adata->capstr); return -1; } /** * imap_close_connection - Close an IMAP connection - * @param mdata Imap Mailbox data + * @param adata Imap Account data */ -void imap_close_connection(struct ImapMboxData *mdata) +void imap_close_connection(struct ImapAccountData *adata) { - if (mdata->state != IMAP_DISCONNECTED) + if (adata->state != IMAP_DISCONNECTED) { - mutt_socket_close(mdata->conn); - mdata->state = IMAP_DISCONNECTED; + mutt_socket_close(adata->conn); + adata->state = IMAP_DISCONNECTED; } - mdata->seqno = false; - mdata->nextcmd = false; - mdata->lastcmd = false; - mdata->status = false; - memset(mdata->cmds, 0, sizeof(struct ImapCommand) * mdata->cmdslots); + adata->seqno = false; + adata->nextcmd = false; + adata->lastcmd = false; + adata->status = false; + memset(adata->cmds, 0, sizeof(struct ImapCommand) * adata->cmdslots); } /** * imap_logout - Gracefully log out of server - * @param mdata Imap Mailbox data + * @param adata Imap Account data */ -void imap_logout(struct ImapMboxData **mdata) +void imap_logout(struct ImapAccountData **adata) { /* we set status here to let imap_handle_untagged know we _expect_ to * receive a bye response (so it doesn't freak out and close the conn) */ - (*mdata)->status = IMAP_BYE; - imap_cmd_start(*mdata, "LOGOUT"); - if (ImapPollTimeout <= 0 || mutt_socket_poll((*mdata)->conn, ImapPollTimeout) != 0) + (*adata)->status = IMAP_BYE; + imap_cmd_start(*adata, "LOGOUT"); + if (ImapPollTimeout <= 0 || mutt_socket_poll((*adata)->conn, ImapPollTimeout) != 0) { - while (imap_cmd_step(*mdata) == IMAP_CMD_CONTINUE) + while (imap_cmd_step(*adata) == IMAP_CMD_CONTINUE) ; } - mutt_socket_close((*mdata)->conn); - imap_mdata_free(mdata); + mutt_socket_close((*adata)->conn); + imap_adata_free(adata); } /** @@ -1175,7 +1175,7 @@ bool imap_has_flag(struct ListHead *flag_list, const char *flag) /** * imap_exec_msgset - Prepare commands for all messages matching conditions - * @param mdata Imap Mailbox data containing context containing header set + * @param adata Imap Account data containing context containing header set * @param pre prefix commands * @param post postfix commands * @param flag flag type on which to filter, e.g. MUTT_REPLIED @@ -1188,7 +1188,7 @@ bool imap_has_flag(struct ListHead *flag_list, const char *flag) * Prepares commands for all messages matching conditions * (must be flushed with imap_exec) */ -int imap_exec_msgset(struct ImapMboxData *mdata, const char *pre, +int imap_exec_msgset(struct ImapAccountData *adata, const char *pre, const char *post, int flag, bool changed, bool invert) { struct Email **emails = NULL; @@ -1205,14 +1205,14 @@ int imap_exec_msgset(struct ImapMboxData *mdata, const char *pre, oldsort = Sort; if (Sort != SORT_ORDER) { - emails = mdata->ctx->mailbox->hdrs; - mdata->ctx->mailbox->hdrs = - mutt_mem_malloc(mdata->ctx->mailbox->msg_count * sizeof(struct Email *)); - memcpy(mdata->ctx->mailbox->hdrs, emails, - mdata->ctx->mailbox->msg_count * sizeof(struct Email *)); + emails = adata->ctx->mailbox->hdrs; + adata->ctx->mailbox->hdrs = + mutt_mem_malloc(adata->ctx->mailbox->msg_count * sizeof(struct Email *)); + memcpy(adata->ctx->mailbox->hdrs, emails, + adata->ctx->mailbox->msg_count * sizeof(struct Email *)); Sort = SORT_ORDER; - qsort(mdata->ctx->mailbox->hdrs, mdata->ctx->mailbox->msg_count, + qsort(adata->ctx->mailbox->hdrs, adata->ctx->mailbox->msg_count, sizeof(struct Email *), mutt_get_sort_func(SORT_ORDER)); } @@ -1222,11 +1222,11 @@ int imap_exec_msgset(struct ImapMboxData *mdata, const char *pre, { cmd->dptr = cmd->data; mutt_buffer_printf(cmd, "%s ", pre); - rc = make_msg_set(mdata, cmd, flag, changed, invert, &pos); + rc = make_msg_set(adata, cmd, flag, changed, invert, &pos); if (rc > 0) { mutt_buffer_printf(cmd, " %s", post); - if (imap_exec(mdata, cmd->data, IMAP_CMD_QUEUE)) + if (imap_exec(adata, cmd->data, IMAP_CMD_QUEUE)) { rc = -1; goto out; @@ -1242,8 +1242,8 @@ out: if (oldsort != Sort) { Sort = oldsort; - FREE(&mdata->ctx->mailbox->hdrs); - mdata->ctx->mailbox->hdrs = emails; + FREE(&adata->ctx->mailbox->hdrs); + adata->ctx->mailbox->hdrs = emails; } return rc; @@ -1251,7 +1251,7 @@ out: /** * imap_sync_message_for_copy - Update server to reflect the flags of a single message - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[in] e Email * @param[in] cmd Buffer for the command string * @param[out] err_continue Did the user force a continue? @@ -1264,7 +1264,7 @@ out: * @note This does not sync the "deleted" flag state, because it is not * desirable to propagate that flag into the copy. */ -int imap_sync_message_for_copy(struct ImapMboxData *mdata, struct Email *e, +int imap_sync_message_for_copy(struct ImapAccountData *adata, struct Email *e, struct Buffer *cmd, int *err_continue) { char flags[LONG_STRING]; @@ -1285,14 +1285,14 @@ int imap_sync_message_for_copy(struct ImapMboxData *mdata, struct Email *e, flags[0] = '\0'; - set_flag(mdata, MUTT_ACL_SEEN, e->read, "\\Seen ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, e->old, "Old ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, e->flagged, "\\Flagged ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, e->replied, "\\Answered ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_DELETE, IMAP_EDATA(e)->deleted, "\\Deleted ", flags, + set_flag(adata, MUTT_ACL_SEEN, e->read, "\\Seen ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, e->old, "Old ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, e->flagged, "\\Flagged ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, e->replied, "\\Answered ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_DELETE, IMAP_EDATA(e)->deleted, "\\Deleted ", flags, sizeof(flags)); - if (mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE)) + if (mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_WRITE)) { /* restore system flags */ if (IMAP_EDATA(e)->flags_system) @@ -1312,15 +1312,15 @@ int imap_sync_message_for_copy(struct ImapMboxData *mdata, struct Email *e, * explicitly revoke all system flags (if we have permission) */ if (!*flags) { - set_flag(mdata, MUTT_ACL_SEEN, 1, "\\Seen ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, 1, "Old ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, 1, "\\Flagged ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_WRITE, 1, "\\Answered ", flags, sizeof(flags)); - set_flag(mdata, MUTT_ACL_DELETE, !IMAP_EDATA(e)->deleted, "\\Deleted ", + set_flag(adata, MUTT_ACL_SEEN, 1, "\\Seen ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, 1, "Old ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, 1, "\\Flagged ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_WRITE, 1, "\\Answered ", flags, sizeof(flags)); + set_flag(adata, MUTT_ACL_DELETE, !IMAP_EDATA(e)->deleted, "\\Deleted ", flags, sizeof(flags)); /* erase custom flags */ - if (mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE) && + if (mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_WRITE) && IMAP_EDATA(e)->flags_remote) mutt_str_strcat(flags, sizeof(flags), IMAP_EDATA(e)->flags_remote); @@ -1339,10 +1339,10 @@ int imap_sync_message_for_copy(struct ImapMboxData *mdata, struct Email *e, /* after all this it's still possible to have no flags, if you * have no ACL rights */ - if (*flags && (imap_exec(mdata, cmd->data, 0) != 0) && err_continue && + if (*flags && (imap_exec(adata, cmd->data, 0) != 0) && err_continue && (*err_continue != MUTT_YES)) { - *err_continue = imap_continue("imap_sync_message: STORE failed", mdata->buf); + *err_continue = imap_continue("imap_sync_message: STORE failed", adata->buf); if (*err_continue != MUTT_YES) { e->active = true; @@ -1377,29 +1377,29 @@ int imap_check_mailbox(struct Mailbox *mailbox, bool force) /** * imap_check - Check for new mail - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param force Force a refresh * @retval >0 Success, e.g. #MUTT_REOPENED * @retval -1 Failure */ -int imap_check(struct ImapMboxData *mdata, bool force) +int imap_check(struct ImapAccountData *adata, bool force) { /* overload keyboard timeout to avoid many mailbox checks in a row. * Most users don't like having to wait exactly when they press a key. */ int result = 0; /* try IDLE first, unless force is set */ - if (!force && ImapIdle && mutt_bit_isset(mdata->capabilities, IDLE) && - (mdata->state != IMAP_IDLE || time(NULL) >= mdata->lastread + ImapKeepalive)) + if (!force && ImapIdle && mutt_bit_isset(adata->capabilities, IDLE) && + (adata->state != IMAP_IDLE || time(NULL) >= adata->lastread + ImapKeepalive)) { - if (imap_cmd_idle(mdata) < 0) + if (imap_cmd_idle(adata) < 0) return -1; } - if (mdata->state == IMAP_IDLE) + if (adata->state == IMAP_IDLE) { - while ((result = mutt_socket_poll(mdata->conn, 0)) > 0) + while ((result = mutt_socket_poll(adata->conn, 0)) > 0) { - if (imap_cmd_step(mdata) != IMAP_CMD_CONTINUE) + if (imap_cmd_step(adata) != IMAP_CMD_CONTINUE) { mutt_debug(1, "Error reading IDLE response\n"); return -1; @@ -1408,28 +1408,28 @@ int imap_check(struct ImapMboxData *mdata, bool force) if (result < 0) { mutt_debug(1, "Poll failed, disabling IDLE\n"); - mutt_bit_unset(mdata->capabilities, IDLE); + mutt_bit_unset(adata->capabilities, IDLE); } } - if ((force || (mdata->state != IMAP_IDLE && time(NULL) >= mdata->lastread + Timeout)) && - imap_exec(mdata, "NOOP", IMAP_CMD_POLL) != 0) + if ((force || (adata->state != IMAP_IDLE && time(NULL) >= adata->lastread + Timeout)) && + imap_exec(adata, "NOOP", IMAP_CMD_POLL) != 0) { return -1; } /* We call this even when we haven't run NOOP in case we have pending * changes to process, since we can reopen here. */ - imap_cmd_finish(mdata); + imap_cmd_finish(adata); - if (mdata->check_status & IMAP_EXPUNGE_PENDING) + if (adata->check_status & IMAP_EXPUNGE_PENDING) result = MUTT_REOPENED; - else if (mdata->check_status & IMAP_NEWMAIL_PENDING) + else if (adata->check_status & IMAP_NEWMAIL_PENDING) result = MUTT_NEW_MAIL; - else if (mdata->check_status & IMAP_FLAGS_PENDING) + else if (adata->check_status & IMAP_FLAGS_PENDING) result = MUTT_FLAGS; - mdata->check_status = 0; + adata->check_status = 0; return result; } @@ -1445,8 +1445,8 @@ int imap_check(struct ImapMboxData *mdata, bool force) */ int imap_mailbox_check(bool check_stats) { - struct ImapMboxData *mdata = NULL; - struct ImapMboxData *lastdata = NULL; + struct ImapAccountData *adata = NULL; + struct ImapAccountData *lastdata = NULL; char name[LONG_STRING]; char command[LONG_STRING * 2]; char munged[LONG_STRING]; @@ -1465,7 +1465,7 @@ int imap_mailbox_check(bool check_stats) if (np->m->magic != MUTT_IMAP) continue; - if (get_mailbox(np->m->path, &mdata, name, sizeof(name)) < 0) + if (get_mailbox(np->m->path, &adata, name, sizeof(name)) < 0) { np->m->has_new = false; continue; @@ -1473,22 +1473,22 @@ int imap_mailbox_check(bool check_stats) /* Don't issue STATUS on the selected mailbox, it will be NOOPed or * IDLEd elsewhere. - * mdata->mailbox may be NULL for connections other than the current + * adata->mailbox may be NULL for connections other than the current * mailbox's, and shouldn't expand to INBOX in that case. #3216. */ - if (mdata->mbox_name && (imap_mxcmp(name, mdata->mbox_name) == 0)) + if (adata->mbox_name && (imap_mxcmp(name, adata->mbox_name) == 0)) { np->m->has_new = false; continue; } - if (!mutt_bit_isset(mdata->capabilities, IMAP4REV1) && - !mutt_bit_isset(mdata->capabilities, STATUS)) + if (!mutt_bit_isset(adata->capabilities, IMAP4REV1) && + !mutt_bit_isset(adata->capabilities, STATUS)) { mutt_debug(2, "Server doesn't support STATUS\n"); continue; } - if (lastdata && mdata != lastdata) + if (lastdata && adata != lastdata) { /* Send commands to previous server. Sorting the mailbox list * may prevent some infelicitous interleavings */ @@ -1499,9 +1499,9 @@ int imap_mailbox_check(bool check_stats) } if (!lastdata) - lastdata = mdata; + lastdata = adata; - imap_munge_mbox_name(mdata, munged, sizeof(munged), name); + imap_munge_mbox_name(adata, munged, sizeof(munged), name); if (check_stats) { snprintf(command, sizeof(command), @@ -1513,7 +1513,7 @@ int imap_mailbox_check(bool check_stats) "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged); } - if (imap_exec(mdata, command, IMAP_CMD_QUEUE | IMAP_CMD_POLL) < 0) + if (imap_exec(adata, command, IMAP_CMD_QUEUE | IMAP_CMD_POLL) < 0) { mutt_debug(1, "Error queueing command\n"); return 0; @@ -1550,26 +1550,26 @@ int imap_status(const char *path, bool queue) { static int queued = 0; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char buf[LONG_STRING * 2]; char mbox[LONG_STRING]; struct ImapStatus *status = NULL; - if (get_mailbox(path, &mdata, buf, sizeof(buf)) < 0) + if (get_mailbox(path, &adata, buf, sizeof(buf)) < 0) return -1; /* We are in the folder we're polling - just return the mailbox count. * * Note that imap_mxcmp() converts NULL to "INBOX", so we need to - * make sure the mdata really is open to a folder. */ - if (mdata->ctx && !imap_mxcmp(buf, mdata->mbox_name)) - return mdata->ctx->mailbox->msg_count; - else if (mutt_bit_isset(mdata->capabilities, IMAP4REV1) || - mutt_bit_isset(mdata->capabilities, STATUS)) + * make sure the adata really is open to a folder. */ + if (adata->ctx && !imap_mxcmp(buf, adata->mbox_name)) + return adata->ctx->mailbox->msg_count; + else if (mutt_bit_isset(adata->capabilities, IMAP4REV1) || + mutt_bit_isset(adata->capabilities, STATUS)) { - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), buf); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), buf); snprintf(buf, sizeof(buf), "STATUS %s (%s)", mbox, "MESSAGES"); - imap_unmunge_mbox_name(mdata, mbox); + imap_unmunge_mbox_name(adata, mbox); } else { @@ -1580,15 +1580,15 @@ int imap_status(const char *path, bool queue) if (queue) { - imap_exec(mdata, buf, IMAP_CMD_QUEUE); + imap_exec(adata, buf, IMAP_CMD_QUEUE); queued = 1; return 0; } else if (!queued) - imap_exec(mdata, buf, 0); + imap_exec(adata, buf, 0); queued = 0; - status = imap_mboxcache_get(mdata, mbox, false); + status = imap_mboxcache_get(adata, mbox, false); if (status) return status->messages; @@ -1597,7 +1597,7 @@ int imap_status(const char *path, bool queue) /** * imap_mboxcache_get - Open an hcache for a mailbox - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param mbox Mailbox to cache * @param create Should it be created if it doesn't exist? * @retval ptr Stats of cached mailbox @@ -1606,11 +1606,11 @@ int imap_status(const char *path, bool queue) * * return cached mailbox stats or NULL if create is 0 */ -struct ImapStatus *imap_mboxcache_get(struct ImapMboxData *mdata, const char *mbox, bool create) +struct ImapStatus *imap_mboxcache_get(struct ImapAccountData *adata, const char *mbox, bool create) { struct ImapStatus *status = NULL; struct ListNode *np = NULL; - STAILQ_FOREACH(np, &mdata->mboxcache, entries) + STAILQ_FOREACH(np, &adata->mboxcache, entries) { status = (struct ImapStatus *) np->data; @@ -1624,13 +1624,13 @@ struct ImapStatus *imap_mboxcache_get(struct ImapMboxData *mdata, const char *mb { struct ImapStatus *scache = mutt_mem_calloc(1, sizeof(struct ImapStatus)); scache->name = (char *) mbox; - mutt_list_insert_tail(&mdata->mboxcache, (char *) scache); - status = imap_mboxcache_get(mdata, mbox, false); + mutt_list_insert_tail(&adata->mboxcache, (char *) scache); + status = imap_mboxcache_get(adata, mbox, false); status->name = mutt_str_strdup(mbox); } #ifdef USE_HCACHE - header_cache_t *hc = imap_hcache_open(mdata, mbox); + header_cache_t *hc = imap_hcache_open(adata, mbox); if (hc) { void *uidvalidity = mutt_hcache_fetch_raw(hc, "/UIDVALIDITY", 12); @@ -1644,7 +1644,7 @@ struct ImapStatus *imap_mboxcache_get(struct ImapMboxData *mdata, const char *mb mutt_hcache_free(hc, &uidnext); mutt_hcache_free(hc, (void **) &modseq); mutt_hcache_close(hc); - return imap_mboxcache_get(mdata, mbox, true); + return imap_mboxcache_get(adata, mbox, true); } status->uidvalidity = *(unsigned int *) uidvalidity; status->uidnext = uidnext ? *(unsigned int *) uidnext : 0; @@ -1664,20 +1664,20 @@ struct ImapStatus *imap_mboxcache_get(struct ImapMboxData *mdata, const char *mb /** * imap_mboxcache_free - Free the cached ImapStatus - * @param mdata Imap Mailbox data + * @param adata Imap Account data */ -void imap_mboxcache_free(struct ImapMboxData *mdata) +void imap_mboxcache_free(struct ImapAccountData *adata) { struct ImapStatus *status = NULL; struct ListNode *np = NULL; - STAILQ_FOREACH(np, &mdata->mboxcache, entries) + STAILQ_FOREACH(np, &adata->mboxcache, entries) { status = (struct ImapStatus *) np->data; FREE(&status->name); } - mutt_list_free(&mdata->mboxcache); + mutt_list_free(&adata->mboxcache); } /** @@ -1690,7 +1690,7 @@ void imap_mboxcache_free(struct ImapMboxData *mdata) int imap_search(struct Mailbox *mailbox, const struct Pattern *pat) { struct Buffer buf; - struct ImapMboxData *mdata = mailbox->data; + struct ImapAccountData *adata = mailbox->data; for (int i = 0; i < mailbox->msg_count; i++) mailbox->hdrs[i]->matched = false; @@ -1704,7 +1704,7 @@ int imap_search(struct Mailbox *mailbox, const struct Pattern *pat) FREE(&buf.data); return -1; } - if (imap_exec(mdata, buf.data, 0) < 0) + if (imap_exec(adata, buf.data, 0) < 0) { FREE(&buf.data); return -1; @@ -1723,7 +1723,7 @@ int imap_search(struct Mailbox *mailbox, const struct Pattern *pat) */ int imap_subscribe(char *path, bool subscribe) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char buf[LONG_STRING * 2]; char mbox[LONG_STRING]; char errstr[STRING]; @@ -1736,11 +1736,11 @@ int imap_subscribe(char *path, bool subscribe) mutt_error(_("Bad mailbox name")); return -1; } - mdata = imap_conn_find(&(mx.account), 0); - if (!mdata) + adata = imap_conn_find(&(mx.account), 0); + if (!adata) goto fail; - imap_fix_path(mdata, mx.mbox, buf, sizeof(buf)); + imap_fix_path(adata, mx.mbox, buf, sizeof(buf)); if (!*buf) mutt_str_strfcpy(buf, "INBOX", sizeof(buf)); @@ -1761,14 +1761,14 @@ int imap_subscribe(char *path, bool subscribe) mutt_message(_("Subscribing to %s..."), buf); else mutt_message(_("Unsubscribing from %s..."), buf); - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), buf); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), buf); snprintf(buf, sizeof(buf), "%sSUBSCRIBE %s", subscribe ? "" : "UN", mbox); - if (imap_exec(mdata, buf, 0) < 0) + if (imap_exec(adata, buf, 0) < 0) goto fail; - imap_unmunge_mbox_name(mdata, mx.mbox); + imap_unmunge_mbox_name(adata, mx.mbox); if (subscribe) mutt_message(_("Subscribed to %s"), mx.mbox); else @@ -1794,7 +1794,7 @@ fail: */ int imap_complete(char *buf, size_t buflen, char *path) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char list[LONG_STRING]; char tmp[LONG_STRING * 2]; struct ImapList listresp; @@ -1813,8 +1813,8 @@ int imap_complete(char *buf, size_t buflen, char *path) /* don't open a new socket just for completion. Instead complete over * known mailboxes/hooks/etc */ - mdata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NONEW); - if (!mdata) + adata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NONEW); + if (!adata) { FREE(&mx.mbox); mutt_str_strfcpy(buf, path, buflen); @@ -1824,23 +1824,23 @@ int imap_complete(char *buf, size_t buflen, char *path) /* reformat path for IMAP list, and append wildcard */ /* don't use INBOX in place of "" */ if (mx.mbox && mx.mbox[0]) - imap_fix_path(mdata, mx.mbox, list, sizeof(list)); + imap_fix_path(adata, mx.mbox, list, sizeof(list)); else list[0] = '\0'; /* fire off command */ snprintf(tmp, sizeof(tmp), "%s \"\" \"%s%%\"", ImapListSubscribed ? "LSUB" : "LIST", list); - imap_cmd_start(mdata, tmp); + imap_cmd_start(adata, tmp); /* and see what the results are */ mutt_str_strfcpy(completion, mx.mbox, sizeof(completion)); - mdata->cmdtype = IMAP_CT_LIST; - mdata->cmddata = &listresp; + adata->cmdtype = IMAP_CT_LIST; + adata->cmddata = &listresp; do { listresp.name = NULL; - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc == IMAP_CMD_CONTINUE && listresp.name) { @@ -1865,7 +1865,7 @@ int imap_complete(char *buf, size_t buflen, char *path) completions++; } } while (rc == IMAP_CMD_CONTINUE); - mdata->cmddata = NULL; + adata->cmddata = NULL; if (completions) { @@ -1899,7 +1899,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) struct Buffer *sync_cmd = NULL; int err_continue = MUTT_NO; - struct ImapMboxData *mdata = mailbox->data; + struct ImapAccountData *adata = mailbox->data; if (imap_parse_path(dest, &mx)) { @@ -1908,16 +1908,16 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) } /* check that the save-to folder is in the same account */ - if (!mutt_account_match(&(mdata->conn->account), &(mx.account))) + if (!mutt_account_match(&(adata->conn->account), &(mx.account))) { mutt_debug(3, "%s not same server as %s\n", dest, mailbox->path); return 1; } - imap_fix_path(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox)); if (!*mbox) mutt_str_strfcpy(mbox, "INBOX", sizeof(mbox)); - imap_munge_mbox_name(mdata, mmbox, sizeof(mmbox), mbox); + imap_munge_mbox_name(adata, mmbox, sizeof(mmbox), mbox); sync_cmd = mutt_buffer_new(); for (int i = 0; i < mailbox->msg_count; i++) @@ -1925,7 +1925,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) if (mailbox->hdrs[i]->active && mailbox->hdrs[i]->changed && mailbox->hdrs[i]->deleted && !mailbox->hdrs[i]->purge) { - rc = imap_sync_message_for_copy(mdata, mailbox->hdrs[i], sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(adata, mailbox->hdrs[i], sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "could not sync\n"); @@ -1937,7 +1937,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) /* loop in case of TRYCREATE */ do { - rc = imap_exec_msgset(mdata, "UID COPY", mmbox, MUTT_TRASH, false, false); + rc = imap_exec_msgset(adata, "UID COPY", mmbox, MUTT_TRASH, false, false); if (!rc) { mutt_debug(1, "No messages to trash\n"); @@ -1956,7 +1956,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) } /* let's get it on */ - rc = imap_exec(mdata, NULL, IMAP_CMD_FAIL_OK); + rc = imap_exec(adata, NULL, IMAP_CMD_FAIL_OK); if (rc == -2) { if (triedcreate) @@ -1965,7 +1965,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) break; } /* bail out if command failed for reasons other than nonexistent target */ - if (mutt_str_strncasecmp(imap_get_qualifier(mdata->buf), "[TRYCREATE]", 11) != 0) + if (mutt_str_strncasecmp(imap_get_qualifier(adata->buf), "[TRYCREATE]", 11) != 0) break; mutt_debug(3, "server suggests TRYCREATE\n"); snprintf(prompt, sizeof(prompt), _("Create %s?"), mbox); @@ -1974,7 +1974,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) mutt_clear_error(); goto out; } - if (imap_create_mailbox(mdata, mbox) < 0) + if (imap_create_mailbox(adata, mbox) < 0) break; triedcreate = true; } @@ -1982,7 +1982,7 @@ int imap_fast_trash(struct Mailbox *mailbox, char *dest) if (rc != 0) { - imap_error("imap_fast_trash", mdata->buf); + imap_error("imap_fast_trash", adata->buf); goto out; } @@ -2010,9 +2010,9 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) int oldsort; int rc; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; - if (mdata->state < IMAP_SELECTED) + if (adata->state < IMAP_SELECTED) { mutt_debug(2, "no mailbox selected\n"); return -1; @@ -2022,14 +2022,14 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) * to be changed. */ imap_allow_reopen(ctx); - rc = imap_check(mdata, false); + rc = imap_check(adata, false); if (rc != 0) return rc; /* if we are expunging anyway, we can do deleted messages very quickly... */ if (expunge && mutt_bit_isset(ctx->mailbox->rights, MUTT_ACL_DELETE)) { - rc = imap_exec_msgset(mdata, "UID STORE", "+FLAGS.SILENT (\\Deleted)", + rc = imap_exec_msgset(adata, "UID STORE", "+FLAGS.SILENT (\\Deleted)", MUTT_DELETED, true, false); if (rc < 0) { @@ -2051,7 +2051,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) } #ifdef USE_HCACHE - mdata->hcache = imap_hcache_open(mdata, NULL); + adata->hcache = imap_hcache_open(adata, NULL); #endif /* save messages with real (non-flag) changes */ @@ -2061,16 +2061,16 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) if (e->deleted) { - imap_cache_del(mdata, e); + imap_cache_del(adata, e); #ifdef USE_HCACHE - imap_hcache_del(mdata, IMAP_EDATA(e)->uid); + imap_hcache_del(adata, IMAP_EDATA(e)->uid); #endif } if (e->active && e->changed) { #ifdef USE_HCACHE - imap_hcache_put(mdata, e); + imap_hcache_put(adata, e); #endif /* if the message has been rethreaded or attachments have been deleted * we delete the message and reupload it. @@ -2094,7 +2094,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) } #ifdef USE_HCACHE - imap_hcache_close(mdata); + imap_hcache_close(adata); #endif /* presort here to avoid doing 10 resorts in imap_exec_msgset */ @@ -2111,15 +2111,15 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) mutt_get_sort_func(SORT_ORDER)); } - rc = sync_helper(mdata, MUTT_ACL_DELETE, MUTT_DELETED, "\\Deleted"); + rc = sync_helper(adata, MUTT_ACL_DELETE, MUTT_DELETED, "\\Deleted"); if (rc >= 0) - rc |= sync_helper(mdata, MUTT_ACL_WRITE, MUTT_FLAG, "\\Flagged"); + rc |= sync_helper(adata, MUTT_ACL_WRITE, MUTT_FLAG, "\\Flagged"); if (rc >= 0) - rc |= sync_helper(mdata, MUTT_ACL_WRITE, MUTT_OLD, "Old"); + rc |= sync_helper(adata, MUTT_ACL_WRITE, MUTT_OLD, "Old"); if (rc >= 0) - rc |= sync_helper(mdata, MUTT_ACL_SEEN, MUTT_READ, "\\Seen"); + rc |= sync_helper(adata, MUTT_ACL_SEEN, MUTT_READ, "\\Seen"); if (rc >= 0) - rc |= sync_helper(mdata, MUTT_ACL_WRITE, MUTT_REPLIED, "\\Answered"); + rc |= sync_helper(adata, MUTT_ACL_WRITE, MUTT_REPLIED, "\\Answered"); if (oldsort != Sort) { @@ -2130,7 +2130,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) /* Flush the queued flags if any were changed in sync_helper. */ if (rc > 0) - if (imap_exec(mdata, NULL, 0) != IMAP_CMD_OK) + if (imap_exec(adata, NULL, 0) != IMAP_CMD_OK) rc = -1; if (rc < 0) @@ -2140,7 +2140,7 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) if (mutt_yesorno(_("Error saving flags. Close anyway?"), 0) == MUTT_YES) { rc = 0; - mdata->state = IMAP_AUTHENTICATED; + adata->state = IMAP_AUTHENTICATED; goto out; } } @@ -2169,25 +2169,25 @@ int imap_sync_mailbox(struct Context *ctx, bool expunge) { mutt_message(_("Expunging messages from server...")); /* Set expunge bit so we don't get spurious reopened messages */ - mdata->reopen |= IMAP_EXPUNGE_EXPECTED; - if (imap_exec(mdata, "EXPUNGE", 0) != 0) + adata->reopen |= IMAP_EXPUNGE_EXPECTED; + if (imap_exec(adata, "EXPUNGE", 0) != 0) { - mdata->reopen &= ~IMAP_EXPUNGE_EXPECTED; - imap_error(_("imap_sync_mailbox: EXPUNGE failed"), mdata->buf); + adata->reopen &= ~IMAP_EXPUNGE_EXPECTED; + imap_error(_("imap_sync_mailbox: EXPUNGE failed"), adata->buf); rc = -1; goto out; } - mdata->reopen &= ~IMAP_EXPUNGE_EXPECTED; + adata->reopen &= ~IMAP_EXPUNGE_EXPECTED; } if (expunge && ctx->mailbox->closing) { - imap_exec(mdata, "CLOSE", IMAP_CMD_QUEUE); - mdata->state = IMAP_AUTHENTICATED; + imap_exec(adata, "CLOSE", IMAP_CMD_QUEUE); + adata->state = IMAP_AUTHENTICATED; } if (MessageCacheClean) - imap_cache_clean(mdata); + imap_cache_clean(adata); rc = 0; @@ -2205,7 +2205,7 @@ out: */ static int imap_mbox_open(struct Context *ctx) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct ImapStatus *status = NULL; char buf[PATH_MAX]; char bufout[PATH_MAX]; @@ -2221,55 +2221,55 @@ static int imap_mbox_open(struct Context *ctx) } /* we require a connection which isn't currently in IMAP_SELECTED state */ - mdata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NOSELECT); - if (!mdata) + adata = imap_conn_find(&(mx.account), MUTT_IMAP_CONN_NOSELECT); + if (!adata) goto fail_noidata; - if (mdata->state < IMAP_AUTHENTICATED) + if (adata->state < IMAP_AUTHENTICATED) goto fail; /* once again the context is new */ - ctx->mailbox->data = mdata; + ctx->mailbox->data = adata; /* Clean up path and replace the one in the mailbox */ - imap_fix_path(mdata, mx.mbox, buf, sizeof(buf)); + imap_fix_path(adata, mx.mbox, buf, sizeof(buf)); if (!*buf) mutt_str_strfcpy(buf, "INBOX", sizeof(buf)); - FREE(&(mdata->mbox_name)); - mdata->mbox_name = mutt_str_strdup(buf); - imap_qualify_path(buf, sizeof(buf), &mx, mdata->mbox_name); + FREE(&(adata->mbox_name)); + adata->mbox_name = mutt_str_strdup(buf); + imap_qualify_path(buf, sizeof(buf), &mx, adata->mbox_name); mutt_str_strfcpy(ctx->mailbox->path, buf, sizeof(ctx->mailbox->path)); mutt_str_strfcpy(ctx->mailbox->realpath, ctx->mailbox->path, sizeof(ctx->mailbox->realpath)); - mdata->ctx = ctx; + adata->ctx = ctx; /* clear mailbox status */ - mdata->status = false; - memset(mdata->ctx->mailbox->rights, 0, sizeof(mdata->ctx->mailbox->rights)); - mdata->new_mail_count = 0; - mdata->max_msn = 0; + adata->status = false; + memset(adata->ctx->mailbox->rights, 0, sizeof(adata->ctx->mailbox->rights)); + adata->new_mail_count = 0; + adata->max_msn = 0; - mutt_message(_("Selecting %s..."), mdata->mbox_name); - imap_munge_mbox_name(mdata, buf, sizeof(buf), mdata->mbox_name); + mutt_message(_("Selecting %s..."), adata->mbox_name); + imap_munge_mbox_name(adata, buf, sizeof(buf), adata->mbox_name); /* pipeline ACL test */ - if (mutt_bit_isset(mdata->capabilities, ACL)) + if (mutt_bit_isset(adata->capabilities, ACL)) { snprintf(bufout, sizeof(bufout), "MYRIGHTS %s", buf); - imap_exec(mdata, bufout, IMAP_CMD_QUEUE); + imap_exec(adata, bufout, IMAP_CMD_QUEUE); } /* assume we have all rights if ACL is unavailable */ else { - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_READ); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_SEEN); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_INSERT); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_POST); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_CREATE); - mutt_bit_set(mdata->ctx->mailbox->rights, MUTT_ACL_DELETE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_LOOKUP); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_READ); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_SEEN); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_WRITE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_INSERT); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_POST); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_CREATE); + mutt_bit_set(adata->ctx->mailbox->rights, MUTT_ACL_DELETE); } /* pipeline the postponed count if possible */ pmx.mbox = NULL; @@ -2281,10 +2281,10 @@ static int imap_mbox_open(struct Context *ctx) FREE(&pmx.mbox); if (ImapCheckSubscribed) - imap_exec(mdata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE); + imap_exec(adata, "LSUB \"\" \"*\"", IMAP_CMD_QUEUE); #ifdef USE_HCACHE - if (mutt_bit_isset(mdata->capabilities, CONDSTORE) && ImapCondStore) + if (mutt_bit_isset(adata->capabilities, CONDSTORE) && ImapCondStore) condstore = " (CONDSTORE)"; else #endif @@ -2293,31 +2293,31 @@ static int imap_mbox_open(struct Context *ctx) snprintf(bufout, sizeof(bufout), "%s %s%s", ctx->mailbox->readonly ? "EXAMINE" : "SELECT", buf, condstore); - mdata->state = IMAP_SELECTED; + adata->state = IMAP_SELECTED; - imap_cmd_start(mdata, bufout); + imap_cmd_start(adata, bufout); - status = imap_mboxcache_get(mdata, mdata->mbox_name, true); + status = imap_mboxcache_get(adata, adata->mbox_name, true); do { char *pc = NULL; - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) break; - pc = mdata->buf + 2; + pc = adata->buf + 2; /* Obtain list of available flags here, may be overridden by a * PERMANENTFLAGS tag in the OK response */ if (mutt_str_strncasecmp("FLAGS", pc, 5) == 0) { /* don't override PERMANENTFLAGS */ - if (STAILQ_EMPTY(&mdata->flags)) + if (STAILQ_EMPTY(&adata->flags)) { mutt_debug(3, "Getting mailbox FLAGS\n"); - pc = get_flags(&mdata->flags, pc); + pc = get_flags(&adata->flags, pc); if (!pc) goto fail; } @@ -2327,10 +2327,10 @@ static int imap_mbox_open(struct Context *ctx) { mutt_debug(3, "Getting mailbox PERMANENTFLAGS\n"); /* safe to call on NULL */ - mutt_list_free(&mdata->flags); + mutt_list_free(&adata->flags); /* skip "OK [PERMANENT" so syntax is the same as FLAGS */ pc += 13; - pc = get_flags(&(mdata->flags), pc); + pc = get_flags(&(adata->flags), pc); if (!pc) goto fail; } @@ -2340,47 +2340,47 @@ static int imap_mbox_open(struct Context *ctx) mutt_debug(3, "Getting mailbox UIDVALIDITY\n"); pc += 3; pc = imap_next_word(pc); - if (mutt_str_atoui(pc, &mdata->uid_validity) < 0) + if (mutt_str_atoui(pc, &adata->uid_validity) < 0) goto fail; - status->uidvalidity = mdata->uid_validity; + status->uidvalidity = adata->uid_validity; } else if (mutt_str_strncasecmp("OK [UIDNEXT", pc, 11) == 0) { mutt_debug(3, "Getting mailbox UIDNEXT\n"); pc += 3; pc = imap_next_word(pc); - if (mutt_str_atoui(pc, &mdata->uidnext) < 0) + if (mutt_str_atoui(pc, &adata->uidnext) < 0) goto fail; - status->uidnext = mdata->uidnext; + status->uidnext = adata->uidnext; } else if (mutt_str_strncasecmp("OK [HIGHESTMODSEQ", pc, 17) == 0) { mutt_debug(3, "Getting mailbox HIGHESTMODSEQ\n"); pc += 3; pc = imap_next_word(pc); - if (mutt_str_atoull(pc, &mdata->modseq) < 0) + if (mutt_str_atoull(pc, &adata->modseq) < 0) goto fail; - status->modseq = mdata->modseq; + status->modseq = adata->modseq; } else if (mutt_str_strncasecmp("OK [NOMODSEQ", pc, 12) == 0) { mutt_debug(3, "Mailbox has NOMODSEQ set\n"); - status->modseq = mdata->modseq = 0; + status->modseq = adata->modseq = 0; } else { pc = imap_next_word(pc); if (mutt_str_strncasecmp("EXISTS", pc, 6) == 0) { - count = mdata->new_mail_count; - mdata->new_mail_count = 0; + count = adata->new_mail_count; + adata->new_mail_count = 0; } } } while (rc == IMAP_CMD_CONTINUE); if (rc == IMAP_CMD_NO) { - char *s = imap_next_word(mdata->buf); /* skip seq */ + char *s = imap_next_word(adata->buf); /* skip seq */ s = imap_next_word(s); /* Skip response */ mutt_error("%s", s); goto fail; @@ -2390,8 +2390,8 @@ static int imap_mbox_open(struct Context *ctx) goto fail; /* check for READ-ONLY notification */ - if ((mutt_str_strncasecmp(imap_get_qualifier(mdata->buf), "[READ-ONLY]", 11) == 0) && - !mutt_bit_isset(mdata->capabilities, ACL)) + if ((mutt_str_strncasecmp(imap_get_qualifier(adata->buf), "[READ-ONLY]", 11) == 0) && + !mutt_bit_isset(adata->capabilities, ACL)) { mutt_debug(2, "Mailbox is read-only.\n"); ctx->mailbox->readonly = true; @@ -2400,7 +2400,7 @@ static int imap_mbox_open(struct Context *ctx) /* dump the mailbox flags we've found */ if (DebugLevel > 2) { - if (STAILQ_EMPTY(&mdata->flags)) + if (STAILQ_EMPTY(&adata->flags)) mutt_debug(3, "No folder flags found\n"); else { @@ -2408,7 +2408,7 @@ static int imap_mbox_open(struct Context *ctx) struct Buffer flag_buffer; mutt_buffer_init(&flag_buffer); mutt_buffer_printf(&flag_buffer, "Mailbox flags: "); - STAILQ_FOREACH(np, &mdata->flags, entries) + STAILQ_FOREACH(np, &adata->flags, entries) { mutt_buffer_printf(&flag_buffer, "[%s] ", np->data); } @@ -2417,10 +2417,10 @@ static int imap_mbox_open(struct Context *ctx) } } - if (!(mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_DELETE) || - mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_SEEN) || - mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE) || - mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_INSERT))) + if (!(mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_DELETE) || + mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_SEEN) || + mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_WRITE) || + mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_INSERT))) { ctx->mailbox->readonly = true; } @@ -2430,7 +2430,7 @@ static int imap_mbox_open(struct Context *ctx) ctx->mailbox->v2r = mutt_mem_calloc(count, sizeof(int)); ctx->mailbox->msg_count = 0; - if (count && (imap_read_headers(mdata, 1, count, true) < 0)) + if (count && (imap_read_headers(adata, 1, count, true) < 0)) { mutt_error(_("Error opening mailbox")); goto fail; @@ -2441,8 +2441,8 @@ static int imap_mbox_open(struct Context *ctx) return 0; fail: - if (mdata->state == IMAP_SELECTED) - mdata->state = IMAP_AUTHENTICATED; + if (adata->state == IMAP_SELECTED) + adata->state = IMAP_AUTHENTICATED; fail_noidata: FREE(&mx.mbox); return -1; @@ -2453,7 +2453,7 @@ fail_noidata: */ static int imap_mbox_open_append(struct Context *ctx, int flags) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char mailbox[PATH_MAX]; struct ImapMbox mx; int rc; @@ -2464,16 +2464,16 @@ static int imap_mbox_open_append(struct Context *ctx, int flags) /* in APPEND mode, we appear to hijack an existing IMAP connection - * ctx is brand new and mostly empty */ - mdata = imap_conn_find(&(mx.account), 0); - if (!mdata) + adata = imap_conn_find(&(mx.account), 0); + if (!adata) { FREE(&mx.mbox); return -1; } - ctx->mailbox->data = mdata; + ctx->mailbox->data = adata; - imap_fix_path(mdata, mx.mbox, mailbox, sizeof(mailbox)); + imap_fix_path(adata, mx.mbox, mailbox, sizeof(mailbox)); if (!*mailbox) mutt_str_strfcpy(mailbox, "INBOX", sizeof(mailbox)); FREE(&mx.mbox); @@ -2490,7 +2490,7 @@ static int imap_mbox_open_append(struct Context *ctx, int flags) if (Confirmcreate && mutt_yesorno(buf, 1) != MUTT_YES) return -1; - if (imap_create_mailbox(mdata, mailbox) < 0) + if (imap_create_mailbox(adata, mailbox) < 0) return -1; return 0; @@ -2523,50 +2523,50 @@ static int imap_mbox_check(struct Context *ctx, int *index_hint) */ static int imap_mbox_close(struct Context *ctx) { - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; /* Check to see if the mailbox is actually open */ - if (!mdata) + if (!adata) return 0; - /* imap_mbox_open_append() borrows the struct ImapMboxData temporarily, - * just for the connection, but does not set mdata->ctx to the + /* imap_mbox_open_append() borrows the struct ImapAccountData temporarily, + * just for the connection, but does not set adata->ctx to the * open-append ctx. * * So when these are equal, it means we are actually closing the - * mailbox and should clean up mdata. Otherwise, we don't want to - * touch mdata - it's still being used. + * mailbox and should clean up adata. Otherwise, we don't want to + * touch adata - it's still being used. */ - if (ctx == mdata->ctx) + if (ctx == adata->ctx) { - if (mdata->status != IMAP_FATAL && mdata->state >= IMAP_SELECTED) + if (adata->status != IMAP_FATAL && adata->state >= IMAP_SELECTED) { /* mx_mbox_close won't sync if there are no deleted messages * and the mailbox is unchanged, so we may have to close here */ if (!ctx->deleted) - imap_exec(mdata, "CLOSE", IMAP_CMD_QUEUE); - mdata->state = IMAP_AUTHENTICATED; + imap_exec(adata, "CLOSE", IMAP_CMD_QUEUE); + adata->state = IMAP_AUTHENTICATED; } - mdata->reopen &= IMAP_REOPEN_ALLOW; - FREE(&(mdata->mbox_name)); - mutt_list_free(&mdata->flags); - mdata->ctx = NULL; + adata->reopen &= IMAP_REOPEN_ALLOW; + FREE(&(adata->mbox_name)); + mutt_list_free(&adata->flags); + adata->ctx = NULL; - mutt_hash_destroy(&mdata->uid_hash); - FREE(&mdata->msn_index); - mdata->msn_index_size = 0; - mdata->max_msn = 0; + mutt_hash_destroy(&adata->uid_hash); + FREE(&adata->msn_index); + adata->msn_index_size = 0; + adata->max_msn = 0; for (int i = 0; i < IMAP_CACHE_LEN; i++) { - if (mdata->cache[i].path) + if (adata->cache[i].path) { - unlink(mdata->cache[i].path); - FREE(&mdata->cache[i].path); + unlink(adata->cache[i].path); + FREE(&adata->cache[i].path); } } - mutt_bcache_close(&mdata->bcache); + mutt_bcache_close(&adata->bcache); } return 0; @@ -2597,10 +2597,10 @@ static int imap_tags_edit(struct Context *ctx, const char *tags, char *buf, size { char *new = NULL; char *checker = NULL; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; /* Check for \* flags capability */ - if (!imap_has_flag(&mdata->flags, NULL)) + if (!imap_has_flag(&adata->flags, NULL)) { mutt_error(_("IMAP server doesn't support custom flags")); return -1; @@ -2684,12 +2684,12 @@ static int imap_tags_commit(struct Context *ctx, struct Email *e, char *buf) struct Buffer *cmd = NULL; char uid[11]; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; if (*buf == '\0') buf = NULL; - if (!mutt_bit_isset(mdata->ctx->mailbox->rights, MUTT_ACL_WRITE)) + if (!mutt_bit_isset(adata->ctx->mailbox->rights, MUTT_ACL_WRITE)) return 0; snprintf(uid, sizeof(uid), "%u", IMAP_EDATA(e)->uid); @@ -2712,7 +2712,7 @@ static int imap_tags_commit(struct Context *ctx, struct Email *e, char *buf) /* Should we return here, or we are fine and we could * continue to add new flags */ - if (imap_exec(mdata, cmd->data, 0) != 0) + if (imap_exec(adata, cmd->data, 0) != 0) { mutt_buffer_free(&cmd); return -1; @@ -2737,7 +2737,7 @@ static int imap_tags_commit(struct Context *ctx, struct Email *e, char *buf) mutt_buffer_addstr(cmd, buf); mutt_buffer_addstr(cmd, ")"); - if (imap_exec(mdata, cmd->data, 0) != 0) + if (imap_exec(adata, cmd->data, 0) != 0) { mutt_debug(1, "fail to add new flags\n"); mutt_buffer_free(&cmd); diff --git a/imap/imap_private.h b/imap/imap_private.h index 520fa1600..d4181be7b 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -202,11 +202,11 @@ enum ImapCommandType }; /** - * struct ImapMboxData - IMAP-specific server data + * struct ImapAccountData - IMAP-specific server data * * This data is specific to a Connection to an IMAP server */ -struct ImapMboxData +struct ImapAccountData { struct Connection *conn; bool recovering; @@ -286,40 +286,40 @@ struct SeqsetIterator /* -- private IMAP functions -- */ /* imap.c */ -int imap_check(struct ImapMboxData *mdata, bool force); -int imap_create_mailbox(struct ImapMboxData *mdata, char *mailbox); -int imap_rename_mailbox(struct ImapMboxData *mdata, struct ImapMbox *mx, const char *newname); -struct ImapStatus *imap_mboxcache_get(struct ImapMboxData *mdata, const char *mbox, bool create); -void imap_mboxcache_free(struct ImapMboxData *mdata); -int imap_exec_msgset(struct ImapMboxData *mdata, const char *pre, const char *post, +int imap_check(struct ImapAccountData *adata, bool force); +int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox); +int imap_rename_mailbox(struct ImapAccountData *adata, struct ImapMbox *mx, const char *newname); +struct ImapStatus *imap_mboxcache_get(struct ImapAccountData *adata, const char *mbox, bool create); +void imap_mboxcache_free(struct ImapAccountData *adata); +int imap_exec_msgset(struct ImapAccountData *adata, const char *pre, const char *post, int flag, bool changed, bool invert); -int imap_open_connection(struct ImapMboxData *mdata); -void imap_close_connection(struct ImapMboxData *mdata); -struct ImapMboxData *imap_conn_find(const struct ConnAccount *account, int flags); -int imap_read_literal(FILE *fp, struct ImapMboxData *mdata, unsigned long bytes, struct Progress *pbar); -void imap_expunge_mailbox(struct ImapMboxData *mdata); -void imap_logout(struct ImapMboxData **mdata); -int imap_sync_message_for_copy(struct ImapMboxData *mdata, struct Email *e, struct Buffer *cmd, int *err_continue); +int imap_open_connection(struct ImapAccountData *adata); +void imap_close_connection(struct ImapAccountData *adata); +struct ImapAccountData *imap_conn_find(const struct ConnAccount *account, int flags); +int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *pbar); +void imap_expunge_mailbox(struct ImapAccountData *adata); +void imap_logout(struct ImapAccountData **adata); +int imap_sync_message_for_copy(struct ImapAccountData *adata, struct Email *e, struct Buffer *cmd, int *err_continue); bool imap_has_flag(struct ListHead *flag_list, const char *flag); /* auth.c */ -int imap_authenticate(struct ImapMboxData *mdata); +int imap_authenticate(struct ImapAccountData *adata); /* command.c */ -int imap_cmd_start(struct ImapMboxData *mdata, const char *cmdstr); -int imap_cmd_step(struct ImapMboxData *mdata); -void imap_cmd_finish(struct ImapMboxData *mdata); +int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr); +int imap_cmd_step(struct ImapAccountData *adata); +void imap_cmd_finish(struct ImapAccountData *adata); bool imap_code(const char *s); -const char *imap_cmd_trailer(struct ImapMboxData *mdata); -int imap_exec(struct ImapMboxData *mdata, const char *cmdstr, int flags); -int imap_cmd_idle(struct ImapMboxData *mdata); +const char *imap_cmd_trailer(struct ImapAccountData *adata); +int imap_exec(struct ImapAccountData *adata, const char *cmdstr, int flags); +int imap_cmd_idle(struct ImapAccountData *adata); /* message.c */ void imap_free_emaildata(void **data); -int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, unsigned int msn_end, bool initial_download); -char *imap_set_flags(struct ImapMboxData *mdata, struct Email *e, char *s, int *server_changes); -int imap_cache_del(struct ImapMboxData *mdata, struct Email *e); -int imap_cache_clean(struct ImapMboxData *mdata); +int imap_read_headers(struct ImapAccountData *adata, unsigned int msn_begin, unsigned int msn_end, bool initial_download); +char *imap_set_flags(struct ImapAccountData *adata, struct Email *e, char *s, int *server_changes); +int imap_cache_del(struct ImapAccountData *adata, struct Email *e); +int imap_cache_clean(struct ImapAccountData *adata); int imap_append_message(struct Context *ctx, struct Message *msg); int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno); @@ -328,24 +328,22 @@ int imap_msg_commit(struct Context *ctx, struct Message *msg); /* util.c */ #ifdef USE_HCACHE -header_cache_t *imap_hcache_open(struct ImapMboxData *mdata, const char *path); -void imap_hcache_close(struct ImapMboxData *mdata); -struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid); -int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e); -int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid); -int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata); -int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata); -char *imap_hcache_get_uid_seqset(struct ImapMboxData *mdata); +header_cache_t *imap_hcache_open(struct ImapAccountData *adata, const char *path); +void imap_hcache_close(struct ImapAccountData *adata); +struct Email *imap_hcache_get(struct ImapAccountData *adata, unsigned int uid); +int imap_hcache_put(struct ImapAccountData *adata, struct Email *e); +int imap_hcache_del(struct ImapAccountData *adata, unsigned int uid); +int imap_hcache_store_uid_seqset(struct ImapAccountData *adata); +int imap_hcache_clear_uid_seqset(struct ImapAccountData *adata); +char *imap_hcache_get_uid_seqset(struct ImapAccountData *adata); #endif int imap_continue(const char *msg, const char *resp); void imap_error(const char *where, const char *msg); -struct ImapMboxData *imap_mdata_new(void); -void imap_mdata_free(struct ImapMboxData **mdata); struct ImapAccountData *imap_adata_new(void); -void imap_adata_free(void **adata); -char *imap_fix_path(struct ImapMboxData *mdata, const char *mailbox, char *path, size_t plen); -void imap_cachepath(struct ImapMboxData *mdata, const char *mailbox, char *dest, size_t dlen); +void imap_adata_free(struct ImapAccountData **adata); +char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *path, size_t plen); +void imap_cachepath(struct ImapAccountData *adata, const char *mailbox, char *dest, size_t dlen); int imap_get_literal_count(const char *buf, unsigned int *bytes); char *imap_get_qualifier(char *buf); int imap_mxcmp(const char *mx1, const char *mx2); @@ -353,8 +351,8 @@ char *imap_next_word(char *s); void imap_qualify_path(char *buf, size_t buflen, struct ImapMbox *mx, char *path); void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick); void imap_unquote_string(char *s); -void imap_munge_mbox_name(struct ImapMboxData *mdata, char *dest, size_t dlen, const char *src); -void imap_unmunge_mbox_name(struct ImapMboxData *mdata, char *s); +void imap_munge_mbox_name(struct ImapAccountData *adata, char *dest, size_t dlen, const char *src); +void imap_unmunge_mbox_name(struct ImapAccountData *adata, char *s); struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset); int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next); void mutt_seqset_iterator_free(struct SeqsetIterator **p_iter); @@ -362,8 +360,8 @@ bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount * void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen); /* utf7.c */ -void imap_utf_encode(struct ImapMboxData *mdata, char **s); -void imap_utf_decode(struct ImapMboxData *mdata, char **s); +void imap_utf_encode(struct ImapAccountData *adata, char **s); +void imap_utf_decode(struct ImapAccountData *adata, char **s); void imap_allow_reopen(struct Context *ctx); void imap_disallow_reopen(struct Context *ctx); diff --git a/imap/message.c b/imap/message.c index 006283dbc..fd44be413 100644 --- a/imap/message.c +++ b/imap/message.c @@ -78,76 +78,76 @@ static struct ImapEmailData *new_emaildata(void) /** * msg_cache_open - Open a message cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval ptr Success, using existing cache * @retval ptr Success, opened new cache * @retval NULL Failure */ -static struct BodyCache *msg_cache_open(struct ImapMboxData *mdata) +static struct BodyCache *msg_cache_open(struct ImapAccountData *adata) { char mailbox[PATH_MAX]; - if (mdata->bcache) - return mdata->bcache; + if (adata->bcache) + return adata->bcache; - imap_cachepath(mdata, mdata->mbox_name, mailbox, sizeof(mailbox)); + imap_cachepath(adata, adata->mbox_name, mailbox, sizeof(mailbox)); - return mutt_bcache_open(&mdata->conn->account, mailbox); + return mutt_bcache_open(&adata->conn->account, mailbox); } /** * msg_cache_get - Get the message cache entry for an email - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param e Email header * @retval ptr Success, handle of cache entry * @retval NULL Failure */ -static FILE *msg_cache_get(struct ImapMboxData *mdata, struct Email *e) +static FILE *msg_cache_get(struct ImapAccountData *adata, struct Email *e) { - if (!mdata || !e) + if (!adata || !e) return NULL; - mdata->bcache = msg_cache_open(mdata); + adata->bcache = msg_cache_open(adata); char id[64]; - snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, IMAP_EDATA(e)->uid); - return mutt_bcache_get(mdata->bcache, id); + snprintf(id, sizeof(id), "%u-%u", adata->uid_validity, IMAP_EDATA(e)->uid); + return mutt_bcache_get(adata->bcache, id); } /** * msg_cache_put - Put an email into the message cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param e Email header * @retval ptr Success, handle of cache entry * @retval NULL Failure */ -static FILE *msg_cache_put(struct ImapMboxData *mdata, struct Email *e) +static FILE *msg_cache_put(struct ImapAccountData *adata, struct Email *e) { - if (!mdata || !e) + if (!adata || !e) return NULL; - mdata->bcache = msg_cache_open(mdata); + adata->bcache = msg_cache_open(adata); char id[64]; - snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, IMAP_EDATA(e)->uid); - return mutt_bcache_put(mdata->bcache, id); + snprintf(id, sizeof(id), "%u-%u", adata->uid_validity, IMAP_EDATA(e)->uid); + return mutt_bcache_put(adata->bcache, id); } /** * msg_cache_commit - Add to the message cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param e Email header * @retval 0 Success * @retval -1 Failure */ -static int msg_cache_commit(struct ImapMboxData *mdata, struct Email *e) +static int msg_cache_commit(struct ImapAccountData *adata, struct Email *e) { - if (!mdata || !e) + if (!adata || !e) return -1; - mdata->bcache = msg_cache_open(mdata); + adata->bcache = msg_cache_open(adata); char id[64]; - snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, IMAP_EDATA(e)->uid); + snprintf(id, sizeof(id), "%u-%u", adata->uid_validity, IMAP_EDATA(e)->uid); - return mutt_bcache_commit(mdata->bcache, id); + return mutt_bcache_commit(adata->bcache, id); } /** @@ -157,13 +157,13 @@ static int msg_cache_commit(struct ImapMboxData *mdata, struct Email *e) static int msg_cache_clean_cb(const char *id, struct BodyCache *bcache, void *data) { unsigned int uv, uid; - struct ImapMboxData *mdata = data; + struct ImapAccountData *adata = data; if (sscanf(id, "%u-%u", &uv, &uid) != 2) return 0; /* bad UID */ - if (uv != mdata->uid_validity || !mutt_hash_int_find(mdata->uid_hash, uid)) + if (uv != adata->uid_validity || !mutt_hash_int_find(adata->uid_hash, uid)) mutt_bcache_del(bcache, id); return 0; @@ -393,7 +393,7 @@ static int msg_fetch_header(struct Mailbox *mailbox, struct ImapHeader *h, int rc = -1; /* default now is that string isn't FETCH response */ int parse_rc; - struct ImapMboxData *mdata = mailbox->data; + struct ImapAccountData *adata = mailbox->data; if (buf[0] != '*') return rc; @@ -424,16 +424,16 @@ static int msg_fetch_header(struct Mailbox *mailbox, struct ImapHeader *h, if (imap_get_literal_count(buf, &bytes) == 0) { - imap_read_literal(fp, mdata, bytes, NULL); + imap_read_literal(fp, adata, bytes, NULL); /* we may have other fields of the FETCH _after_ the literal * (eg Domino puts FLAGS here). Nothing wrong with that, either. * This all has to go - we should accept literals and nonliterals * interchangeably at any time. */ - if (imap_cmd_step(mdata) != IMAP_CMD_CONTINUE) + if (imap_cmd_step(adata) != IMAP_CMD_CONTINUE) return rc; - if (msg_parse_fetch(h, mdata->buf) == -1) + if (msg_parse_fetch(h, adata->buf) == -1) return rc; } @@ -461,13 +461,13 @@ static void flush_buffer(char *buf, size_t *len, struct Connection *conn) /** * query_abort_header_download - Ask the user whether to abort the download - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval true Abort the download * * If the user hits ctrl-c during an initial header download for a mailbox, * prompt whether to completely abort the download and close the mailbox. */ -static bool query_abort_header_download(struct ImapMboxData *mdata) +static bool query_abort_header_download(struct ImapAccountData *adata) { bool abort = false; @@ -476,7 +476,7 @@ static bool query_abort_header_download(struct ImapMboxData *mdata) if (mutt_yesorno(_("Abort download and close mailbox?"), MUTT_YES) == MUTT_YES) { abort = true; - imap_close_connection(mdata); + imap_close_connection(adata); } SigInt = 0; @@ -485,16 +485,16 @@ static bool query_abort_header_download(struct ImapMboxData *mdata) /** * alloc_msn_index - Create lookup table of MSN to Header - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_count Number of MSNs in use * * Mapping from Message Sequence Number to Header */ -static void alloc_msn_index(struct ImapMboxData *mdata, size_t msn_count) +static void alloc_msn_index(struct ImapAccountData *adata, size_t msn_count) { size_t new_size; - if (msn_count <= mdata->msn_index_size) + if (msn_count <= adata->msn_index_size) return; /* This is a conservative check to protect against a malicious imap @@ -509,36 +509,36 @@ static void alloc_msn_index(struct ImapMboxData *mdata, size_t msn_count) /* Add a little padding, like mx_allloc_memory() */ new_size = msn_count + 25; - if (!mdata->msn_index) - mdata->msn_index = mutt_mem_calloc(new_size, sizeof(struct Email *)); + if (!adata->msn_index) + adata->msn_index = mutt_mem_calloc(new_size, sizeof(struct Email *)); else { - mutt_mem_realloc(&mdata->msn_index, sizeof(struct Email *) * new_size); - memset(mdata->msn_index + mdata->msn_index_size, 0, - sizeof(struct Email *) * (new_size - mdata->msn_index_size)); + mutt_mem_realloc(&adata->msn_index, sizeof(struct Email *) * new_size); + memset(adata->msn_index + adata->msn_index_size, 0, + sizeof(struct Email *) * (new_size - adata->msn_index_size)); } - mdata->msn_index_size = new_size; + adata->msn_index_size = new_size; } /** * imap_alloc_uid_hash - Create a Hash Table for the UIDs - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_count Number of MSNs in use * * This function is run after imap_alloc_msn_index, so we skip the * malicious msn_count size check. */ -static void imap_alloc_uid_hash(struct ImapMboxData *mdata, unsigned int msn_count) +static void imap_alloc_uid_hash(struct ImapAccountData *adata, unsigned int msn_count) { - if (!mdata->uid_hash) - mdata->uid_hash = mutt_hash_int_create(MAX(6 * msn_count / 5, 30), 0); + if (!adata->uid_hash) + adata->uid_hash = mutt_hash_int_create(MAX(6 * msn_count / 5, 30), 0); } /** * imap_fetch_msn_seqset - Generate a sequence set * @param b Buffer for the result - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_begin First Message Sequence number * @param msn_end Last Message Sequence number * @@ -549,7 +549,7 @@ static void imap_alloc_uid_hash(struct ImapMboxData *mdata, unsigned int msn_cou * Ideally, we would generate multiple requests if the number of ranges * is too big, but for now just abort to using the whole range. */ -static void imap_fetch_msn_seqset(struct Buffer *b, struct ImapMboxData *mdata, +static void imap_fetch_msn_seqset(struct Buffer *b, struct ImapAccountData *adata, unsigned int msn_begin, unsigned int msn_end) { int chunks = 0; @@ -559,7 +559,7 @@ static void imap_fetch_msn_seqset(struct Buffer *b, struct ImapMboxData *mdata, for (unsigned int msn = msn_begin; msn <= (msn_end + 1); msn++) { - if ((msn <= msn_end) && !mdata->msn_index[msn - 1]) + if ((msn <= msn_end) && !adata->msn_index[msn - 1]) { switch (state) { @@ -639,7 +639,7 @@ static void set_changed_flag(struct Context *ctx, struct Email *e, #ifdef USE_HCACHE /** * read_headers_normal_eval_cache - Retrieve data from the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_end Last Message Sequence number * @param uidnext UID of next email * @param store_flag_updates if true, save flags to the header cache @@ -654,14 +654,14 @@ static void set_changed_flag(struct Context *ctx, struct Email *e, * their MSN. The current flag state will be queried in * read_headers_condstore_qresync_updates(). */ -static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, +static int read_headers_normal_eval_cache(struct ImapAccountData *adata, unsigned int msn_end, unsigned int uidnext, bool store_flag_updates, bool eval_condstore) { struct Progress progress; char buf[LONG_STRING]; - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; int idx = ctx->mailbox->msg_count; /* L10N: @@ -674,14 +674,14 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, snprintf(buf, sizeof(buf), "UID FETCH 1:%u (UID%s)", uidnext - 1, eval_condstore ? "" : " FLAGS"); - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); int rc = IMAP_CMD_CONTINUE; int mfhrc = 0; struct ImapHeader h; for (int msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++) { - if (SigInt && query_abort_header_download(mdata)) + if (SigInt && query_abort_header_download(adata)) return -1; mutt_progress_update(&progress, msgno, -1); @@ -690,11 +690,11 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, h.data = new_emaildata(); do { - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) break; - mfhrc = msg_fetch_header(ctx->mailbox, &h, mdata->buf, NULL); + mfhrc = msg_fetch_header(ctx->mailbox, &h, adata->buf, NULL); if (mfhrc < 0) continue; @@ -712,18 +712,18 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, continue; } - if (mdata->msn_index[h.data->msn - 1]) + if (adata->msn_index[h.data->msn - 1]) { mutt_debug(2, "skipping hcache FETCH for duplicate message %d\n", h.data->msn); continue; } - ctx->mailbox->hdrs[idx] = imap_hcache_get(mdata, h.data->uid); + ctx->mailbox->hdrs[idx] = imap_hcache_get(adata, h.data->uid); if (ctx->mailbox->hdrs[idx]) { - mdata->max_msn = MAX(mdata->max_msn, h.data->msn); - mdata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; - mutt_hash_int_insert(mdata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); + adata->max_msn = MAX(adata->max_msn, h.data->msn); + adata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; + mutt_hash_int_insert(adata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); ctx->mailbox->hdrs[idx]->index = idx; /* messages which have not been expunged are ACTIVE (borrowed from mh @@ -759,7 +759,7 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, /* If this is the first time we are fetching, we need to * store the current state of flags back into the header cache */ if (!eval_condstore && store_flag_updates) - imap_hcache_put(mdata, ctx->mailbox->hdrs[idx]); + imap_hcache_put(adata, ctx->mailbox->hdrs[idx]); h.data = NULL; idx++; @@ -777,7 +777,7 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, /** * read_headers_qresync_eval_cache - Retrieve data from the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param uid_seqset Sequence Set of UIDs * @retval >=0 Success * @retval -1 Error @@ -787,13 +787,13 @@ static int read_headers_normal_eval_cache(struct ImapMboxData *mdata, * In read_headers_condstore_qresync_updates(). We will update change flags * using CHANGEDSINCE and find out what UIDs have been expunged using VANISHED. */ -static int read_headers_qresync_eval_cache(struct ImapMboxData *mdata, char *uid_seqset) +static int read_headers_qresync_eval_cache(struct ImapAccountData *adata, char *uid_seqset) { int rc; unsigned int uid = 0; mutt_debug(2, "Reading uid seqset from header cache\n"); - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; unsigned int msn = 1; struct SeqsetIterator *iter = mutt_seqset_iterator_new(uid_seqset); @@ -804,14 +804,14 @@ static int read_headers_qresync_eval_cache(struct ImapMboxData *mdata, char *uid { /* The seqset may contain more headers than the fetch request, so * we need to watch and reallocate the context and msn_index */ - if (msn > mdata->msn_index_size) - alloc_msn_index(mdata, msn); + if (msn > adata->msn_index_size) + alloc_msn_index(adata, msn); - struct Email *e = imap_hcache_get(mdata, uid); + struct Email *e = imap_hcache_get(adata, uid); if (e) { - mdata->max_msn = MAX(mdata->max_msn, msn); - mdata->msn_index[msn - 1] = e; + adata->max_msn = MAX(adata->max_msn, msn); + adata->msn_index[msn - 1] = e; if (ctx->mailbox->msg_count >= ctx->mailbox->hdrmax) mx_alloc_memory(ctx->mailbox); @@ -831,7 +831,7 @@ static int read_headers_qresync_eval_cache(struct ImapMboxData *mdata, char *uid edata->msn = msn; edata->uid = uid; - mutt_hash_int_insert(mdata->uid_hash, uid, e); + mutt_hash_int_insert(adata->uid_hash, uid, e); ctx->mailbox->size += e->content->length; ctx->mailbox->hdrs[ctx->mailbox->msg_count++] = e; @@ -847,7 +847,7 @@ static int read_headers_qresync_eval_cache(struct ImapMboxData *mdata, char *uid /** * read_headers_condstore_qresync_updates - Retrieve updates from the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_end Last Message Sequence number * @param uidnext UID of next email * @param hc_modseq Timestamp of last Header Cache update @@ -857,7 +857,7 @@ static int read_headers_qresync_eval_cache(struct ImapMboxData *mdata, char *uid * * CONDSTORE and QRESYNC use FETCH extensions to grab updates. */ -static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, +static int read_headers_condstore_qresync_updates(struct ImapAccountData *adata, unsigned int msn_end, unsigned int uidnext, unsigned long long hc_modseq, bool eval_qresync) { @@ -865,7 +865,7 @@ static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, char buf[LONG_STRING]; unsigned int header_msn = 0; - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; /* L10N: Fetching IMAP flag changes, using the CONDSTORE extension */ mutt_progress_init(&progress, _("Fetching flag updates..."), @@ -874,24 +874,24 @@ static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, snprintf(buf, sizeof(buf), "UID FETCH 1:%u (FLAGS) (CHANGEDSINCE %llu%s)", uidnext - 1, hc_modseq, eval_qresync ? " VANISHED" : ""); - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); int rc = IMAP_CMD_CONTINUE; for (int msgno = 1; rc == IMAP_CMD_CONTINUE; msgno++) { - if (SigInt && query_abort_header_download(mdata)) + if (SigInt && query_abort_header_download(adata)) return -1; mutt_progress_update(&progress, msgno, -1); /* cmd_parse_fetch will update the flags */ - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) break; /* so we just need to grab the header and persist it back into * the header cache */ - char *fetch_buf = mdata->buf; + char *fetch_buf = adata->buf; if (fetch_buf[0] != '*') continue; @@ -899,27 +899,27 @@ static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, if (!isdigit((unsigned char) *fetch_buf) || (mutt_str_atoui(fetch_buf, &header_msn) < 0)) continue; - if ((header_msn < 1) || (header_msn > msn_end) || !mdata->msn_index[header_msn - 1]) + if ((header_msn < 1) || (header_msn > msn_end) || !adata->msn_index[header_msn - 1]) { mutt_debug(1, "skipping CONDSTORE flag update for unknown message number %u\n", header_msn); continue; } - imap_hcache_put(mdata, mdata->msn_index[header_msn - 1]); + imap_hcache_put(adata, adata->msn_index[header_msn - 1]); } /* The IMAP flag setting as part of cmd_parse_fetch() ends up * flipping these on. */ - mdata->check_status &= ~IMAP_FLAGS_PENDING; + adata->check_status &= ~IMAP_FLAGS_PENDING; ctx->mailbox->changed = false; /* VANISHED handling: we need to empty out the messages */ - if (mdata->reopen & IMAP_EXPUNGE_PENDING) + if (adata->reopen & IMAP_EXPUNGE_PENDING) { - imap_hcache_close(mdata); - imap_expunge_mailbox(mdata); - mdata->hcache = imap_hcache_open(mdata, NULL); - mdata->reopen &= ~IMAP_EXPUNGE_PENDING; + imap_hcache_close(adata); + imap_expunge_mailbox(adata); + adata->hcache = imap_hcache_open(adata, NULL); + adata->reopen &= ~IMAP_EXPUNGE_PENDING; } return 0; @@ -928,7 +928,7 @@ static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, /** * read_headers_fetch_new - Retrieve new messages from the server - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[in] msn_begin First Message Sequence number * @param[in] msn_end Last Message Sequence number * @param[in] evalhc if true, check the Header Cache @@ -937,7 +937,7 @@ static int read_headers_condstore_qresync_updates(struct ImapMboxData *mdata, * @retval 0 Success * @retval -1 Error */ -static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_begin, +static int read_headers_fetch_new(struct ImapAccountData *adata, unsigned int msn_begin, unsigned int msn_end, bool evalhc, unsigned int *maxuid, bool initial_download) { @@ -953,15 +953,15 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b "CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL " "X-ORIGINAL-TO"; - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; int idx = ctx->mailbox->msg_count; - if (mutt_bit_isset(mdata->capabilities, IMAP4REV1)) + if (mutt_bit_isset(adata->capabilities, IMAP4REV1)) { safe_asprintf(&hdrreq, "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", want_headers, ImapHeaders ? " " : "", NONULL(ImapHeaders)); } - else if (mutt_bit_isset(mdata->capabilities, IMAP4)) + else if (mutt_bit_isset(adata->capabilities, IMAP4)) { safe_asprintf(&hdrreq, "RFC822.HEADER.LINES (%s%s%s)", want_headers, ImapHeaders ? " " : "", NONULL(ImapHeaders)); @@ -993,7 +993,7 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b { /* In case there are holes in the header cache. */ evalhc = false; - imap_fetch_msn_seqset(b, mdata, msn_begin, msn_end); + imap_fetch_msn_seqset(b, adata, msn_begin, msn_end); } else mutt_buffer_printf(b, "%u:%u", msn_begin, msn_end); @@ -1001,14 +1001,14 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b fetch_msn_end = msn_end; char *cmd = NULL; safe_asprintf(&cmd, "FETCH %s (UID FLAGS INTERNALDATE RFC822.SIZE %s)", b->data, hdrreq); - imap_cmd_start(mdata, cmd); + imap_cmd_start(adata, cmd); FREE(&cmd); mutt_buffer_free(&b); rc = IMAP_CMD_CONTINUE; for (int msgno = msn_begin; rc == IMAP_CMD_CONTINUE; msgno++) { - if (initial_download && SigInt && query_abort_header_download(mdata)) + if (initial_download && SigInt && query_abort_header_download(adata)) goto bail; mutt_progress_update(&progress, msgno, -1); @@ -1023,11 +1023,11 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b */ do { - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) break; - mfhrc = msg_fetch_header(ctx->mailbox, &h, mdata->buf, fp); + mfhrc = msg_fetch_header(ctx->mailbox, &h, adata->buf, fp); if (mfhrc < 0) continue; @@ -1048,7 +1048,7 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b } /* May receive FLAGS updates in a separate untagged response (#2935) */ - if (mdata->msn_index[h.data->msn - 1]) + if (adata->msn_index[h.data->msn - 1]) { mutt_debug(2, "skipping FETCH response for duplicate message %d\n", h.data->msn); @@ -1057,9 +1057,9 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b ctx->mailbox->hdrs[idx] = mutt_email_new(); - mdata->max_msn = MAX(mdata->max_msn, h.data->msn); - mdata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; - mutt_hash_int_insert(mdata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); + adata->max_msn = MAX(adata->max_msn, h.data->msn); + adata->msn_index[h.data->msn - 1] = ctx->mailbox->hdrs[idx]; + mutt_hash_int_insert(adata->uid_hash, h.data->uid, ctx->mailbox->hdrs[idx]); ctx->mailbox->hdrs[idx]->index = idx; /* messages which have not been expunged are ACTIVE (borrowed from mh @@ -1090,7 +1090,7 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b ctx->mailbox->size += h.content_length; #ifdef USE_HCACHE - imap_hcache_put(mdata, ctx->mailbox->hdrs[idx]); + imap_hcache_put(adata, ctx->mailbox->hdrs[idx]); #endif /* USE_HCACHE */ ctx->mailbox->msg_count++; @@ -1111,17 +1111,17 @@ static int read_headers_fetch_new(struct ImapMboxData *mdata, unsigned int msn_b * middle of a FETCH. But just to be cautious, use the current state * of max_msn, not fetch_msn_end to set the next start range. */ - if (mdata->reopen & IMAP_NEWMAIL_PENDING) + if (adata->reopen & IMAP_NEWMAIL_PENDING) { /* update to the last value we actually pulled down */ - fetch_msn_end = mdata->max_msn; - msn_begin = mdata->max_msn + 1; - msn_end = mdata->new_mail_count; + fetch_msn_end = adata->max_msn; + msn_begin = adata->max_msn + 1; + msn_end = adata->new_mail_count; while (msn_end > ctx->mailbox->hdrmax) mx_alloc_memory(ctx->mailbox); - alloc_msn_index(mdata, msn_end); - mdata->reopen &= ~IMAP_NEWMAIL_PENDING; - mdata->new_mail_count = 0; + alloc_msn_index(adata, msn_end); + adata->reopen &= ~IMAP_NEWMAIL_PENDING; + adata->new_mail_count = 0; } } @@ -1136,7 +1136,7 @@ bail: /** * imap_read_headers - Read headers from the server - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param msn_begin First Message Sequence Number * @param msn_end Last Message Sequence Number * @param initial_download true, if this is the first opening of the mailbox @@ -1147,7 +1147,7 @@ bail: * the last message read. It will return a value other than msn_end if mail * comes in while downloading headers (in theory). */ -int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, +int imap_read_headers(struct ImapAccountData *adata, unsigned int msn_begin, unsigned int msn_end, bool initial_download) { struct ImapStatus *status = NULL; @@ -1169,58 +1169,58 @@ int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, char *uid_seqset = NULL; #endif /* USE_HCACHE */ - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; /* make sure context has room to hold the mailbox */ while (msn_end > ctx->mailbox->hdrmax) mx_alloc_memory(ctx->mailbox); - alloc_msn_index(mdata, msn_end); - imap_alloc_uid_hash(mdata, msn_end); + alloc_msn_index(adata, msn_end); + imap_alloc_uid_hash(adata, msn_end); oldmsgcount = ctx->mailbox->msg_count; - mdata->reopen &= ~(IMAP_REOPEN_ALLOW | IMAP_NEWMAIL_PENDING); - mdata->new_mail_count = 0; + adata->reopen &= ~(IMAP_REOPEN_ALLOW | IMAP_NEWMAIL_PENDING); + adata->new_mail_count = 0; #ifdef USE_HCACHE - mdata->hcache = imap_hcache_open(mdata, NULL); + adata->hcache = imap_hcache_open(adata, NULL); - if (mdata->hcache && initial_download) + if (adata->hcache && initial_download) { - uid_validity = mutt_hcache_fetch_raw(mdata->hcache, "/UIDVALIDITY", 12); - puidnext = mutt_hcache_fetch_raw(mdata->hcache, "/UIDNEXT", 8); + uid_validity = mutt_hcache_fetch_raw(adata->hcache, "/UIDVALIDITY", 12); + puidnext = mutt_hcache_fetch_raw(adata->hcache, "/UIDNEXT", 8); if (puidnext) { uidnext = *(unsigned int *) puidnext; - mutt_hcache_free(mdata->hcache, &puidnext); + mutt_hcache_free(adata->hcache, &puidnext); } - if (mdata->modseq) + if (adata->modseq) { - if (mutt_bit_isset(mdata->capabilities, CONDSTORE) && ImapCondStore) + if (mutt_bit_isset(adata->capabilities, 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 - * mdata->qresync is set. + * adata->qresync is set. */ - if (mdata->qresync) + if (adata->qresync) has_qresync = true; } - if (uid_validity && uidnext && (*(unsigned int *) uid_validity == mdata->uid_validity)) + if (uid_validity && uidnext && (*(unsigned int *) uid_validity == adata->uid_validity)) { evalhc = true; - pmodseq = mutt_hcache_fetch_raw(mdata->hcache, "/MODSEQ", 7); + pmodseq = mutt_hcache_fetch_raw(adata->hcache, "/MODSEQ", 7); if (pmodseq) { hc_modseq = *pmodseq; - mutt_hcache_free(mdata->hcache, (void **) &pmodseq); + mutt_hcache_free(adata->hcache, (void **) &pmodseq); } if (hc_modseq) { if (has_qresync) { - uid_seqset = imap_hcache_get_uid_seqset(mdata); + uid_seqset = imap_hcache_get_uid_seqset(adata); if (uid_seqset) eval_qresync = true; } @@ -1229,25 +1229,25 @@ int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, eval_condstore = true; } } - mutt_hcache_free(mdata->hcache, &uid_validity); + mutt_hcache_free(adata->hcache, &uid_validity); } if (evalhc) { if (eval_qresync) { - if (read_headers_qresync_eval_cache(mdata, uid_seqset) < 0) + if (read_headers_qresync_eval_cache(adata, uid_seqset) < 0) goto bail; } else { - if (read_headers_normal_eval_cache(mdata, msn_end, uidnext, has_condstore || has_qresync, + if (read_headers_normal_eval_cache(adata, msn_end, uidnext, has_condstore || has_qresync, eval_condstore) < 0) goto bail; } - if ((eval_condstore || eval_qresync) && (hc_modseq != mdata->modseq)) + if ((eval_condstore || eval_qresync) && (hc_modseq != adata->modseq)) { - if (read_headers_condstore_qresync_updates(mdata, msn_end, uidnext, + if (read_headers_condstore_qresync_updates(adata, msn_end, uidnext, hc_modseq, eval_qresync) < 0) { goto bail; @@ -1257,34 +1257,34 @@ int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, /* Look for the first empty MSN and start there */ while (msn_begin <= msn_end) { - if (!mdata->msn_index[msn_begin - 1]) + if (!adata->msn_index[msn_begin - 1]) break; msn_begin++; } } #endif /* USE_HCACHE */ - if (read_headers_fetch_new(mdata, msn_begin, msn_end, evalhc, &maxuid, initial_download) < 0) + if (read_headers_fetch_new(adata, msn_begin, msn_end, evalhc, &maxuid, initial_download) < 0) goto bail; - if (maxuid && (status = imap_mboxcache_get(mdata, mdata->mbox_name, 0)) && + if (maxuid && (status = imap_mboxcache_get(adata, adata->mbox_name, 0)) && (status->uidnext < maxuid + 1)) { status->uidnext = maxuid + 1; } #ifdef USE_HCACHE - mutt_hcache_store_raw(mdata->hcache, "/UIDVALIDITY", 12, &mdata->uid_validity, - sizeof(mdata->uid_validity)); - if (maxuid && mdata->uidnext < maxuid + 1) + mutt_hcache_store_raw(adata->hcache, "/UIDVALIDITY", 12, &adata->uid_validity, + sizeof(adata->uid_validity)); + if (maxuid && adata->uidnext < maxuid + 1) { - mutt_debug(2, "Overriding UIDNEXT: %u -> %u\n", mdata->uidnext, maxuid + 1); - mdata->uidnext = maxuid + 1; + mutt_debug(2, "Overriding UIDNEXT: %u -> %u\n", adata->uidnext, maxuid + 1); + adata->uidnext = maxuid + 1; } - if (mdata->uidnext > 1) + if (adata->uidnext > 1) { - mutt_hcache_store_raw(mdata->hcache, "/UIDNEXT", 8, &mdata->uidnext, - sizeof(mdata->uidnext)); + mutt_hcache_store_raw(adata->hcache, "/UIDNEXT", 8, &adata->uidnext, + sizeof(adata->uidnext)); } /* We currently only sync CONDSTORE and QRESYNC on the initial download. @@ -1296,16 +1296,16 @@ int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, { if (has_condstore || has_qresync) { - mutt_hcache_store_raw(mdata->hcache, "/MODSEQ", 7, &mdata->modseq, - sizeof(mdata->modseq)); + mutt_hcache_store_raw(adata->hcache, "/MODSEQ", 7, &adata->modseq, + sizeof(adata->modseq)); } else - mutt_hcache_delete(mdata->hcache, "/MODSEQ", 7); + mutt_hcache_delete(adata->hcache, "/MODSEQ", 7); if (has_qresync) - imap_hcache_store_uid_seqset(mdata); + imap_hcache_store_uid_seqset(adata); else - imap_hcache_clear_uid_seqset(mdata); + imap_hcache_clear_uid_seqset(adata); } #endif /* USE_HCACHE */ @@ -1317,13 +1317,13 @@ int imap_read_headers(struct ImapMboxData *mdata, unsigned int msn_begin, mx_update_context(ctx, ctx->mailbox->msg_count - oldmsgcount); } - mdata->reopen |= IMAP_REOPEN_ALLOW; + adata->reopen |= IMAP_REOPEN_ALLOW; retval = msn_end; bail: #ifdef USE_HCACHE - imap_hcache_close(mdata); + imap_hcache_close(adata); FREE(&uid_seqset); #endif /* USE_HCACHE */ @@ -1352,12 +1352,12 @@ int imap_append_message(struct Context *ctx, struct Message *msg) struct ImapMbox mx; int rc; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; if (imap_parse_path(ctx->mailbox->path, &mx)) return -1; - imap_fix_path(mdata, mx.mbox, mailbox, sizeof(mailbox)); + imap_fix_path(adata, mx.mbox, mailbox, sizeof(mailbox)); if (!*mailbox) mutt_str_strfcpy(mailbox, "INBOX", sizeof(mailbox)); @@ -1386,7 +1386,7 @@ int imap_append_message(struct Context *ctx, struct Message *msg) mutt_progress_init(&progressbar, _("Uploading message..."), MUTT_PROGRESS_SIZE, NetInc, len); - imap_munge_mbox_name(mdata, mbox, sizeof(mbox), mailbox); + imap_munge_mbox_name(adata, mbox, sizeof(mbox), mailbox); mutt_date_make_imap(internaldate, sizeof(internaldate), msg->received); imap_flags[0] = 0; @@ -1404,17 +1404,17 @@ int imap_append_message(struct Context *ctx, struct Message *msg) snprintf(buf, sizeof(buf), "APPEND %s (%s) \"%s\" {%lu}", mbox, imap_flags + 1, internaldate, (unsigned long) len); - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); if (rc != IMAP_CMD_RESPOND) { - mutt_debug(1, "#1 command failed: %s\n", mdata->buf); + mutt_debug(1, "#1 command failed: %s\n", adata->buf); - char *pc = mdata->buf + SEQLEN; + char *pc = adata->buf + SEQLEN; SKIPWS(pc); pc = imap_next_word(pc); mutt_error("%s", pc); @@ -1432,25 +1432,25 @@ int imap_append_message(struct Context *ctx, struct Message *msg) if (len > sizeof(buf) - 3) { sent += len; - flush_buffer(buf, &len, mdata->conn); + flush_buffer(buf, &len, adata->conn); mutt_progress_update(&progressbar, sent, -1); } } if (len) - flush_buffer(buf, &len, mdata->conn); + flush_buffer(buf, &len, adata->conn); - mutt_socket_send(mdata->conn, "\r\n"); + mutt_socket_send(adata->conn, "\r\n"); mutt_file_fclose(&fp); do - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); while (rc == IMAP_CMD_CONTINUE); - if (!imap_code(mdata->buf)) + if (!imap_code(adata->buf)) { - mutt_debug(1, "#2 command failed: %s\n", mdata->buf); - char *pc = mdata->buf + SEQLEN; + mutt_debug(1, "#2 command failed: %s\n", adata->buf); + char *pc = adata->buf + SEQLEN; SKIPWS(pc); pc = imap_next_word(pc); mutt_error("%s", pc); @@ -1486,7 +1486,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de int err_continue = MUTT_NO; int triedcreate = 0; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; if (imap_parse_path(dest, &mx)) { @@ -1495,7 +1495,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de } /* check that the save-to folder is in the same account */ - if (!mutt_account_match(&(mdata->conn->account), &(mx.account))) + if (!mutt_account_match(&(adata->conn->account), &(mx.account))) { mutt_debug(3, "%s not same server as %s\n", dest, ctx->mailbox->path); return 1; @@ -1507,10 +1507,10 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de return 1; } - imap_fix_path(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox)); if (!*mbox) mutt_str_strfcpy(mbox, "INBOX", sizeof(mbox)); - imap_munge_mbox_name(mdata, mmbox, sizeof(mmbox), mbox); + imap_munge_mbox_name(adata, mmbox, sizeof(mmbox), mbox); /* loop in case of TRYCREATE */ do @@ -1537,7 +1537,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de if (ctx->mailbox->hdrs[i]->active && ctx->mailbox->hdrs[i]->changed) { - rc = imap_sync_message_for_copy(mdata, ctx->mailbox->hdrs[i], + rc = imap_sync_message_for_copy(adata, ctx->mailbox->hdrs[i], &sync_cmd, &err_continue); if (rc < 0) { @@ -1547,7 +1547,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de } } - rc = imap_exec_msgset(mdata, "UID COPY", mmbox, MUTT_TAG, false, false); + rc = imap_exec_msgset(adata, "UID COPY", mmbox, MUTT_TAG, false, false); if (!rc) { mutt_debug(1, "No messages tagged\n"); @@ -1572,14 +1572,14 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de if (e->active && e->changed) { - rc = imap_sync_message_for_copy(mdata, e, &sync_cmd, &err_continue); + rc = imap_sync_message_for_copy(adata, e, &sync_cmd, &err_continue); if (rc < 0) { mutt_debug(1, "#2 could not sync\n"); goto out; } } - rc = imap_exec(mdata, cmd.data, IMAP_CMD_QUEUE); + rc = imap_exec(adata, cmd.data, IMAP_CMD_QUEUE); if (rc < 0) { mutt_debug(1, "#2 could not queue copy\n"); @@ -1588,7 +1588,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de } /* let's get it on */ - rc = imap_exec(mdata, NULL, IMAP_CMD_FAIL_OK); + rc = imap_exec(adata, NULL, IMAP_CMD_FAIL_OK); if (rc == -2) { if (triedcreate) @@ -1597,7 +1597,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de break; } /* bail out if command failed for reasons other than nonexistent target */ - if (mutt_str_strncasecmp(imap_get_qualifier(mdata->buf), "[TRYCREATE]", 11) != 0) + if (mutt_str_strncasecmp(imap_get_qualifier(adata->buf), "[TRYCREATE]", 11) != 0) break; mutt_debug(3, "server suggests TRYCREATE\n"); snprintf(prompt, sizeof(prompt), _("Create %s?"), mbox); @@ -1606,7 +1606,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de mutt_clear_error(); goto out; } - if (imap_create_mailbox(mdata, mbox) < 0) + if (imap_create_mailbox(adata, mbox) < 0) break; triedcreate = 1; } @@ -1614,7 +1614,7 @@ int imap_copy_messages(struct Context *ctx, struct Email *e, char *dest, bool de if (rc != 0) { - imap_error("imap_copy_messages", mdata->buf); + imap_error("imap_copy_messages", adata->buf); goto out; } @@ -1657,31 +1657,31 @@ out: /** * imap_cache_del - Delete an email from the body cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param e Email header * @retval 0 Success * @retval -1 Failure */ -int imap_cache_del(struct ImapMboxData *mdata, struct Email *e) +int imap_cache_del(struct ImapAccountData *adata, struct Email *e) { - if (!mdata || !e) + if (!adata || !e) return -1; - mdata->bcache = msg_cache_open(mdata); + adata->bcache = msg_cache_open(adata); char id[64]; - snprintf(id, sizeof(id), "%u-%u", mdata->uid_validity, IMAP_EDATA(e)->uid); - return mutt_bcache_del(mdata->bcache, id); + snprintf(id, sizeof(id), "%u-%u", adata->uid_validity, IMAP_EDATA(e)->uid); + return mutt_bcache_del(adata->bcache, id); } /** * imap_cache_clean - Delete all the entries in the message cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Always */ -int imap_cache_clean(struct ImapMboxData *mdata) +int imap_cache_clean(struct ImapAccountData *adata) { - mdata->bcache = msg_cache_open(mdata); - mutt_bcache_list(mdata->bcache, msg_cache_clean_cb, mdata); + adata->bcache = msg_cache_open(adata); + mutt_bcache_list(adata->bcache, msg_cache_clean_cb, adata); return 0; } @@ -1704,7 +1704,7 @@ void imap_free_emaildata(void **data) /** * imap_set_flags - fill the message header according to the server flags - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[in] e Email Header * @param[in] s Command string * @param[out] server_changes Flags have changed @@ -1720,9 +1720,9 @@ void imap_free_emaildata(void **data) * case of e->changed, if a change to a flag _would_ have been * made. */ -char *imap_set_flags(struct ImapMboxData *mdata, struct Email *e, char *s, int *server_changes) +char *imap_set_flags(struct ImapAccountData *adata, struct Email *e, char *s, int *server_changes) { - struct Context *ctx = mdata->ctx; + struct Context *ctx = adata->ctx; struct ImapHeader newh = { 0 }; struct ImapEmailData old_edata; bool readonly; @@ -1797,10 +1797,10 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) bool fetched = false; int output_progress; - struct ImapMboxData *mdata = ctx->mailbox->data; + struct ImapAccountData *adata = ctx->mailbox->data; struct Email *e = ctx->mailbox->hdrs[msgno]; - msg->fp = msg_cache_get(mdata, e); + msg->fp = msg_cache_get(adata, e); if (msg->fp) { if (IMAP_EDATA(e)->parsed) @@ -1812,7 +1812,7 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) /* we still do some caching even if imap_cachedir is unset */ /* see if we already have the message in our cache */ cacheno = IMAP_EDATA(e)->uid % IMAP_CACHE_LEN; - cache = &mdata->cache[cacheno]; + cache = &adata->cache[cacheno]; if (cache->path) { @@ -1832,7 +1832,7 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) if (output_progress) mutt_message(_("Fetching message...")); - msg->fp = msg_cache_put(mdata, e); + msg->fp = msg_cache_put(adata, e); if (!msg->fp) { cache->uid = IMAP_EDATA(e)->uid; @@ -1852,18 +1852,18 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) e->active = false; snprintf(buf, sizeof(buf), "UID FETCH %u %s", IMAP_EDATA(e)->uid, - (mutt_bit_isset(mdata->capabilities, IMAP4REV1) ? + (mutt_bit_isset(adata->capabilities, IMAP4REV1) ? (ImapPeek ? "BODY.PEEK[]" : "BODY[]") : "RFC822")); - imap_cmd_start(mdata, buf); + imap_cmd_start(adata, buf); do { - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) break; - pc = mdata->buf; + pc = adata->buf; pc = imap_next_word(pc); pc = imap_next_word(pc); @@ -1899,16 +1899,16 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) mutt_progress_init(&progressbar, _("Fetching message..."), MUTT_PROGRESS_SIZE, NetInc, bytes); } - if (imap_read_literal(msg->fp, mdata, bytes, + if (imap_read_literal(msg->fp, adata, bytes, output_progress ? &progressbar : NULL) < 0) { goto bail; } /* pick up trailing line */ - rc = imap_cmd_step(mdata); + rc = imap_cmd_step(adata); if (rc != IMAP_CMD_CONTINUE) goto bail; - pc = mdata->buf; + pc = adata->buf; fetched = true; } @@ -1918,7 +1918,7 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) * incrementally update flags later, this won't stop us syncing */ else if ((mutt_str_strncasecmp("FLAGS", pc, 5) == 0) && !e->changed) { - pc = imap_set_flags(mdata, e, pc, NULL); + pc = imap_set_flags(adata, e, pc, NULL); if (!pc) goto bail; } @@ -1939,10 +1939,10 @@ int imap_msg_open(struct Context *ctx, struct Message *msg, int msgno) if (rc != IMAP_CMD_OK) goto bail; - if (!fetched || !imap_code(mdata->buf)) + if (!fetched || !imap_code(adata->buf)) goto bail; - msg_cache_commit(mdata, e); + msg_cache_commit(adata, e); parsemsg: /* Update the header information. Previously, we only downloaded a @@ -1983,7 +1983,7 @@ parsemsg: /* retry message parse if cached message is empty */ if (!retried && ((e->lines == 0) || (e->content->length == 0))) { - imap_cache_del(mdata, e); + imap_cache_del(adata, e); retried = true; goto parsemsg; } @@ -1992,7 +1992,7 @@ parsemsg: bail: mutt_file_fclose(&msg->fp); - imap_cache_del(mdata, e); + imap_cache_del(adata, e); if (cache->path) { unlink(cache->path); diff --git a/imap/utf7.c b/imap/utf7.c index c03b247b3..f05c1527e 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -311,10 +311,10 @@ bail: /** * imap_utf_encode - Encode email from local charset to UTF-8 - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Email to convert */ -void imap_utf_encode(struct ImapMboxData *mdata, char **s) +void imap_utf_encode(struct ImapAccountData *adata, char **s) { if (!Charset || !s) return; @@ -323,7 +323,7 @@ void imap_utf_encode(struct ImapMboxData *mdata, char **s) if (t && (mutt_ch_convert_string(&t, Charset, "utf-8", 0) == 0)) { FREE(s); - if (mdata->unicode) + if (adata->unicode) *s = mutt_str_strdup(t); else *s = utf8_to_utf7(t, strlen(t), NULL, 0); @@ -333,17 +333,17 @@ void imap_utf_encode(struct ImapMboxData *mdata, char **s) /** * imap_utf_decode - Decode email from UTF-8 to local charset - * @param[in] mdata Imap Mailbox data + * @param[in] adata Imap Account data * @param[out] s Email to convert */ -void imap_utf_decode(struct ImapMboxData *mdata, char **s) +void imap_utf_decode(struct ImapAccountData *adata, char **s) { if (!Charset) return; char *t = NULL; - if (mdata->unicode) + if (adata->unicode) t = mutt_str_strdup(*s); else t = utf7_to_utf8(*s, strlen(*s), 0, 0); diff --git a/imap/util.c b/imap/util.c index 10391d57f..00f4a4819 100644 --- a/imap/util.c +++ b/imap/util.c @@ -81,7 +81,7 @@ short ImapPipelineDepth; ///< Config: (imap) Number of IMAP commands that may be int imap_expand_path(char *buf, size_t buflen) { struct ImapMbox mx; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; struct Url url; char fixedpath[LONG_STRING]; int rc; @@ -89,9 +89,9 @@ int imap_expand_path(char *buf, size_t buflen) if (imap_parse_path(buf, &mx) < 0) return -1; - mdata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + adata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); mutt_account_tourl(&mx.account, &url); - imap_fix_path(mdata, mx.mbox, fixedpath, sizeof(fixedpath)); + imap_fix_path(adata, mx.mbox, fixedpath, sizeof(fixedpath)); url.path = fixedpath; rc = url_tostring(&url, buf, buflen, U_DECODE_PASSWD); @@ -156,7 +156,7 @@ void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen) void imap_get_parent_path(const char *path, char *buf, size_t buflen) { struct ImapMbox mx; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char mbox[LONG_STRING] = ""; if (imap_parse_path(path, &mx) < 0) @@ -165,18 +165,18 @@ void imap_get_parent_path(const char *path, char *buf, size_t buflen) return; } - mdata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); - if (!mdata) + adata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!adata) { mutt_str_strfcpy(buf, path, buflen); return; } /* Stores a fixed path in mbox */ - imap_fix_path(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox)); /* Gets the parent mbox in mbox */ - imap_get_parent(mbox, mdata->delim, mbox, sizeof(mbox)); + imap_get_parent(mbox, adata->delim, mbox, sizeof(mbox)); /* Returns a fully qualified IMAP url */ imap_qualify_path(buf, buflen, &mx, mbox); @@ -193,18 +193,18 @@ void imap_get_parent_path(const char *path, char *buf, size_t buflen) void imap_clean_path(char *path, size_t plen) { struct ImapMbox mx; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; char mbox[LONG_STRING] = ""; if (imap_parse_path(path, &mx) < 0) return; - mdata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); - if (!mdata) + adata = imap_conn_find(&mx.account, MUTT_IMAP_CONN_NONEW); + if (!adata) return; /* Stores a fixed path in mbox */ - imap_fix_path(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_fix_path(adata, mx.mbox, mbox, sizeof(mbox)); /* Returns a fully qualified IMAP url */ imap_qualify_path(path, plen, &mx, mbox); @@ -214,23 +214,23 @@ void imap_clean_path(char *path, size_t plen) /** * imap_msn_index_to_uid_seqset - Convert MSN index of UIDs to Seqset * @param b Buffer for the result - * @param mdata Imap Mailbox data + * @param adata Imap Account data * * Generates a seqseq of the UIDs in msn_index to persist in the header cache. * Empty spots are stored as 0. */ -static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapMboxData *mdata) +static void imap_msn_index_to_uid_seqset(struct Buffer *b, struct ImapAccountData *adata) { int first = 1, state = 0; unsigned int cur_uid = 0, last_uid = 0; unsigned int range_begin = 0, range_end = 0; - for (unsigned int msn = 1; msn <= mdata->max_msn + 1; msn++) + for (unsigned int msn = 1; msn <= adata->max_msn + 1; msn++) { bool match = false; - if (msn <= mdata->max_msn) + if (msn <= adata->max_msn) { - struct Email *cur_header = mdata->msn_index[msn - 1]; + struct Email *cur_header = adata->msn_index[msn - 1]; cur_uid = cur_header ? IMAP_EDATA(cur_header)->uid : 0; if (!state || (cur_uid && ((cur_uid - 1) == last_uid))) match = true; @@ -281,12 +281,12 @@ static int imap_hcache_namer(const char *path, char *dest, size_t dlen) /** * imap_hcache_open - Open a header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param path Path to the header cache * @retval ptr HeaderCache * @retval NULL Failure */ -header_cache_t *imap_hcache_open(struct ImapMboxData *mdata, const char *path) +header_cache_t *imap_hcache_open(struct ImapAccountData *adata, const char *path) { struct ImapMbox mx; struct Url url; @@ -294,13 +294,13 @@ header_cache_t *imap_hcache_open(struct ImapMboxData *mdata, const char *path) char mbox[PATH_MAX]; if (path) - imap_cachepath(mdata, path, mbox, sizeof(mbox)); + imap_cachepath(adata, path, mbox, sizeof(mbox)); else { - if (!mdata->ctx || imap_parse_path(mdata->ctx->mailbox->path, &mx) < 0) + if (!adata->ctx || imap_parse_path(adata->ctx->mailbox->path, &mx) < 0) return NULL; - imap_cachepath(mdata, mx.mbox, mbox, sizeof(mbox)); + imap_cachepath(adata, mx.mbox, mbox, sizeof(mbox)); FREE(&mx.mbox); } @@ -310,7 +310,7 @@ header_cache_t *imap_hcache_open(struct ImapMboxData *mdata, const char *path) if ((len > 3) && (strcmp(mbox + len - 3, "/..") == 0)) return NULL; - mutt_account_tourl(&mdata->conn->account, &url); + mutt_account_tourl(&adata->conn->account, &url); url.path = mbox; url_tostring(&url, cachepath, sizeof(cachepath), U_PATH); @@ -319,42 +319,42 @@ header_cache_t *imap_hcache_open(struct ImapMboxData *mdata, const char *path) /** * imap_hcache_close - Close the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data */ -void imap_hcache_close(struct ImapMboxData *mdata) +void imap_hcache_close(struct ImapAccountData *adata) { - if (!mdata->hcache) + if (!adata->hcache) return; - mutt_hcache_close(mdata->hcache); - mdata->hcache = NULL; + mutt_hcache_close(adata->hcache); + adata->hcache = NULL; } /** * imap_hcache_get - Get a header cache entry by its UID - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param uid UID to find * @retval ptr Email Header * @retval NULL Failure */ -struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid) +struct Email *imap_hcache_get(struct ImapAccountData *adata, unsigned int uid) { char key[16]; void *uv = NULL; struct Email *e = NULL; - if (!mdata->hcache) + if (!adata->hcache) return NULL; sprintf(key, "/%u", uid); - uv = mutt_hcache_fetch(mdata->hcache, key, imap_hcache_keylen(key)); + uv = mutt_hcache_fetch(adata->hcache, key, imap_hcache_keylen(key)); if (uv) { - if (*(unsigned int *) uv == mdata->uid_validity) + if (*(unsigned int *) uv == adata->uid_validity) e = mutt_hcache_restore(uv); else mutt_debug(3, "hcache uidvalidity mismatch: %u\n", *(unsigned int *) uv); - mutt_hcache_free(mdata->hcache, &uv); + mutt_hcache_free(adata->hcache, &uv); } return e; @@ -362,61 +362,61 @@ struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid) /** * imap_hcache_put - Add an entry to the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param e Email Header * @retval 0 Success * @retval -1 Failure */ -int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e) +int imap_hcache_put(struct ImapAccountData *adata, struct Email *e) { char key[16]; - if (!mdata->hcache) + if (!adata->hcache) return -1; sprintf(key, "/%u", IMAP_EDATA(e)->uid); - return mutt_hcache_store(mdata->hcache, key, imap_hcache_keylen(key), e, mdata->uid_validity); + return mutt_hcache_store(adata->hcache, key, imap_hcache_keylen(key), e, adata->uid_validity); } /** * imap_hcache_del - Delete an item from the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param uid UID of entry to delete * @retval 0 Success * @retval -1 Failure */ -int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid) +int imap_hcache_del(struct ImapAccountData *adata, unsigned int uid) { char key[16]; - if (!mdata->hcache) + if (!adata->hcache) return -1; sprintf(key, "/%u", uid); - return mutt_hcache_delete(mdata->hcache, key, imap_hcache_keylen(key)); + return mutt_hcache_delete(adata->hcache, key, imap_hcache_keylen(key)); } /** * imap_hcache_store_uid_seqset - Store a UID Sequence Set in the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval -1 Error */ -int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata) +int imap_hcache_store_uid_seqset(struct ImapAccountData *adata) { - if (!mdata->hcache) + if (!adata->hcache) return -1; struct Buffer *b = mutt_buffer_new(); /* The seqset is likely large. Preallocate to reduce reallocs */ mutt_buffer_increase_size(b, HUGE_STRING); - imap_msn_index_to_uid_seqset(b, mdata); + imap_msn_index_to_uid_seqset(b, adata); size_t seqset_size = b->dptr - b->data; if (seqset_size == 0) b->data[0] = '\0'; - int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, b->data, seqset_size + 1); + int rc = mutt_hcache_store_raw(adata->hcache, "/UIDSEQSET", 10, b->data, seqset_size + 1); mutt_debug(5, "Stored /UIDSEQSET %s\n", b->data); mutt_buffer_free(&b); return rc; @@ -424,32 +424,32 @@ int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata) /** * imap_hcache_clear_uid_seqset - Delete a UID Sequence Set from the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval 0 Success * @retval -1 Error */ -int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata) +int imap_hcache_clear_uid_seqset(struct ImapAccountData *adata) { - if (!mdata->hcache) + if (!adata->hcache) return -1; - return mutt_hcache_delete(mdata->hcache, "/UIDSEQSET", 10); + return mutt_hcache_delete(adata->hcache, "/UIDSEQSET", 10); } /** * imap_hcache_get_uid_seqset - Get a UID Sequence Set from the header cache - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @retval ptr UID Sequence Set * @retval NULL Error */ -char *imap_hcache_get_uid_seqset(struct ImapMboxData *mdata) +char *imap_hcache_get_uid_seqset(struct ImapAccountData *adata) { - if (!mdata->hcache) + if (!adata->hcache) return NULL; - char *hc_seqset = mutt_hcache_fetch_raw(mdata->hcache, "/UIDSEQSET", 10); + char *hc_seqset = mutt_hcache_fetch_raw(adata->hcache, "/UIDSEQSET", 10); char *seqset = mutt_str_strdup(hc_seqset); - mutt_hcache_free(mdata->hcache, (void **) &hc_seqset); + mutt_hcache_free(adata->hcache, (void **) &hc_seqset); mutt_debug(5, "Retrieved /UIDSEQSET %s\n", NONULL(seqset)); return seqset; @@ -701,45 +701,45 @@ void imap_error(const char *where, const char *msg) } /** - * imap_mdata_new - Allocate and initialise a new ImapMboxData structure - * @retval ptr New ImapMboxData + * imap_adata_new - Allocate and initialise a new ImapAccountData structure + * @retval ptr New ImapAccountData */ -struct ImapMboxData *imap_mdata_new(void) +struct ImapAccountData *imap_adata_new(void) { - struct ImapMboxData *mdata = mutt_mem_calloc(1, sizeof(struct ImapMboxData)); + struct ImapAccountData *adata = mutt_mem_calloc(1, sizeof(struct ImapAccountData)); - mdata->cmdbuf = mutt_buffer_new(); - mdata->cmdslots = ImapPipelineDepth + 2; - mdata->cmds = mutt_mem_calloc(mdata->cmdslots, sizeof(*mdata->cmds)); + adata->cmdbuf = mutt_buffer_new(); + adata->cmdslots = ImapPipelineDepth + 2; + adata->cmds = mutt_mem_calloc(adata->cmdslots, sizeof(*adata->cmds)); - STAILQ_INIT(&mdata->flags); - STAILQ_INIT(&mdata->mboxcache); + STAILQ_INIT(&adata->flags); + STAILQ_INIT(&adata->mboxcache); - return mdata; + return adata; } /** - * imap_mdata_free - Release and clear storage in an ImapMboxData structure - * @param mdata Imap Mailbox data + * imap_adata_free - Release and clear storage in an ImapAccountData structure + * @param adata Imap Account data */ -void imap_mdata_free(struct ImapMboxData **mdata) +void imap_adata_free(struct ImapAccountData **adata) { - if (!mdata) + if (!adata) return; - FREE(&(*mdata)->capstr); - mutt_list_free(&(*mdata)->flags); - imap_mboxcache_free(*mdata); - mutt_buffer_free(&(*mdata)->cmdbuf); - FREE(&(*mdata)->buf); - mutt_bcache_close(&(*mdata)->bcache); - FREE(&(*mdata)->cmds); - FREE(mdata); + FREE(&(*adata)->capstr); + mutt_list_free(&(*adata)->flags); + imap_mboxcache_free(*adata); + mutt_buffer_free(&(*adata)->cmdbuf); + FREE(&(*adata)->buf); + mutt_bcache_close(&(*adata)->bcache); + FREE(&(*adata)->cmds); + FREE(adata); } /** * imap_fix_path - Fix up the imap path - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param mailbox Mailbox path * @param path Buffer for the result * @param plen Length of buffer @@ -751,20 +751,20 @@ void imap_mdata_free(struct ImapMboxData **mdata) * to "/". IMAP servers are not required to do this. * Moreover, IMAP servers may dislike the path ending with the delimiter. */ -char *imap_fix_path(struct ImapMboxData *mdata, const char *mailbox, char *path, size_t plen) +char *imap_fix_path(struct ImapAccountData *adata, const char *mailbox, char *path, size_t plen) { int i = 0; char delim = '\0'; - if (mdata) - delim = mdata->delim; + if (adata) + delim = adata->delim; while (mailbox && *mailbox && i < plen - 1) { if ((ImapDelimChars && strchr(ImapDelimChars, *mailbox)) || (delim && *mailbox == delim)) { /* use connection delimiter if known. Otherwise use user delimiter */ - if (!mdata) + if (!adata) delim = *mailbox; while (*mailbox && ((ImapDelimChars && strchr(ImapDelimChars, *mailbox)) || @@ -790,19 +790,19 @@ char *imap_fix_path(struct ImapMboxData *mdata, const char *mailbox, char *path, /** * imap_cachepath - Generate a cache path for a mailbox - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param mailbox Mailbox name * @param dest Buffer to store cache path * @param dlen Length of buffer */ -void imap_cachepath(struct ImapMboxData *mdata, const char *mailbox, char *dest, size_t dlen) +void imap_cachepath(struct ImapAccountData *adata, const char *mailbox, char *dest, size_t dlen) { char *s = NULL; const char *p = mailbox; for (s = dest; p && *p && dlen; dlen--) { - if (*p == mdata->delim) + if (*p == adata->delim) { *s = '/'; /* simple way to avoid collisions with UIDs */ @@ -992,15 +992,15 @@ void imap_unquote_string(char *s) /** * imap_munge_mbox_name - Quote awkward characters in a mailbox name - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param dest Buffer to store safe mailbox name * @param dlen Length of buffer * @param src Mailbox name */ -void imap_munge_mbox_name(struct ImapMboxData *mdata, char *dest, size_t dlen, const char *src) +void imap_munge_mbox_name(struct ImapAccountData *adata, char *dest, size_t dlen, const char *src) { char *buf = mutt_str_strdup(src); - imap_utf_encode(mdata, &buf); + imap_utf_encode(adata, &buf); imap_quote_string(dest, dlen, buf, false); @@ -1009,19 +1009,19 @@ void imap_munge_mbox_name(struct ImapMboxData *mdata, char *dest, size_t dlen, c /** * imap_unmunge_mbox_name - Remove quoting from a mailbox name - * @param mdata Imap Mailbox data + * @param adata Imap Account data * @param s Mailbox name * * The string will be altered in-place. */ -void imap_unmunge_mbox_name(struct ImapMboxData *mdata, char *s) +void imap_unmunge_mbox_name(struct ImapAccountData *adata, char *s) { imap_unquote_string(s); char *buf = mutt_str_strdup(s); if (buf) { - imap_utf_decode(mdata, &buf); + imap_utf_decode(adata, &buf); strncpy(s, buf, strlen(s)); } @@ -1034,17 +1034,17 @@ void imap_unmunge_mbox_name(struct ImapMboxData *mdata, char *s) void imap_keepalive(void) { struct Connection *conn = NULL; - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; time_t now = time(NULL); TAILQ_FOREACH(conn, mutt_socket_head(), entries) { if (conn->account.type == MUTT_ACCT_TYPE_IMAP) { - mdata = conn->data; - if (mdata->state >= IMAP_AUTHENTICATED && now >= mdata->lastread + ImapKeepalive) + adata = conn->data; + if (adata->state >= IMAP_AUTHENTICATED && now >= adata->lastread + ImapKeepalive) { - imap_check(mdata, true); + imap_check(adata, true); } } } @@ -1105,13 +1105,13 @@ int imap_wait_keepalive(pid_t pid) */ void imap_allow_reopen(struct Context *ctx) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; if (!ctx || !ctx->mailbox->data || ctx->mailbox->magic != MUTT_IMAP) return; - mdata = ctx->mailbox->data; - if (mdata->ctx == ctx) - mdata->reopen |= IMAP_REOPEN_ALLOW; + adata = ctx->mailbox->data; + if (adata->ctx == ctx) + adata->reopen |= IMAP_REOPEN_ALLOW; } /** @@ -1120,13 +1120,13 @@ void imap_allow_reopen(struct Context *ctx) */ void imap_disallow_reopen(struct Context *ctx) { - struct ImapMboxData *mdata = NULL; + struct ImapAccountData *adata = NULL; if (!ctx || !ctx->mailbox || !ctx->mailbox->data || ctx->mailbox->magic != MUTT_IMAP) return; - mdata = ctx->mailbox->data; - if (mdata->ctx == ctx) - mdata->reopen &= ~IMAP_REOPEN_ALLOW; + adata = ctx->mailbox->data; + if (adata->ctx == ctx) + adata->reopen &= ~IMAP_REOPEN_ALLOW; } /** @@ -1137,8 +1137,8 @@ void imap_disallow_reopen(struct Context *ctx) */ bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2) { - struct ImapMboxData *a1_idata = imap_conn_find(a1, MUTT_IMAP_CONN_NONEW); - struct ImapMboxData *a2_idata = imap_conn_find(a2, MUTT_IMAP_CONN_NONEW); + struct ImapAccountData *a1_idata = imap_conn_find(a1, MUTT_IMAP_CONN_NONEW); + struct ImapAccountData *a2_idata = imap_conn_find(a2, MUTT_IMAP_CONN_NONEW); const struct ConnAccount *a1_canon = a1_idata ? &a1_idata->conn->account : a1; const struct ConnAccount *a2_canon = a2_idata ? &a2_idata->conn->account : a2;