From 67721f3dbd4ffeb1a03145170df40f616ee0a118 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sat, 25 Apr 2020 14:22:41 -0400 Subject: Accumulate thread envelopes before concatenation --- concat.c | 76 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'concat.c') diff --git a/concat.c b/concat.c index 22645e4..e75c857 100644 --- a/concat.c +++ b/concat.c @@ -35,14 +35,6 @@ 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) { @@ -52,6 +44,33 @@ void concatFetch(FILE *imap, enum Atom tag, struct List threads) { fprintf(imap, " (UID ENVELOPE)\r\n"); } +void concatData( + struct List threads, struct Envelope *envelopes, struct List items +) { + uint32_t uid = 0; + struct List 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: envelope = dataCheck(data, List).list; + break; default:; + } + } + if (!uid) errx(EX_PROTOCOL, "missing UID data item"); + if (!envelope.len) errx(EX_PROTOCOL, "missing ENVELOPE data item"); + + for (size_t i = 0; i < threads.len; ++i) { + struct List thread = dataCheck(threads.ptr[i], List).list; + if (threadRoot(thread) == uid) { + parseEnvelope(&envelopes[i], envelope); + return; + } + } + errx(EX_TEMPFAIL, "no thread with root UID %" PRIu32, uid); +} + static const char *uidPath(uint32_t uid, const char *type) { char str[32]; snprintf(str, sizeof(str), "%" PRIu32, uid); @@ -119,24 +138,7 @@ static const char *threadPath(const char *messageID, const char *type) { const char *concatHead; -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); +static void concatThread(struct List thread, const struct Envelope *envelope) { struct List flat = {0}; listFlatten(&flat, thread); @@ -145,7 +147,7 @@ void concatData(struct List threads, struct List items) { const char *path; struct stat status; - path = threadPath(envelope.messageID, "mbox"); + path = threadPath(envelope->messageID, "mbox"); error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "mbox")) { file = fopen(path, "w"); @@ -161,13 +163,13 @@ void concatData(struct List threads, struct List items) { if (error) err(EX_IOERR, "%s", path); } - path = threadPath(envelope.messageID, "atom"); + path = threadPath(envelope->messageID, "atom"); error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "atom")) { FILE *file = fopen(path, "w"); if (!file) err(EX_CANTCREAT, "%s", path); - error = atomFeedOpen(file, &envelope); + error = atomFeedOpen(file, envelope); if (error) err(EX_IOERR, "%s", path); for (size_t i = 0; i < flat.len; ++i) { @@ -180,13 +182,13 @@ void concatData(struct List threads, struct List items) { if (error) err(EX_IOERR, "%s", path); } - path = threadPath(envelope.messageID, "html"); + path = threadPath(envelope->messageID, "html"); error = stat(path, &status); if (error || status.st_mtime < uidNewest(flat, "html")) { FILE *file = fopen(path, "w"); if (!file) err(EX_CANTCREAT, "%s", path); - error = htmlThreadHead(file, &envelope); + error = htmlThreadHead(file, envelope); if (error) err(EX_IOERR, "%s", path); if (concatHead) { @@ -195,7 +197,7 @@ void concatData(struct List threads, struct List items) { } error = 0 - || htmlThreadOpen(file, &envelope) + || htmlThreadOpen(file, envelope) || concatHTML(file, thread) || htmlThreadClose(file) || fclose(file); @@ -203,5 +205,13 @@ void concatData(struct List threads, struct List items) { } listFree(flat); - envelopeFree(envelope); +} + +void concatThreads(struct List threads, const struct Envelope *envelopes) { + for (size_t i = 0; i < threads.len; ++i) { + concatThread(dataCheck(threads.ptr[i], List).list, &envelopes[i]); + } +} + +void concatIndex(struct List threads, const struct Envelope *envelopes) { } -- cgit 1.4.1 2-08-14 09:11:26 -0400'>2022-08-14Remove tweets text fileJune McEnroe Such link rot. 2022-08-04Add Conversations With FriendsJune McEnroe The better of the two, but largely the same. I feel like these books are a bit too autobiographical, but I don't know if I'm allowed to accuse an author of that. My real problem is that I read these books as largely uncritical of their characters. They behave in nonsense ways, are mostly uncritical of their own behaviour, and don't really have arcs of growth or change. I suppose this book had a bit of one, but only in the last two chapters. 2022-07-30Add Normal PeopleJune McEnroe Unbearably straight. Eyerolls and sighs per page off the charts. Shout out to Joanna, I guess. I kinda like the lack of quotation marks though to be honest. After half of the Ruth Ozeki novel and now this, I need to get back to some genre fiction. 2022-07-26Rewrite glitch from new pngoJune McEnroe 2022-07-26Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe