about summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-10 14:20:35 -0400
committerJune McEnroe <june@causal.agency>2020-04-10 14:20:35 -0400
commit4d541ff929d0c320c382d6ebd6569c0c7faf8304 (patch)
tree0d15cc5675aedd31ac6d9c2b219ed6b0bb11ef7e /export.c
parentFix UIDNEXT check and write (diff)
downloadbubger-4d541ff929d0c320c382d6ebd6569c0c7faf8304.tar.gz
bubger-4d541ff929d0c320c382d6ebd6569c0c7faf8304.zip
Refactor main loop state machine
Diffstat (limited to 'export.c')
-rw-r--r--export.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/export.c b/export.c
index 2ff6c5d..c8d742f 100644
--- a/export.c
+++ b/export.c
@@ -50,7 +50,7 @@ static void flatten(struct List *flat, struct List nested) {
 	}
 }
 
-enum Atom exportFetch(FILE *imap, struct List threads) {
+bool exportFetch(FILE *imap, enum Atom tag, struct List threads) {
 	struct List uids = {0};
 	flatten(&uids, threads);
 	for (size_t i = uids.len - 1; i < uids.len; --i) {
@@ -66,10 +66,11 @@ enum Atom exportFetch(FILE *imap, struct List threads) {
 			uids.ptr[i] = uids.ptr[--uids.len];
 		}
 	}
-	enum Atom tag = 0;
-	if (!uids.len) goto done;
+	if (!uids.len) {
+		listFree(uids);
+		return false;
+	}
 
-	tag = atom("exportFetch");
 	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);
@@ -81,10 +82,7 @@ enum Atom exportFetch(FILE *imap, struct List threads) {
 		"BODY[HEADER.FIELDS (" MBOX_HEADERS ")] BODY[TEXT]"
 		")\r\n"
 	);
-
-done:
-	listFree(uids);
-	return tag;
+	return true;
 }
 
 static struct Address parseAddress(struct List list) {