Correct various bugs in the recovery mechanism

The namespace of the selected mailbox was not properly applied after
recovery, CRAM-MD5 authentication during the recovery would fail, and
searching after recovery could fail in some cases.
This commit is contained in:
Lefteris Chatzimparmpas 2013-04-09 20:49:46 +02:00
parent 568e414754
commit 4c310f9df5
4 changed files with 18 additions and 10 deletions

View File

@ -209,8 +209,8 @@ request_login(session **ssnptr, const char *server, const char *port, const
CHECK(t = send_request(ssn, "AUTHENTICATE CRAM-MD5"));
CHECK(r = response_authenticate(ssn, t, &in));
if (r == STATUS_CONTINUE) {
if ((out = auth_cram_md5(user, pass, in)) ==
NULL)
if ((out = auth_cram_md5(ssn->username,
ssn->password, in)) == NULL)
goto abort;
CHECK(send_continuation(ssn, (char *)(out),
strlen((char *)(out))));
@ -239,14 +239,16 @@ request_login(session **ssnptr, const char *server, const char *port, const
CHECK(t = send_request(ssn, "CAPABILITY"));
CHECK(response_capability(ssn, t));
if (!ssn->ns.delim && ssn->capabilities & CAPABILITY_NAMESPACE &&
if (ssn->capabilities & CAPABILITY_NAMESPACE &&
get_option_boolean("namespace")) {
CHECK(t = send_request(ssn, "NAMESPACE"));
CHECK(response_namespace(ssn, t));
}
if (ssn->selected) {
CHECK(t = send_request(ssn, "SELECT \"%s\"", ssn->selected));
CHECK(t = send_request(ssn, "SELECT \"%s\"",
apply_namespace(ssn->selected, ssn->ns.prefix,
ssn->ns.delim)));
CHECK(response_select(ssn, t));
}
@ -318,7 +320,7 @@ request_select(session *ssn, const char *mbox)
TRY(r = response_select(ssn, t));
if (r == STATUS_OK)
ssn->selected = mbox;
ssn->selected = xstrdup(mbox);
return r;
}
@ -335,8 +337,10 @@ request_close(session *ssn)
TRY(t = send_request(ssn, "CLOSE"));
TRY(r = response_generic(ssn, t));
if (r == STATUS_OK && ssn->selected)
if (r == STATUS_OK && ssn->selected) {
xfree(ssn->selected);
ssn->selected = NULL;
}
return r;
}

View File

@ -381,6 +381,8 @@ response_namespace(session *ssn, int tag)
if (r == -1 || r == STATUS_BYE)
return r;
if (ssn->ns.prefix != NULL)
xfree(ssn->ns.prefix);
ssn->ns.prefix = NULL;
ssn->ns.delim = '\0';
@ -576,13 +578,13 @@ response_search(session *ssn, int tag, char **mesgs)
re = &responses[RESPONSE_SEARCH];
b = ibuf.data;
m = NULL;
while (!regexec(re->preg, b, re->nmatch, re->pmatch, 0)) {
if (!*mesgs) {
m = *mesgs = (char *)xmalloc((ibuf.len + 1) *
*mesgs = (char *)xmalloc((ibuf.len + 1) *
sizeof(char));
*m = '\0';
}
m = *mesgs;
*m = '\0';
min = (unsigned int)(re->pmatch[1].rm_eo -
re->pmatch[1].rm_so) < ibuf.len ?

View File

@ -64,5 +64,7 @@ session_destroy(session *ssn)
if (ssn->ns.prefix)
xfree(ssn->ns.prefix);
if (ssn->selected)
xfree(ssn->selected);
xfree(ssn);
}

View File

@ -21,7 +21,7 @@ typedef struct session {
char *prefix; /* Namespace prefix. */
char delim; /* Namespace delimiter. */
} ns;
const char *selected; /* Selected mailbox. */
char *selected; /* Selected mailbox. */
} session;