From 2060d70f0574019381cbf6f2c78db941f391224c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Apr 2020 12:00:17 -0400 Subject: Rework path functions again --- export.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'export.c') diff --git a/export.c b/export.c index 8e97370..6327d22 100644 --- a/export.c +++ b/export.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -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( -- cgit 1.4.1