about summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-06-13 11:17:21 -0400
committerJune McEnroe <june@causal.agency>2021-06-13 11:17:21 -0400
commit2d048a0c5a7be72038d70e7473b84f19cacc85fa (patch)
tree9d6f7549740f9f7bf7d278cc6e5ce39256cb0c7d /export.c
parentCompress thread root UID sets with ranges (diff)
downloadbubger-2d048a0c5a7be72038d70e7473b84f19cacc85fa.tar.gz
bubger-2d048a0c5a7be72038d70e7473b84f19cacc85fa.zip
Sort and compress export fetch UIDs
Diffstat (limited to '')
-rw-r--r--export.c11
1 files changed, 8 insertions, 3 deletions
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,