summary refs log tree commit diff
path: root/notemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'notemap.c')
-rw-r--r--notemap.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/notemap.c b/notemap.c
index dfe9872..99a1418 100644
--- a/notemap.c
+++ b/notemap.c
@@ -283,9 +283,14 @@ int main(int argc, char *argv[]) {
 	enum Atom next = atom("next");
 	enum Atom create = atom("create");
 	enum Atom replace = atom("replace");
-	enum Atom envelope = atom("ENVELOPE");
-	FILE *imap = imapOpen(host, port);
-	for (struct Resp resp; resp = imapResp(imap), resp.resp != AtomBye;) {
+
+	FILE *imapRead, *imap;
+	imapOpen(&imapRead, &imap, host, port);
+	for (
+		struct Resp resp;
+		resp = imapResp(imapRead), resp.resp != AtomBye;
+		respFree(resp)
+	) {
 		if (resp.resp == AtomNo || resp.resp == AtomBad) {
 			errx(EX_CONFIG, "%s: %s", Atoms[resp.resp], resp.text);
 		}
@@ -335,8 +340,6 @@ next:
 				"%s SEARCH HEADER X-Universally-Unique-Identifier \"%s\"\r\n",
 				Atoms[AtomSearch], uuid
 			);
-
-			respFree(resp);
 			continue;
 		}
 
@@ -368,7 +371,7 @@ next:
 			resp.data.ptr[0].type == List &&
 			resp.data.ptr[0].list.len > 1 &&
 			resp.data.ptr[0].list.ptr[0].type == Atom &&
-			resp.data.ptr[0].list.ptr[0].atom == envelope &&
+			resp.data.ptr[0].list.ptr[0].atom == AtomEnvelope &&
 			resp.data.ptr[0].list.ptr[1].type == List
 		) {
 			struct List envelope = resp.data.ptr[0].list.ptr[1].list;
@@ -414,9 +417,8 @@ next:
 				Atoms[next], seq
 			);
 		}
-
-		respFree(resp);
 	}
+	fclose(imapRead);
 	fclose(imap);
 
 	int ret = EX_OK;