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 '')
-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
ommit/www/text.causal.agency/037-care.7?id=94a437f5107bfc69ecb2ac4fc4e7d5ebc7a1c1a5&follow=1'>Update Care with time-to-ID and piercingsJune McEnroe 2022-07-26Add -w to upJune McEnroe 2022-07-13Set push.autoSetupRemoteJune McEnroe 2022-07-08Remove TOURJune McEnroe There is not that much distinct stuff here anymore. 2022-07-03Add The Bone Shard EmperorJune McEnroe Suffers a little bit from middle book but I really enjoyed it. Read it faster than the first one too, despite its length. 2022-06-25Bump xterm font size to 12June McEnroe 2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe 2022-06-10Switch to jorts Install scriptJune McEnroe 2022-06-08Indicate if still reading or no resultsJune McEnroe 2022-06-08Add Maiden, Mother, CroneJune McEnroe Mixed bag like most collections of short stories. Some of them are pretty good. The author of the worst written story also has the worst written bio. 2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe 2022-06-03Set line number on File linesJune McEnroe 2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe Absolutely indiscriminately. 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe For some reason I haven't been able to figure out, trying to poll /dev/tty returns POLLNVAL (and this was using 100% CPU looping), but using stderr instead works fine. 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe