summary refs log tree commit diff
path: root/archive.c
diff options
context:
space:
mode:
Diffstat (limited to 'archive.c')
-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;