Even though it's attached to a Mailbox, this is Account data.
/**
* 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;
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);
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;
}
#ifndef MUTT_IMAP_AUTH_H
#define MUTT_IMAP_AUTH_H
-struct ImapMboxData;
+struct ImapAccountData;
/**
* enum ImapAuthRes - Results of IMAP Authentication
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 */
/**
* 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)
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)
goto bail;
}
- if (imap_code(mdata->buf))
+ if (imap_code(adata->buf))
return IMAP_AUTH_SUCCESS;
bail:
/**
* 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
* 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)
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");
* 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);
* 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)
goto bail;
}
- if (imap_code(mdata->buf))
+ if (imap_code(adata->buf))
return IMAP_AUTH_SUCCESS;
bail:
/**
* 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;
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);
/* 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)
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)
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;
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)
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);
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)
}
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");
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:
/**
* 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)
{
/**
* 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;
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;
}
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;
/* 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);
/* 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)
/**
* 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)
/**
* 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;
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;
/* 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;
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++] = ' ';
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)
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;
}
/* 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;
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);
}
while (irc != IMAP_CMD_OK)
{
- irc = imap_cmd_step(mdata);
+ irc = imap_cmd_step(adata);
if (irc != IMAP_CMD_CONTINUE)
break;
}
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;
}
/**
* 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;
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)
{
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;
*/
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];
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..."));
/* 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
/* 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] &&
}
}
} 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)
{
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);
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)
*/
int imap_mailbox_create(const char *folder)
{
- struct ImapMboxData *mdata = NULL;
+ struct ImapAccountData *adata = NULL;
struct ImapMbox mx;
char buf[PATH_MAX];
short n;
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;
/* 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';
}
goto fail;
}
- if (imap_create_mailbox(mdata, buf) < 0)
+ if (imap_create_mailbox(adata, buf) < 0)
goto fail;
mutt_message(_("Mailbox created"));
*/
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];
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;
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;
}
/**
* 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;
/**
* 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;
/**
* 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
*
* 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;
}
/**
* 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.
}
/* 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;
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;
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;
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);
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");
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)
{
{
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;
}
/**
* 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;
/* 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];
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;
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;
/**
* 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");
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);
/**
* 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;
{
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;
}
/**
* 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;
/* 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++;
{
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;
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;
}
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
/**
* 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");
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);
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. */
}
/* 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;
}
/**
* 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;
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;
}
* 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;
}
/* 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.
* 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;
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;
/**
* 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)
{
(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;
}
/**
* 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
* * 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;
}
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);
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;
}
/**
* 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)
/**
* 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."));
/**
* 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
* @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 */
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);
/**
* 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;
* @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;
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;
*/
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];
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
{
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);
/**
* 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;
}
/**
* 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);
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;
}
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;
{
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);
}
/**
* 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
* @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;
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;
/**
* 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);
}
}
#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);
}
/**
* 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)))
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;
}
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;
}
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;
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
{
#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);
}
/**
/**
* 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
* 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;
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));
}
{
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;
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;
/**
* 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?
* @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];
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)
* 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);
/* 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;
/**
* 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;
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;
}
*/
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];
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;
/* 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 */
}
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),
"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;
{
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
{
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;
/**
* 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
*
* 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;
{
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);
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;
/**
* 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);
}
/**
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;
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;
*/
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];
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));
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
*/
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;
/* 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);
/* 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)
{
completions++;
}
} while (rc == IMAP_CMD_CONTINUE);
- mdata->cmddata = NULL;
+ adata->cmddata = NULL;
if (completions)
{
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))
{
}
/* 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++)
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");
/* 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");
}
/* 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)
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);
mutt_clear_error();
goto out;
}
- if (imap_create_mailbox(mdata, mbox) < 0)
+ if (imap_create_mailbox(adata, mbox) < 0)
break;
triedcreate = true;
}
if (rc != 0)
{
- imap_error("imap_fast_trash", mdata->buf);
+ imap_error("imap_fast_trash", adata->buf);
goto out;
}
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;
* 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)
{
}
#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 */
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.
}
#ifdef USE_HCACHE
- imap_hcache_close(mdata);
+ imap_hcache_close(adata);
#endif
/* presort here to avoid doing 10 resorts in imap_exec_msgset */
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)
{
/* 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)
if (mutt_yesorno(_("Error saving flags. Close anyway?"), 0) == MUTT_YES)
{
rc = 0;
- mdata->state = IMAP_AUTHENTICATED;
+ adata->state = IMAP_AUTHENTICATED;
goto out;
}
}
{
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;
*/
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];
}
/* 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;
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
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;
}
{
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;
}
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;
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;
/* 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
{
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);
}
}
}
- 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;
}
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;
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;
*/
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;
/* 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);
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;
*/
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;
{
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;
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);
/* 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;
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);
};
/**
- * 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;
/* -- 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);
/* 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);
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);
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);
/**
* 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);
}
/**
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;
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;
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;
}
/**
* 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;
if (mutt_yesorno(_("Abort download and close mailbox?"), MUTT_YES) == MUTT_YES)
{
abort = true;
- imap_close_connection(mdata);
+ imap_close_connection(adata);
}
SigInt = 0;
/**
* 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
/* 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
*
* 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;
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)
{
#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
* 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:
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);
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;
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
/* 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++;
/**
* 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
* 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);
{
/* 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);
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;
/**
* 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
*
* 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)
{
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..."),
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;
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;
/**
* 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
* @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)
{
"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));
{
/* 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);
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);
*/
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;
}
/* 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);
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
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++;
* 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;
}
}
/**
* 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
* 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;
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;
}
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;
/* 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.
{
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 */
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 */
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));
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;
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);
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);
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))
{
}
/* 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;
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
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)
{
}
}
- 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");
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");
}
/* 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)
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);
mutt_clear_error();
goto out;
}
- if (imap_create_mailbox(mdata, mbox) < 0)
+ if (imap_create_mailbox(adata, mbox) < 0)
break;
triedcreate = 1;
}
if (rc != 0)
{
- imap_error("imap_copy_messages", mdata->buf);
+ imap_error("imap_copy_messages", adata->buf);
goto 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;
}
/**
* 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
* 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;
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)
/* 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)
{
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;
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);
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;
}
* 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;
}
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
/* 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;
}
bail:
mutt_file_fclose(&msg->fp);
- imap_cache_del(mdata, e);
+ imap_cache_del(adata, e);
if (cache->path)
{
unlink(cache->path);
/**
* 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;
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);
/**
* 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);
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;
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);
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)
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);
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);
/**
* 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;
/**
* 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;
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);
}
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);
/**
* 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;
/**
* 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;
/**
* 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;
}
/**
- * 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
* 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)) ||
/**
* 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 */
/**
* 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);
/**
* 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));
}
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);
}
}
}
*/
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;
}
/**
*/
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;
}
/**
*/
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;