Mercurial > dovecot > core-2.2
changeset 13614:c358b13e32cc
imapc: Changed mailbox opening API to be more extensible.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 07 Oct 2011 20:31:57 +0300 |
parents | e0a339d677cb |
children | 4f305d785bc7 |
files | src/lib-imap-client/imapc-client.c src/lib-imap-client/imapc-client.h src/lib-imap-client/imapc-connection.c src/lib-imap-client/imapc-connection.h src/lib-storage/index/imapc/imapc-storage.c |
diffstat | 5 files changed, 53 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-imap-client/imapc-client.c Fri Oct 07 20:10:11 2011 +0300 +++ b/src/lib-imap-client/imapc-client.c Fri Oct 07 20:31:57 2011 +0300 @@ -234,8 +234,6 @@ struct imapc_client_mailbox * imapc_client_mailbox_open(struct imapc_client *client, - const char *name, bool examine, - imapc_command_callback_t *callback, void *context, void *untagged_box_context) { struct imapc_client_mailbox *box; @@ -248,8 +246,6 @@ conn->box = box; box->conn = conn->conn; box->msgmap = imapc_msgmap_init(); - - imapc_connection_select(box, name, examine, callback, context); return box; }
--- a/src/lib-imap-client/imapc-client.h Fri Oct 07 20:10:11 2011 +0300 +++ b/src/lib-imap-client/imapc-client.h Fri Oct 07 20:31:57 2011 +0300 @@ -25,6 +25,11 @@ }; extern const struct imapc_capability_name imapc_capability_names[]; +enum imapc_command_flags { + /* The command changes the selected mailbox (SELECT, EXAMINE) */ + IMAPC_COMMAND_FLAG_SELECT = 0x01 +}; + enum imapc_client_ssl_mode { IMAPC_CLIENT_SSL_MODE_NONE, IMAPC_CLIENT_SSL_MODE_IMMEDIATE, @@ -112,6 +117,8 @@ struct imapc_command * imapc_client_cmd(struct imapc_client *client, imapc_command_callback_t *callback, void *context); +void imapc_command_set_flags(struct imapc_command *cmd, + enum imapc_command_flags flags); void imapc_command_send(struct imapc_command *cmd, const char *cmd_str); void imapc_command_sendf(struct imapc_command *cmd, const char *cmd_fmt, ...) ATTR_FORMAT(2, 3); @@ -132,8 +139,6 @@ struct imapc_client_mailbox * imapc_client_mailbox_open(struct imapc_client *client, - const char *name, bool examine, - imapc_command_callback_t *callback, void *context, void *untagged_box_context); void imapc_client_mailbox_close(struct imapc_client_mailbox **box); void imapc_client_mailbox_disconnect(struct imapc_client_mailbox *box);
--- a/src/lib-imap-client/imapc-connection.c Fri Oct 07 20:10:11 2011 +0300 +++ b/src/lib-imap-client/imapc-connection.c Fri Oct 07 20:31:57 2011 +0300 @@ -47,6 +47,7 @@ unsigned int send_pos; unsigned int tag; + enum imapc_command_flags flags; struct imapc_connection *conn; /* If non-NULL, points to the mailbox where this command should be executed */ @@ -1421,6 +1422,24 @@ return 1; } +static void imapc_connection_set_selecting(struct imapc_client_mailbox *box) +{ + struct imapc_connection *conn = box->conn; + + i_assert(conn->selecting_box == NULL); + + if (conn->selected_box != NULL && + (conn->capabilities & IMAPC_CAPABILITY_QRESYNC) != 0) { + /* server will send a [CLOSED] once selected mailbox is + closed */ + conn->selecting_box = box; + } else { + /* we'll have to assume that all the future untagged messages + are for the mailbox we're selecting */ + conn->selected_box = box; + } +} + static void imapc_command_send_more(struct imapc_connection *conn, struct imapc_command *cmd) { @@ -1432,7 +1451,13 @@ i_assert(!cmd->wait_for_literal); i_assert(cmd->send_pos < cmd->data->used); - if (cmd->box != NULL && !imapc_client_mailbox_is_connected(cmd->box)) { + if (cmd->box == NULL) { + /* non-mailbox command */ + } else if (cmd->send_pos == 0 && + (cmd->flags & IMAPC_COMMAND_FLAG_SELECT) != 0) { + /* SELECT/EXAMINE command */ + imapc_connection_set_selecting(cmd->box); + } else if (!imapc_client_mailbox_is_connected(cmd->box)) { /* shouldn't normally happen */ memset(&reply, 0, sizeof(reply)); reply.text_without_resp = reply.text_full = "Mailbox not open"; @@ -1569,6 +1594,12 @@ return cmd; } +void imapc_command_set_flags(struct imapc_command *cmd, + enum imapc_command_flags flags) +{ + cmd->flags = flags; +} + void imapc_command_set_mailbox(struct imapc_command *cmd, struct imapc_client_mailbox *box) { @@ -1676,30 +1707,6 @@ return conn->capabilities; } -void imapc_connection_select(struct imapc_client_mailbox *box, - const char *name, bool examine, - imapc_command_callback_t *callback, void *context) -{ - struct imapc_connection *conn = box->conn; - struct imapc_command *cmd; - - i_assert(conn->selecting_box == NULL); - - if (conn->selected_box != NULL && - (conn->capabilities & IMAPC_CAPABILITY_QRESYNC) != 0) { - /* server will send a [CLOSED] once selected mailbox is - closed */ - conn->selecting_box = box; - } else { - /* we'll have to assume that all the future untagged messages - are for the mailbox we're selecting */ - conn->selected_box = box; - } - - cmd = imapc_connection_cmd(conn, callback, context); - imapc_command_sendf(cmd, examine ? "EXAMINE %s" : "SELECT %s", name); -} - void imapc_connection_unselect(struct imapc_client_mailbox *box) { struct imapc_connection *conn = box->conn;
--- a/src/lib-imap-client/imapc-connection.h Fri Oct 07 20:10:11 2011 +0300 +++ b/src/lib-imap-client/imapc-connection.h Fri Oct 07 20:31:57 2011 +0300 @@ -32,9 +32,6 @@ imapc_connection_cmd(struct imapc_connection *conn, imapc_command_callback_t *callback, void *context); -void imapc_connection_select(struct imapc_client_mailbox *box, - const char *name, bool examine, - imapc_command_callback_t *callback, void *context); void imapc_connection_unselect(struct imapc_client_mailbox *box); enum imapc_connection_state
--- a/src/lib-storage/index/imapc/imapc-storage.c Fri Oct 07 20:10:11 2011 +0300 +++ b/src/lib-storage/index/imapc/imapc-storage.c Fri Oct 07 20:31:57 2011 +0300 @@ -386,20 +386,30 @@ int imapc_mailbox_select(struct imapc_mailbox *mbox) { + struct imapc_command *cmd; struct imapc_open_context ctx; bool examine = TRUE; + i_assert(mbox->client_box == NULL); + examine = (mbox->box.flags & MAILBOX_FLAG_DROP_RECENT) == 0 && ((mbox->box.flags & MAILBOX_FLAG_READONLY) != 0 || (mbox->box.flags & MAILBOX_FLAG_SAVEONLY) != 0); + mbox->client_box = + imapc_client_mailbox_open(mbox->storage->client, mbox); + mbox->selecting = TRUE; ctx.mbox = mbox; ctx.ret = -2; - mbox->client_box = - imapc_client_mailbox_open(mbox->storage->client, mbox->box.name, - examine, imapc_mailbox_open_callback, - &ctx, mbox); + cmd = imapc_client_mailbox_cmd(mbox->client_box, + imapc_mailbox_open_callback, &ctx); + imapc_command_set_flags(cmd, IMAPC_COMMAND_FLAG_SELECT); + if (examine) + imapc_command_sendf(cmd, "EXAMINE %s", mbox->box.name); + else + imapc_command_sendf(cmd, "SELECT %s", mbox->box.name); + while (ctx.ret == -2) imapc_storage_run(mbox->storage); mbox->selecting = FALSE;