about summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-13 12:00:17 -0400
committerJune McEnroe <june@causal.agency>2020-04-13 12:00:17 -0400
commit2060d70f0574019381cbf6f2c78db941f391224c (patch)
treee4e80d26ee609f4870e6206adcfc2296897a0e6c /export.c
parentRename atom rendering functions (diff)
downloadbubger-2060d70f0574019381cbf6f2c78db941f391224c.tar.gz
bubger-2060d70f0574019381cbf6f2c78db941f391224c.zip
Rework path functions again
Diffstat (limited to 'export.c')
-rw-r--r--export.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/export.c b/export.c
index 8e97370..6327d22 100644
--- a/export.c
+++ b/export.c
@@ -16,7 +16,6 @@
 
 #include <err.h>
 #include <inttypes.h>
-#include <limits.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -29,13 +28,12 @@
 bool exportFetch(FILE *imap, enum Atom tag, struct List threads) {
 	struct List uids = {0};
 	listFlatten(&uids, threads);
-	char path[PATH_MAX];
 	for (size_t i = uids.len - 1; i < uids.len; --i) {
 		uint32_t uid = dataCheck(uids.ptr[i], Number).number;
 		int error = 0
-			|| access(pathUID(path, uid, "atom"), F_OK)
-			|| access(pathUID(path, uid, "html"), F_OK)
-			|| access(pathUID(path, uid, "mbox"), F_OK);
+			|| access(pathUID(uid, "atom"), F_OK)
+			|| access(pathUID(uid, "html"), F_OK)
+			|| access(pathUID(uid, "mbox"), F_OK);
 		if (!error) uids.ptr[i] = uids.ptr[--uids.len];
 	}
 	if (!uids.len) {
@@ -58,9 +56,10 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads) {
 static void exportEnvelope(uint32_t uid, const struct Envelope *envelope) {
 	int error;
 	FILE *file;
-	char path[PATH_MAX];
+	const char *path;
 
-	file = fopen(pathUID(path, uid, "html"), "w");
+	path = pathUID(uid, "html");
+	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0
 		|| htmlMessageHead(file, envelope)
@@ -68,7 +67,8 @@ static void exportEnvelope(uint32_t uid, const struct Envelope *envelope) {
 		|| fclose(file);
 	if (error) err(EX_IOERR, "%s", path);
 
-	file = fopen(pathUID(path, uid, "atom"), "w");
+	path = pathUID(uid, "atom");
+	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0
 		|| atomEntryOpen(file, envelope)
@@ -81,21 +81,20 @@ static void exportRaw(
 	uint32_t uid, const struct Envelope *envelope,
 	const char *header, const char *body
 ) {
-	char src[PATH_MAX];
-	FILE *file = fopen(pathUID(src, uid, "mbox"), "w");
-	if (!file) err(EX_CANTCREAT, "%s", src);
+	const char *path = pathUID(uid, "mbox");
+	FILE *file = fopen(path, "w");
+	if (!file) err(EX_CANTCREAT, "%s", path);
 	int error = 0
 		|| mboxFrom(file)
 		|| mboxHeader(file, header)
 		|| mboxBody(file, body)
 		|| fclose(file);
-	if (error) err(EX_IOERR, "%s", src);
+	if (error) err(EX_IOERR, "%s", path);
 
-	char dst[PATH_MAX];
-	pathMessage(dst, envelope->messageID, "mbox");
-	unlink(dst);
-	error = link(src, dst);
-	if (error) err(EX_CANTCREAT, "%s", dst);
+	const char *msg = pathMessage(envelope->messageID, "mbox");
+	unlink(msg);
+	error = link(path, msg);
+	if (error) err(EX_CANTCREAT, "%s", msg);
 }
 
 static void exportBodyPart(