From 4d35c86401b4a947689eac375ec4ba29b3c99d6d Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Sun, 19 Apr 2020 11:27:26 -0400 Subject: Use template system for paths and URLs This probably still needs a lot of cleaning up. --- archive.h | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) (limited to 'archive.h') diff --git a/archive.h b/archive.h index b1cb3dc..532ef47 100644 --- a/archive.h +++ b/archive.h @@ -15,7 +15,6 @@ */ #include -#include #include #include #include @@ -108,6 +107,15 @@ static inline bool bodyPartType( return !strcasecmp(partType, type) && !strcasecmp(part->subtype, subtype); } +static inline char *paramGet(struct List params, const char *key) { + for (size_t i = 0; i + 1 < params.len; i += 2) { + if (!strcasecmp(dataCheck(params.ptr[i], String).string, key)) { + return dataCheck(params.ptr[i + 1], String).string; + } + } + return NULL; +} + static inline void bodyPartFree(struct BodyPart part) { if (part.multipart) { for (size_t i = 0; i < part.parts.len; ++i) { @@ -143,6 +151,7 @@ struct Variable { typedef int EscapeFn(FILE *file, const char *str); +int escapePath(FILE *file, const char *str); int escapeURL(FILE *file, const char *str); int escapeXML(FILE *file, const char *str); @@ -160,37 +169,11 @@ char *decodeHeader(const char *header); char *decodeToString(const struct BodyPart *part, const char *content); int decodeToFile(FILE *file, const struct BodyPart *part, const char *content); -struct Attachment { - char path[3][NAME_MAX + 1]; -}; - -static inline const char *pathUID(uint32_t uid, const char *type) { - static char buf[PATH_MAX + 1]; - snprintf(buf, sizeof(buf), "UID/%" PRIu32 ".%s", uid, type); - return buf; -} - -static inline const char *pathSafe(const char *messageID) { - if (!strchr(messageID, '/')) return messageID; - static char buf[NAME_MAX + 1]; - strlcpy(buf, messageID, sizeof(buf)); - for (char *ptr = buf; (ptr = strchr(ptr, '/')); ++ptr) { - *ptr = ';'; - } - return buf; -} - -static inline const char *pathMessage(const char *messageID, const char *type) { - static char buf[PATH_MAX + 1]; - snprintf(buf, sizeof(buf), "message/%s.%s", pathSafe(messageID), type); - return buf; -} - -static inline const char *pathThread(const char *messageID, const char *type) { - static char buf[PATH_MAX + 1]; - snprintf(buf, sizeof(buf), "thread/%s.%s", pathSafe(messageID), type); - return buf; -} +#define PATH_UID "UID/[uid].[type]" +#define PATH_MESSAGE "message/[messageID].[type]" +#define PATH_THREAD "thread/[messageID].[type]" +#define PATH_ATTACHMENT \ + "attachment/[messageID]/[section]/[name][disposition][.][subtype]" #define MBOX_HEADERS \ "Date Subject From Sender Reply-To To Cc Bcc " \ @@ -212,7 +195,7 @@ extern const char *htmlTitle; int htmlMessageOpen(FILE *file, const struct Envelope *envelope); int htmlInline(FILE *file, const struct BodyPart *part, const char *content); int htmlAttachment( - FILE *file, const struct BodyPart *part, const struct Attachment *attach + FILE *file, const struct BodyPart *part, const struct Variable pathVars[] ); int htmlMessageClose(FILE *file); int htmlThreadHead(FILE *file, const struct Envelope *envelope); -- cgit 1.4.1