]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: imap-storage-callbacks - Move imap_storage_callback_line() to imap-progress.c
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 26 Aug 2025 03:19:06 +0000 (05:19 +0200)
committerStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 26 Jan 2026 01:35:25 +0000 (02:35 +0100)
src/imap/Makefile.am
src/imap/imap-progress.c [new file with mode: 0644]
src/imap/imap-progress.h [new file with mode: 0644]
src/imap/imap-storage-callbacks.c
src/imap/test-imap-storage-callbacks.c

index 33bf5443ee265419af7c36ce82cc40fe8e38be42..b6ab4cc7eabc3b4ebda2e8f4fb95fed2f43a671d 100644 (file)
@@ -87,6 +87,7 @@ common_sources = \
        imap-list.c \
        imap-master-client.c \
        imap-notify.c \
+       imap-progress.c \
        imap-search.c \
        imap-search-args.c \
        imap-settings.c \
@@ -110,6 +111,7 @@ headers = \
        imap-list.h \
        imap-master-client.h \
        imap-notify.h \
+       imap-progress.h \
        imap-search.h \
        imap-search-args.h \
        imap-settings.h \
@@ -132,7 +134,7 @@ test_programs = \
 
 test_imap_storage_callbacks_SOURCES = \
        test-imap-storage-callbacks.c \
-       imap-storage-callbacks.c
+       imap-progress.c
 test_imap_storage_callbacks_LDADD = $(imap_LDADD)
 test_imap_storage_callbacks_DEPENDENCIES = $(imap_DEPENDENCIES)
 
diff --git a/src/imap/imap-progress.c b/src/imap/imap-progress.c
new file mode 100644 (file)
index 0000000..95f7237
--- /dev/null
@@ -0,0 +1,71 @@
+/* Copyright (c) 2025 Dovecot authors, see the included COPYING file */
+
+#include "imap-common.h"
+#include "str.h"
+#include "time-util.h"
+#include "imap-quote.h"
+#include "imap-progress.h"
+
+const char *
+imap_storage_callback_line(const struct mail_storage_progress_details *dtl,
+                          const char *tag)
+{
+       const char *verb = dtl->verb;
+       unsigned int total = dtl->total;
+       unsigned int processed = dtl->processed;
+
+       if (verb == NULL || *verb == '\0')
+               verb = "Processed";
+
+       if (total > 0 && processed >= total)
+               processed = total - 1;
+
+       /* The "]" character is totally legit in command tags, but it is
+          problematic inside IMAP resp-text-code(s), which are terminated
+          with "]". If the character appears inside the tag, we avoid
+          emitting the tag and replace it with NIL. */
+       bool has_tag = tag != NULL && *tag != '\0' && strchr(tag, ']') == NULL;
+
+       string_t *str = t_str_new(128);
+       str_append(str, "* OK [INPROGRESS");
+       if (has_tag || processed > 0 || total > 0) {
+               str_append(str, " (");
+               if (has_tag)
+                       imap_append_quoted(str, tag);
+               else
+                       str_append(str, "NIL");
+
+               if (processed > 0 || total > 0)
+                       str_printfa(str, " %u", processed);
+               else
+                       str_append(str, " NIL");
+
+               if (total > 0)
+                       str_printfa(str, " %u", total);
+               else
+                       str_append(str, " NIL");
+
+               str_append_c(str, ')');
+       }
+       str_append(str, "] ");
+
+       if (total > 0) {
+               float percentage = processed * 100.0 / total;
+               str_printfa(str, "%s %d%% of the mailbox", verb, (int)percentage);
+
+               long long elapsed_ms = timeval_diff_msecs(&dtl->now,
+                                                         &dtl->start_time);
+               if (percentage > 0 && elapsed_ms > 0) {
+                       int eta_secs = elapsed_ms * (100 - percentage) /
+                                           (1000 * percentage);
+
+                       str_printfa(str, ", ETA %d:%02d",
+                                   eta_secs / 60, eta_secs % 60);
+               }
+       } else if (processed > 0)
+               str_printfa(str, "%s %u item(s)", verb, processed);
+       else
+               str_append(str, "Hang in there..");
+
+       return str_c(str);
+}
diff --git a/src/imap/imap-progress.h b/src/imap/imap-progress.h
new file mode 100644 (file)
index 0000000..9a75701
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef IMAP_PROGRESS_H
+#define IMAP_PROGRESS_H
+
+const char *
+imap_storage_callback_line(const struct mail_storage_progress_details *dtl,
+                          const char *tag);
+
+#endif
index e29f2b768740b3c1076d52e324015eae8c2f8456..9858e70b87f6d024b2990a0078229193622c83b6 100644 (file)
@@ -2,10 +2,10 @@
 
 #include "lib.h"
 #include "str.h"
-#include "time-util.h"
 #include "imap-common.h"
 #include "imap-quote.h"
 #include "ostream.h"
+#include "imap-progress.h"
 #include "imap-storage-callbacks.h"
 
 static void notify_status(struct mailbox *mailbox ATTR_UNUSED,
@@ -50,70 +50,6 @@ static const char *find_cmd_tag(struct event *event)
               field->value.str : NULL;
 }
 
-const char *
-imap_storage_callback_line(const struct mail_storage_progress_details *dtl,
-                          const char *tag)
-{
-       const char *verb = dtl->verb;
-       unsigned int total = dtl->total;
-       unsigned int processed = dtl->processed;
-
-       if (verb == NULL || *verb == '\0')
-               verb = "Processed";
-
-       if (total > 0 && processed >= total)
-               processed = total - 1;
-
-       /* The "]" character is totally legit in command tags, but it is
-          problematic inside IMAP resp-text-code(s), which are terminated
-          with "]". If the character appears inside the tag, we avoid
-          emitting the tag and replace it with NIL. */
-       bool has_tag = tag != NULL && *tag != '\0' && strchr(tag, ']') == NULL;
-
-       string_t *str = t_str_new(128);
-       str_append(str, "* OK [INPROGRESS");
-       if (has_tag || processed > 0 || total > 0) {
-               str_append(str, " (");
-               if (has_tag)
-                       imap_append_quoted(str, tag);
-               else
-                       str_append(str, "NIL");
-
-               if (processed > 0 || total > 0)
-                       str_printfa(str, " %u", processed);
-               else
-                       str_append(str, " NIL");
-
-               if (total > 0)
-                       str_printfa(str, " %u", total);
-               else
-                       str_append(str, " NIL");
-
-               str_append_c(str, ')');
-       }
-       str_append(str, "] ");
-
-       if (total > 0) {
-               float percentage = processed * 100.0 / total;
-               str_printfa(str, "%s %d%% of the mailbox", verb, (int)percentage);
-
-               long long elapsed_ms = timeval_diff_msecs(&dtl->now,
-                                                         &dtl->start_time);
-               if (percentage > 0 && elapsed_ms > 0) {
-                       int eta_secs = elapsed_ms * (100 - percentage) /
-                                           (1000 * percentage);
-
-                       str_printfa(str, ", ETA %d:%02d",
-                                   eta_secs / 60, eta_secs % 60);
-               }
-       } else if (processed > 0)
-               str_printfa(str, "%s %u item(s)", verb, processed);
-       else
-               str_append(str, "Hang in there..");
-
-       return str_c(str);
-}
-
 int imap_notify_progress(const struct mail_storage_progress_details *dtl,
                         struct client *client)
 {
index 350c100f87ad7236c21bee5ac0b7b99a7c0894dd..71a5d3c710c910baf87f54c28cc5be5be62cb28f 100644 (file)
@@ -3,14 +3,11 @@
 #include "lib.h"
 #include "test-common.h"
 #include "test-subprocess.h"
-#include "imap-storage-callbacks.h"
+#include "mail-storage.h"
+#include "imap-progress.h"
 
 #include <stdio.h>
 
-void client_send_line(struct client *client ATTR_UNUSED, const char *data ATTR_UNUSED)
-{
-}
-
 #define non_0            1
 #define t_non_0          { .tv_sec = non_0 }
 #define t_zero           { .tv_sec = 0 }