about summary refs log tree commit diff
path: root/imap.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-09 14:22:19 -0400
committerJune McEnroe <june@causal.agency>2020-04-09 14:22:19 -0400
commit128491a7281f03023f7271bbac3cfb9c83ebe535 (patch)
tree77f38e67601417ea3e7ec88287caaecc9a279131 /imap.h
parentImplement login and UIDVALIDITY check (diff)
downloadbubger-128491a7281f03023f7271bbac3cfb9c83ebe535.tar.gz
bubger-128491a7281f03023f7271bbac3cfb9c83ebe535.zip
Send FETCH for uncached UIDs
Diffstat (limited to 'imap.h')
-rw-r--r--imap.h33
1 files changed, 21 insertions, 12 deletions
diff --git a/imap.h b/imap.h
index 0c9f6b9..e4ac7ea 100644
--- a/imap.h
+++ b/imap.h
@@ -96,14 +96,27 @@ struct Data {
 	};
 };
 
+static inline void listPush(struct List *list, struct Data data) {
+	if (list->len == list->cap) {
+		list->cap = (list->cap ? list->cap * 2 : 4);
+		list->ptr = realloc(list->ptr, sizeof(*list->ptr) * list->cap);
+		if (!list->ptr) err(EX_OSERR, "realloc");
+	}
+	list->ptr[list->len++] = data;
+}
+
+static inline void dataFree(struct Data data);
+
+static inline void listFree(struct List list) {
+	for (size_t i = 0; i < list.len; ++i) {
+		dataFree(list.ptr[i]);
+	}
+	free(list.ptr);
+}
+
 static inline void dataFree(struct Data data) {
 	if (data.type == String) free(data.string);
-	if (data.type == List) {
-		for (size_t i = 0; i < data.list.len; ++i) {
-			dataFree(data.list.ptr[i]);
-		}
-		free(data.list.ptr);
-	}
+	if (data.type == List) listFree(data.list);
 }
 
 struct Resp {
@@ -116,12 +129,8 @@ struct Resp {
 };
 
 static inline void respFree(struct Resp resp) {
-	for (size_t i = 0; i < resp.code.len; ++i) {
-		dataFree(resp.code.ptr[i]);
-	}
-	for (size_t i = 0; i < resp.data.len; ++i) {
-		dataFree(resp.data.ptr[i]);
-	}
+	listFree(resp.code);
+	listFree(resp.data);
 }
 
 extern bool imapVerbose;