dovecot-2.1: imapc: Changed mailbox opening API to be more exten...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Oct 7 20:23:40 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/c358b13e32cc
changeset: 13614:c358b13e32cc
user: Timo Sirainen <tss at iki.fi>
date: Fri Oct 07 20:31:57 2011 +0300
description:
imapc: Changed mailbox opening API to be more extensible.
diffstat:
src/lib-imap-client/imapc-client.c | 4 --
src/lib-imap-client/imapc-client.h | 9 +++-
src/lib-imap-client/imapc-connection.c | 57 ++++++++++++++++------------
src/lib-imap-client/imapc-connection.h | 3 -
src/lib-storage/index/imapc/imapc-storage.c | 18 +++++++--
5 files changed, 53 insertions(+), 38 deletions(-)
diffs (200 lines):
diff -r e0a339d677cb -r c358b13e32cc src/lib-imap-client/imapc-client.c
--- 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;
}
diff -r e0a339d677cb -r c358b13e32cc src/lib-imap-client/imapc-client.h
--- 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);
diff -r e0a339d677cb -r c358b13e32cc src/lib-imap-client/imapc-connection.c
--- 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;
diff -r e0a339d677cb -r c358b13e32cc src/lib-imap-client/imapc-connection.h
--- 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
diff -r e0a339d677cb -r c358b13e32cc src/lib-storage/index/imapc/imapc-storage.c
--- 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;
More information about the dovecot-cvs
mailing list