From f83e1927a6225699522918bbdf581c2b73efbe71 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 17 Apr 2020 16:35:52 -0400 Subject: Write attachment files All this path stuff needs cleaning up. I think it's time to use the template renderer for paths. --- archive.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'archive.h') diff --git a/archive.h b/archive.h index d0bc00d..06fd435 100644 --- a/archive.h +++ b/archive.h @@ -156,15 +156,19 @@ 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]; + 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[PATH_MAX]; + static char buf[NAME_MAX + 1]; strlcpy(buf, messageID, sizeof(buf)); for (char *ptr = buf; (ptr = strchr(ptr, '/')); ++ptr) { *ptr = ';'; @@ -173,13 +177,13 @@ static inline const char *pathSafe(const char *messageID) { } static inline const char *pathMessage(const char *messageID, const char *type) { - static char buf[PATH_MAX]; + 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]; + static char buf[PATH_MAX + 1]; snprintf(buf, sizeof(buf), "thread/%s.%s", pathSafe(messageID), type); return buf; } @@ -203,6 +207,9 @@ int atomFeedClose(FILE *file); 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 +); int htmlMessageClose(FILE *file); int htmlThreadHead(FILE *file, const struct Envelope *envelope); int htmlThreadOpen(FILE *file, const struct Envelope *envelope); -- cgit 1.4.1