summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-13 14:58:53 -0400
committerJune McEnroe <june@causal.agency>2020-04-13 14:58:53 -0400
commit9032566beb37bc907ed21cf0446ee427a82bdcb0 (patch)
treeea42d3f62f344f696551cee811028748422116b5
parentDo not escape > in XML/HTML (diff)
downloadbubger-9032566beb37bc907ed21cf0446ee427a82bdcb0.tar.gz
bubger-9032566beb37bc907ed21cf0446ee427a82bdcb0.zip
Export content to Atom
Temporarily disabling HTML output...
Diffstat (limited to '')
-rw-r--r--archive.h12
-rw-r--r--concat.c15
-rw-r--r--export.c64
3 files changed, 35 insertions, 56 deletions
diff --git a/archive.h b/archive.h
index 9ea15f4..749ab1b 100644
--- a/archive.h
+++ b/archive.h
@@ -180,6 +180,13 @@ int mboxFrom(FILE *file);
 int mboxHeader(FILE *file, const char *header);
 int mboxBody(FILE *file, const char *body);
 
+int atomEntryOpen(FILE *file, const struct Envelope *envelope);
+int atomContentOpen(FILE *file);
+int atomContentClose(FILE *file);
+int atomEntryClose(FILE *file);
+int atomFeedOpen(FILE *file, const struct Envelope *envelope);
+int atomFeedClose(FILE *file);
+
 int htmlMessageHead(FILE *file, const struct Envelope *envelope);
 int htmlMessageTail(FILE *file);
 int htmlThreadHead(FILE *file, const struct Envelope *envelope);
@@ -187,8 +194,3 @@ int htmlThreadHeader(FILE *file, const struct Envelope *envelope);
 int htmlThreadOpen(FILE *file);
 int htmlThreadClose(FILE *file);
 int htmlThreadTail(FILE *file);
-
-int atomEntryOpen(FILE *file, const struct Envelope *envelope);
-int atomEntryClose(FILE *file);
-int atomFeedOpen(FILE *file, const struct Envelope *envelope);
-int atomFeedClose(FILE *file);
diff --git a/concat.c b/concat.c
index abf648c..a0f451e 100644
--- a/concat.c
+++ b/concat.c
@@ -157,20 +157,5 @@ void concatData(struct List threads, struct List items) {
 		if (error) err(EX_IOERR, "%s", path);
 	}
 
-	path = pathThread(envelope.messageID, "html");
-	error = stat(path, &status);
-	if (error || status.st_mtime < uidNewest(flat, "html")) {
-		FILE *file = fopen(path, "w");
-		if (!file) err(EX_CANTCREAT, "%s", path);
-
-		error = 0
-			|| htmlThreadHead(file, &envelope) // TODO: Include -h file.
-			|| htmlThreadHeader(file, &envelope)
-			|| concatHTML(file, thread)
-			|| htmlThreadTail(file)
-			|| fclose(file);
-		if (error) err(EX_IOERR, "%s", path);
-	}
-
 	listFree(flat);
 }
diff --git a/export.c b/export.c
index 6327d22..54178f6 100644
--- a/export.c
+++ b/export.c
@@ -53,31 +53,7 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads) {
 	return true;
 }
 
-static void exportEnvelope(uint32_t uid, const struct Envelope *envelope) {
-	int error;
-	FILE *file;
-	const char *path;
-
-	path = pathUID(uid, "html");
-	file = fopen(path, "w");
-	if (!file) err(EX_CANTCREAT, "%s", path);
-	error = 0
-		|| htmlMessageHead(file, envelope)
-		|| htmlMessageTail(file)
-		|| fclose(file);
-	if (error) err(EX_IOERR, "%s", path);
-
-	path = pathUID(uid, "atom");
-	file = fopen(path, "w");
-	if (!file) err(EX_CANTCREAT, "%s", path);
-	error = 0
-		|| atomEntryOpen(file, envelope)
-		|| atomEntryClose(file)
-		|| fclose(file);
-	if (error) err(EX_IOERR, "%s", path);
-}
-
-static void exportRaw(
+static void exportMbox(
 	uint32_t uid, const struct Envelope *envelope,
 	const char *header, const char *body
 ) {
@@ -97,10 +73,32 @@ static void exportRaw(
 	if (error) err(EX_CANTCREAT, "%s", msg);
 }
 
-static void exportBodyPart(
-	uint32_t uid, const struct BodyPart *structure,
-	const struct BodyPart *part, const char *content
+static void exportAtom(
+	uint32_t uid, const struct Envelope *envelope,
+	const struct BodyPart *structure, const char *body
 ) {
+	const char *path = pathUID(uid, "atom");
+	FILE *file = fopen(path, "w");
+	if (!file) err(EX_CANTCREAT, "%s", path);
+
+	int error = atomEntryOpen(file, envelope);
+	if (error) err(EX_IOERR, "%s", path);
+
+	if (
+		!structure->multipart &&
+		!strcmp(structure->type, "TEXT") &&
+		!strcmp(structure->subtype, "PLAIN")
+	) {
+		// TODO: Decode content into file.
+		error = 0
+			|| atomContentOpen(file)
+			|| escapeXML(file, body)
+			|| atomContentClose(file);
+		if (error) err(EX_IOERR, "%s", path);
+	}
+
+	error = atomEntryClose(file) || fclose(file);
+	if (error) err(EX_IOERR, "%s", path);
 }
 
 bool exportData(FILE *imap, enum Atom tag, struct List items) {
@@ -147,14 +145,8 @@ bool exportData(FILE *imap, enum Atom tag, struct List items) {
 	if (!header) errx(EX_PROTOCOL, "missing BODY[HEADER.FIELDS] data item");
 	if (!body) errx(EX_PROTOCOL, "missing BODY[TEXT] data item");
 
-	exportRaw(uid, &envelope, header, body);
-	exportEnvelope(uid, &envelope);
-
-	if (structure.multipart) {
-		// TODO: FETCH each body part.
-	} else {
-		exportBodyPart(uid, &structure, &structure, body);
-	}
+	exportMbox(uid, &envelope, header, body);
+	exportAtom(uid, &envelope, &structure, body);
 
 	envelopeFree(envelope);
 	bodyPartFree(structure);