From 2d048a0c5a7be72038d70e7473b84f19cacc85fa Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 13 Jun 2021 11:17:21 -0400 Subject: Sort and compress export fetch UIDs --- concat.c | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'concat.c') diff --git a/concat.c b/concat.c index a3b4bac..8da5a7a 100644 --- a/concat.c +++ b/concat.c @@ -37,37 +37,9 @@ #include "archive.h" #include "imap.h" -static uint32_t threadRoot(struct List thread) { - if (!thread.len) errx(EX_PROTOCOL, "empty thread"); - while (thread.ptr[0].type == List) { - thread = thread.ptr[0].list; - if (!thread.len) errx(EX_PROTOCOL, "empty subthread"); - } - return dataCheck(thread.ptr[0], Number).number; -} - -static void compressRoots(FILE *imap, struct List threads) { - uint32_t base = 0; - uint32_t prev = 0; - for (size_t i = 0; i < threads.len; ++i) { - uint32_t root = threadRoot(dataCheck(threads.ptr[i], List).list); - if (!base) { - fprintf(imap, "%" PRIu32, root); - base = prev = root; - } else if (root == prev + 1) { - prev = root; - } else { - if (prev > base) fprintf(imap, ":%" PRIu32, prev); - fprintf(imap, ",%" PRIu32, root); - base = prev = root; - } - } - if (prev > base) fprintf(imap, ":%" PRIu32, prev); -} - void concatFetch(FILE *imap, enum Atom tag, struct List threads) { fprintf(imap, "%s UID FETCH ", Atoms[tag]); - compressRoots(imap, threads); + compressUIDs(imap, threads); fprintf(imap, " (UID ENVELOPE)\r\n"); } @@ -75,7 +47,7 @@ void concatSearch( FILE *imap, enum Atom tag, struct List threads, const char *expr ) { fprintf(imap, "%s UID SEARCH CHARSET UTF-8 UID ", Atoms[tag]); - compressRoots(imap, threads); + compressUIDs(imap, threads); fprintf(imap, " %s\r\n", expr); } -- cgit 1.4.1