about summary refs log tree commit diff
path: root/export.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-12 16:43:08 -0400
committerJune McEnroe <june@causal.agency>2020-04-12 16:43:08 -0400
commitc5db1246fbafe62fc125f13664dd0e10204aa0b1 (patch)
treeb05e2bc24a392a61e07b9d8594ea2c17f821de5e /export.c
parentAvoid mutating header/body for mbox output (diff)
downloadbubger-c5db1246fbafe62fc125f13664dd0e10204aa0b1.tar.gz
bubger-c5db1246fbafe62fc125f13664dd0e10204aa0b1.zip
Factor out path functions
Diffstat (limited to 'export.c')
-rw-r--r--export.c32
1 files changed, 11 insertions, 21 deletions
diff --git a/export.c b/export.c
index 8fc82d8..9cc4a37 100644
--- a/export.c
+++ b/export.c
@@ -26,27 +26,16 @@
 #include "archive.h"
 #include "imap.h"
 
-static const char *uidPath(uint32_t uid, const char *type) {
-	static char buf[PATH_MAX];
-	snprintf(buf, sizeof(buf), "UID/%" PRIu32 ".%s", uid, type);
-	return buf;
-}
-
-static const char *messagePath(const char *messageID, const char *type) {
-	static char buf[PATH_MAX];
-	snprintf(buf, sizeof(buf), "message/%s.%s", messageID, type);
-	return buf;
-}
-
 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(uidPath(uid, "atom"), F_OK)
-			|| access(uidPath(uid, "html"), F_OK)
-			|| access(uidPath(uid, "mbox"), F_OK);
+			|| access(pathUID(path, uid, "atom"), F_OK)
+			|| access(pathUID(path, uid, "html"), F_OK)
+			|| access(pathUID(path, uid, "mbox"), F_OK);
 		if (!error) uids.ptr[i] = uids.ptr[--uids.len];
 	}
 	if (!uids.len) {
@@ -69,11 +58,11 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads) {
 static void exportEnvelope(
 	uint32_t uid, struct Envelope *envelope, char *header, char *body
 ) {
-	const char *path;
-	FILE *file;
 	int error;
+	FILE *file;
+	char path[PATH_MAX];
 
-	path = uidPath(uid, "mbox");
+	pathUID(path, uid, "mbox");
 	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0
@@ -83,12 +72,13 @@ static void exportEnvelope(
 		|| fclose(file);
 	if (error) err(EX_IOERR, "%s", path);
 
-	const char *dest = messagePath(envelope->messageID, "mbox");
+	char dest[PATH_MAX];
+	pathMessage(dest, envelope->messageID, "mbox");
 	unlink(dest);
 	error = link(path, dest);
 	if (error) err(EX_CANTCREAT, "%s", dest);
 
-	path = uidPath(uid, "html");
+	pathUID(path, uid, "html");
 	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0
@@ -97,7 +87,7 @@ static void exportEnvelope(
 		|| fclose(file);
 	if (error) err(EX_IOERR, "%s", path);
 
-	path = uidPath(uid, "atom");
+	pathUID(path, uid, "atom");
 	file = fopen(path, "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0