Skip to content

Commit

Permalink
imapc: Make sure storage error has the proper auth failure error string
Browse files Browse the repository at this point in the history
The first failed command always had the correct error string, but the
following failed commands just returned -1 without updating storage error.
The storage error could have been something completely different by then.
  • Loading branch information
sirainen authored and villesavolainen committed Jun 13, 2017
1 parent 767e835 commit 92ca406
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/lib-storage/index/imapc/imapc-storage.c
Expand Up @@ -231,28 +231,36 @@ imapc_storage_client_login_callback(const struct imapc_command_reply *reply,

client->auth_failed_state = reply->state;
client->auth_failed_reason = i_strdup(reply->text_full);
if (!imapc_storage_client_handle_auth_failure(client))
i_unreached();
}

bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client)
{
if (client->auth_failed_state == IMAPC_COMMAND_STATE_OK)
return FALSE;

/* We need to set the error to either storage or to list, depending on
whether the caller is from mail-storage.h API or mailbox-list.h API.
We don't know here what the caller is though, so just set the error
to both of them. */
if (client->_storage != NULL) {
if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
if (client->auth_failed_state == IMAPC_COMMAND_STATE_DISCONNECTED)
mail_storage_set_internal_error(&client->_storage->storage);
else {
mail_storage_set_error(&client->_storage->storage,
MAIL_ERROR_PERM, reply->text_full);
MAIL_ERROR_PERM, client->auth_failed_reason);
}
}
if (client->_list != NULL) {
if (reply->state == IMAPC_COMMAND_STATE_DISCONNECTED)
if (client->auth_failed_state == IMAPC_COMMAND_STATE_DISCONNECTED)
mailbox_list_set_internal_error(&client->_list->list);
else {
mailbox_list_set_error(&client->_list->list,
MAIL_ERROR_PERM, reply->text_full);
MAIL_ERROR_PERM, client->auth_failed_reason);
}
}
}

bool imapc_storage_client_handle_auth_failure(struct imapc_storage_client *client)
{
return client->auth_failed_state != IMAPC_COMMAND_STATE_OK;
return TRUE;
}

static void imapc_storage_client_login(struct imapc_storage_client *client,
Expand Down

0 comments on commit 92ca406

Please sign in to comment.