summary refs log tree commit diff
path: root/archive.h
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-19 11:27:26 -0400
committerJune McEnroe <june@causal.agency>2020-04-20 11:17:56 -0400
commit4d35c86401b4a947689eac375ec4ba29b3c99d6d (patch)
tree70b71841a1114c88f4d4c0bea0e645ff3b301ca7 /archive.h
parentSkip leading whitespace in message IDs (diff)
downloadbubger-4d35c86401b4a947689eac375ec4ba29b3c99d6d.tar.gz
bubger-4d35c86401b4a947689eac375ec4ba29b3c99d6d.zip
Use template system for paths and URLs
This probably still needs a lot of cleaning up.
Diffstat (limited to '')
-rw-r--r--archive.h49
1 files changed, 16 insertions, 33 deletions
diff --git a/archive.h b/archive.h
index b1cb3dc..532ef47 100644
--- a/archive.h
+++ b/archive.h
@@ -15,7 +15,6 @@
  */
 
 #include <inttypes.h>
-#include <limits.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -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);