summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-10 15:20:17 -0400
committerJune McEnroe <june@causal.agency>2020-04-10 15:20:17 -0400
commitb9d7c7ee965eb4b96350bc6d081d2bc51dc7f2b0 (patch)
tree193a01dbc5a48e5a2b97596510396709ea574cff
parentClean up exportData (diff)
downloadbubger-b9d7c7ee965eb4b96350bc6d081d2bc51dc7f2b0.tar.gz
bubger-b9d7c7ee965eb4b96350bc6d081d2bc51dc7f2b0.zip
Parse envelope and find thread in concatData
-rw-r--r--concat.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/concat.c b/concat.c
index 9ad8537..26f24f6 100644
--- a/concat.c
+++ b/concat.c
@@ -33,6 +33,14 @@ static uint32_t threadRoot(struct List thread) {
 	return dataCheck(thread.ptr[0], Number).number;
 }
 
+static struct List threadFind(struct List threads, uint32_t root) {
+	for (size_t i = 0; i < threads.len; ++i) {
+		struct List thread = dataCheck(threads.ptr[i], List).list;
+		if (threadRoot(thread) == root) return thread;
+	}
+	errx(EX_TEMPFAIL, "no thread with root UID %" PRIu32, root);
+}
+
 void concatFetch(FILE *imap, enum Atom tag, struct List threads) {
 	fprintf(imap, "%s UID FETCH ", Atoms[tag]);
 	for (size_t i = 0; i < threads.len; ++i) {
@@ -43,4 +51,21 @@ void concatFetch(FILE *imap, enum Atom tag, struct List threads) {
 }
 
 void concatData(struct List threads, struct List items) {
+	uint32_t uid = 0;
+	struct Envelope envelope = {0};
+	for (size_t i = 0; i + 1 < items.len; i += 2) {
+		enum Atom name = dataCheck(items.ptr[i], Atom).atom;
+		struct Data data = items.ptr[i + 1];
+		switch (name) {
+			break; case AtomUID:
+				uid = dataCheck(data, Number).number;
+			break; case AtomEnvelope:
+				parseEnvelope(&envelope, dataCheck(data, List).list);
+			break; default:;
+		}
+	}
+	if (!uid) errx(EX_PROTOCOL, "missing UID data item");
+	if (!envelope.subject) errx(EX_PROTOCOL, "missing ENVELOPE data item");
+
+	struct List thread = threadFind(threads, uid);
 }