about summary refs log tree commit diff
path: root/archive.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/archive.c b/archive.c
index ea2259c..c2e7f5c 100644
--- a/archive.c
+++ b/archive.c
@@ -103,11 +103,14 @@ int main(int argc, char *argv[]) {
 		if (!pass) errx(EX_CONFIG, ENV_PASSWORD " unset");
 	}
 
-	uint32_t uidNext = 0;
 	enum Atom login = 0;
 	enum Atom examine = atom("EXAMINE");
 	enum Atom thread = atom("THREAD");
 	enum Atom export = 0;
+	enum Atom concat = 0;
+
+	uint32_t uidNext = 0;
+	struct List threads = {0};
 
 	FILE *imap = imapOpen(host, port);
 	for (struct Resp resp; resp = imapResp(imap), resp.resp != AtomBye;) {
@@ -172,7 +175,10 @@ int main(int argc, char *argv[]) {
 			}
 			createDir("UID");
 			createDir("message");
-			export = exportFetch(imap, resp.data);
+			threads = resp.data;
+			resp.data = (struct List) {0};
+			export = exportFetch(imap, threads);
+			if (!export) concat = concatFetch(imap, threads);
 		}
 
 		if (export && resp.resp == AtomFetch) {
@@ -182,6 +188,11 @@ int main(int argc, char *argv[]) {
 			exportData(resp.data.ptr[0].list);
 		}
 
+		if (export && resp.tag == export) {
+			export = 0;
+			concat = concatFetch(imap, threads);
+		}
+
 		respFree(resp);
 	}
 	fclose(imap);