summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-01 17:15:22 -0400
committerJune McEnroe <june@causal.agency>2020-05-01 17:20:45 -0400
commiteeed8059e2eca4e078f2b95ae6650963b3edfd2e (patch)
tree3cc786d51b298e181bea4220fa3ab5e47db74d4b /imbox.c
parentRemove unused includes (diff)
downloadimbox-eeed8059e2eca4e078f2b95ae6650963b3edfd2e.tar.gz
imbox-eeed8059e2eca4e078f2b95ae6650963b3edfd2e.zip
Update IMAP parser
Diffstat (limited to 'imbox.c')
-rw-r--r--imbox.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/imbox.c b/imbox.c
index d63763d..a37b24d 100644
--- a/imbox.c
+++ b/imbox.c
@@ -172,11 +172,14 @@ int main(int argc, char *argv[]) {
 
 	enum Atom login = 0;
 	enum Atom examine = atom("examine");
-	enum Atom headerFields = atom("HEADER.FIELDS");
-	enum Atom text = atom("TEXT");
 
-	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);
 		}
@@ -240,10 +243,10 @@ int main(int argc, char *argv[]) {
 				if (item.type != List) continue;
 				if (!item.list.len) continue;
 				if (item.list.ptr[0].type != Atom) continue;
-				if (item.list.ptr[0].atom == headerFields) {
+				if (item.list.ptr[0].atom == AtomHeader) {
 					if (i + 1 < items.len) headers = items.ptr[i + 1];
 				}
-				if (item.list.ptr[0].atom == text) {
+				if (item.list.ptr[0].atom == AtomText) {
 					if (i + 1 < items.len) body = items.ptr[i + 1];
 				}
 			}
@@ -260,8 +263,7 @@ int main(int argc, char *argv[]) {
 		if (resp.tag == AtomFetch) {
 			fprintf(imap, "ayy LOGOUT\r\n");
 		}
-
-		respFree(resp);
 	}
+	fclose(imapRead);
 	fclose(imap);
 }