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 --- export.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'export.c') diff --git a/export.c b/export.c index bebd524..b7420fb 100644 --- a/export.c +++ b/export.c @@ -48,6 +48,12 @@ static char *exportPath(uint32_t uid, const char *type) { return templateString(PATH_UID, vars, escapePath); } +static int numberCompare(const void *_a, const void *_b) { + const struct Data *a = _a; + const struct Data *b = _b; + return (a->number > b->number) - (a->number < b->number); +} + bool exportFetch(FILE *imap, enum Atom tag, struct List threads) { struct List uids = {0}; listFlatten(&uids, threads); @@ -69,11 +75,10 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads) { listFree(uids); return false; } + qsort(uids.ptr, uids.len, sizeof(*uids.ptr), numberCompare); fprintf(imap, "%s UID FETCH ", Atoms[tag]); - for (size_t i = 0; i < uids.len; ++i) { - fprintf(imap, "%s%" PRIu32, (i ? "," : ""), uids.ptr[i].number); - } + compressUIDs(imap, uids); listFree(uids); fprintf( imap, -- cgit 1.4.1