summary refs log tree commit diff
path: root/archive.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-25 14:22:41 -0400
committerJune McEnroe <june@causal.agency>2020-04-25 14:22:41 -0400
commit67721f3dbd4ffeb1a03145170df40f616ee0a118 (patch)
tree488236f2789a6e41ef4e16eb5d818825e43c29a0 /archive.c
parentFree envelope in concatData (diff)
downloadbubger-67721f3dbd4ffeb1a03145170df40f616ee0a118.tar.gz
bubger-67721f3dbd4ffeb1a03145170df40f616ee0a118.zip
Accumulate thread envelopes before concatenation
Diffstat (limited to '')
-rw-r--r--archive.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/archive.c b/archive.c
index 64b234e..af0329a 100644
--- a/archive.c
+++ b/archive.c
@@ -123,6 +123,7 @@ int main(int argc, char *argv[]) {
 
 	uint32_t uidNext = 0;
 	struct List threads = {0};
+	struct Envelope *envelopes = NULL;
 	for (struct Resp resp; resp = imapResp(imapRead), resp.resp != AtomBye;) {
 		if (resp.resp == AtomNo || resp.resp == AtomBad) {
 			errx(EX_CONFIG, "%s %s", Atoms[resp.resp], resp.text);
@@ -184,8 +185,12 @@ int main(int argc, char *argv[]) {
 				createDir("attachment");
 				createDir("message");
 				createDir("thread");
+
 				threads = resp.data;
 				resp.data = (struct List) {0};
+				envelopes = calloc(threads.len, sizeof(*envelopes));
+				if (!envelopes) err(EX_OSERR, "calloc");
+
 				if (exportFetch(imap, export, threads)) {
 					exportTags = 1;
 					state = Export;
@@ -209,9 +214,12 @@ int main(int argc, char *argv[]) {
 			break; case Concat: {
 				if (resp.resp == AtomFetch) {
 					if (!resp.data.len) errx(EX_PROTOCOL, "missing FETCH data");
-					concatData(threads, dataCheck(resp.data.ptr[0], List).list);
+					struct Data items = dataTake(&resp.data.ptr[0]);
+					concatData(threads, envelopes, dataCheck(items, List).list);
 				}
 				if (resp.tag != concat) break;
+				concatThreads(threads, envelopes);
+				concatIndex(threads, envelopes);
 				uidWrite("UIDNEXT", uidNext);
 				fprintf(imap, "ayy LOGOUT\r\n");
 				state = Logout;