summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
Diffstat (limited to 'export.c')
-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,