]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: Add imapc_client_find_command_by_tag()
authorMarco Bettini <marco.bettini@open-xchange.com>
Thu, 9 Nov 2023 10:23:30 +0000 (10:23 +0000)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Sat, 18 Nov 2023 17:12:30 +0000 (17:12 +0000)
src/lib-imap-client/imapc-client.h
src/lib-imap-client/imapc-connection.c

index 5c81be616c5e33a6e98673f36bfaef0a88fdb7ac..b6e69d06436e8b4c7a3ac01b1ce39c0537a28d8c 100644 (file)
@@ -210,6 +210,9 @@ void imapc_command_sendvf(struct imapc_command *cmd,
 const char *imapc_command_get_tag(struct imapc_command *cmd);
 void imapc_command_abort(struct imapc_command **cmd);
 
+struct imapc_command *
+imapc_client_find_command_by_tag(struct imapc_client *client, const char *tag);
+
 void imapc_client_register_untagged(struct imapc_client *client,
                                    imapc_untagged_callback_t *callback,
                                    void *context);
index a8c9b366b6e5623aeae2c2ca6367b1311cc5bd97..85aff705de7a231c9865fa7f86b49db1f646509e 100644 (file)
@@ -2544,3 +2544,28 @@ struct event *imapc_connection_get_event(struct imapc_connection *conn)
 {
        return conn->event;
 }
+
+struct imapc_command *
+imapc_client_find_command_by_tag(struct imapc_client *client, const char *tag_str)
+{
+       unsigned int tag;
+       if (str_to_uint(tag_str, &tag) != 0) {
+               /* All the tags we use are numerical. If it can't be parsed
+                  into a number, then we won't find it anyway */
+               return NULL;
+       }
+
+       struct imapc_client_connection *conn;
+       array_foreach_elem(&client->conns, conn) {
+               struct imapc_command *cmd;
+               array_foreach_elem(&conn->conn->cmd_wait_list, cmd) {
+                       if (cmd->tag == tag)
+                               return cmd;
+               }
+               array_foreach_elem(&conn->conn->cmd_send_queue, cmd) {
+                       if (cmd->tag == tag)
+                               return cmd;
+               }
+       }
+       return NULL;
+}