summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-11-29 01:12:45 -0500
committerJune McEnroe <june@causal.agency>2020-11-29 01:12:45 -0500
commita852935b3c51e527bd28ceaf10ae81424b8cb49f (patch)
tree6918c5016decacf61ef11a1c60b1c3bd9c45b298
parentRevert to old quoting style in atom (diff)
downloadbubger-a852935b3c51e527bd28ceaf10ae81424b8cb49f.tar.gz
bubger-a852935b3c51e527bd28ceaf10ae81424b8cb49f.zip
Rearrange archive.h
-rw-r--r--archive.h144
1 files changed, 71 insertions, 73 deletions
diff --git a/archive.h b/archive.h
index 8576df5..3605a4b 100644
--- a/archive.h
+++ b/archive.h
@@ -25,19 +25,61 @@
  * covered work.
  */
 
-#include <inttypes.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
 #include <strings.h>
 #include <time.h>
 
 #include "imap.h"
 
+#define Q(...) #__VA_ARGS__
+
 #define GENERATOR_URL "https://git.causal.agency/bubger"
 
-#define Q(...) #__VA_ARGS__
+#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 " \
+	"Message-Id In-Reply-To References " \
+	"MIME-Version Content-Type Content-Disposition Content-Transfer-Encoding"
+
+extern const char *baseURL;
+extern const char *baseTitle;
+extern const char *baseMailto;
+extern const char *baseSubscribe;
+
+static inline struct ISO8601 {
+	char s[sizeof("0000-00-00T00:00:00Z")];
+} iso8601(time_t time) {
+	struct ISO8601 buf;
+	strftime(buf.s, sizeof(buf.s), "%FT%TZ", gmtime(&time));
+	return buf;
+}
+
+struct Variable {
+	const char *name;
+	const char *value;
+};
+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);
+
+int templateRender(
+	FILE *file, const char *template,
+	const struct Variable vars[], EscapeFn *escape
+);
+char *templateString(
+	const char *template,
+	const struct Variable vars[], EscapeFn *escape
+);
 
 struct Address {
 	char *name;
@@ -45,10 +87,6 @@ struct Address {
 	const char *host;
 };
 
-static inline const char *addressName(struct Address addr) {
-	return (addr.name ? addr.name : addr.mailbox);
-}
-
 struct AddressList {
 	size_t len;
 	struct Address *addrs;
@@ -64,25 +102,6 @@ struct Envelope {
 	const char *messageID;
 };
 
-static inline void envelopeFree(struct Envelope envelope) {
-	free(envelope.subject);
-	free(envelope.from.name);
-	free(envelope.sender.name);
-	free(envelope.replyTo.name);
-	for (size_t i = 0; i < envelope.to.len; ++i) {
-		free(envelope.to.addrs[i].name);
-	}
-	for (size_t i = 0; i < envelope.cc.len; ++i) {
-		free(envelope.cc.addrs[i].name);
-	}
-	for (size_t i = 0; i < envelope.bcc.len; ++i) {
-		free(envelope.bcc.addrs[i].name);
-	}
-	free(envelope.to.addrs);
-	free(envelope.cc.addrs);
-	free(envelope.bcc.addrs);
-}
-
 struct BodyPart {
 	bool multipart;
 	union {
@@ -115,6 +134,13 @@ struct BodyPart {
 	struct List location;
 };
 
+void parseEnvelope(struct Envelope *envelope, struct List list);
+void parseBodyPart(struct BodyPart *part, struct List list);
+
+static inline const char *addressName(struct Address addr) {
+	return (addr.name ? addr.name : addr.mailbox);
+}
+
 static inline bool bodyPartType(
 	const struct BodyPart *part, const char *type, const char *subtype
 ) {
@@ -131,6 +157,25 @@ static inline char *paramGet(struct List params, const char *key) {
 	return NULL;
 }
 
+static inline void addressListFree(struct AddressList list) {
+	for (size_t i = 0; i < list.len; ++i) {
+		free(list.addrs[i].name);
+	}
+}
+
+static inline void envelopeFree(struct Envelope envelope) {
+	free(envelope.subject);
+	free(envelope.from.name);
+	free(envelope.sender.name);
+	free(envelope.replyTo.name);
+	addressListFree(envelope.to);
+	addressListFree(envelope.cc);
+	addressListFree(envelope.bcc);
+	free(envelope.to.addrs);
+	free(envelope.cc.addrs);
+	free(envelope.bcc.addrs);
+}
+
 static inline void bodyPartFree(struct BodyPart part) {
 	if (part.multipart) {
 		for (size_t i = 0; i < part.parts.len; ++i) {
@@ -148,19 +193,10 @@ static inline void bodyPartFree(struct BodyPart part) {
 	}
 }
 
-void parseEnvelope(struct Envelope *envelope, struct List list);
-void parseBodyPart(struct BodyPart *part, struct List list);
-
 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);
 
-#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]"
-
 bool exportFetch(FILE *imap, enum Atom tag, struct List threads);
 bool exportData(FILE *imap, enum Atom tag, struct List items);
 
@@ -172,44 +208,6 @@ void concatData(
 void concatThreads(struct List threads, const struct Envelope *envelopes);
 void concatIndex(struct List threads, const struct Envelope *envelopes);
 
-static inline struct ISO8601 {
-	char s[sizeof("0000-00-00T00:00:00Z")];
-} iso8601(time_t time) {
-	struct ISO8601 buf;
-	strftime(buf.s, sizeof(buf.s), "%FT%TZ", gmtime(&time));
-	return buf;
-}
-
-struct Variable {
-	const char *name;
-	const char *value;
-};
-
-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);
-
-int templateRender(
-	FILE *file, const char *template,
-	const struct Variable vars[], EscapeFn *escape
-);
-char *templateString(
-	const char *template,
-	const struct Variable vars[], EscapeFn *escape
-);
-
-extern const char *baseURL;
-extern const char *baseTitle;
-extern const char *baseMailto;
-extern const char *baseSubscribe;
-
-#define MBOX_HEADERS \
-	"Date Subject From Sender Reply-To To Cc Bcc " \
-	"Message-Id In-Reply-To References " \
-	"MIME-Version Content-Type Content-Disposition Content-Transfer-Encoding"
-
 int mboxFrom(FILE *file);
 int mboxHeader(FILE *file, const char *header);
 int mboxBody(FILE *file, const char *body);