From b9d7c7ee965eb4b96350bc6d081d2bc51dc7f2b0 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 10 Apr 2020 15:20:17 -0400 Subject: Parse envelope and find thread in concatData --- concat.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'concat.c') 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); } -- cgit 1.4.1