diff --git a/src/request.c b/src/request.c index 18ab9de..fdd052d 100644 --- a/src/request.c +++ b/src/request.c @@ -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; } diff --git a/src/response.c b/src/response.c index dfd7390..62c49d4 100644 --- a/src/response.c +++ b/src/response.c @@ -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 ? diff --git a/src/session.c b/src/session.c index 15a2c1e..c9b160f 100644 --- a/src/session.c +++ b/src/session.c @@ -64,5 +64,7 @@ session_destroy(session *ssn) if (ssn->ns.prefix) xfree(ssn->ns.prefix); + if (ssn->selected) + xfree(ssn->selected); xfree(ssn); } diff --git a/src/session.h b/src/session.h index 8714a86..0209c88 100644 --- a/src/session.h +++ b/src/session.h @@ -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;