about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.h2
-rw-r--r--export.c12
-rw-r--r--html.c21
3 files changed, 31 insertions, 4 deletions
diff --git a/archive.h b/archive.h
index 49f2a1f..8b991cb 100644
--- a/archive.h
+++ b/archive.h
@@ -206,6 +206,8 @@ int atomFeedClose(FILE *file);
 
 extern const char *htmlTitle;
 int htmlMessageOpen(FILE *file, const struct Envelope *envelope);
+int htmlInlineOpen(FILE *file, const struct BodyPart *part);
+int htmlInlineClose(FILE *file);
 int htmlMessageClose(FILE *file);
 int htmlThreadHead(FILE *file, const struct Envelope *envelope);
 int htmlThreadOpen(FILE *file, const struct Envelope *envelope);
diff --git a/export.c b/export.c
index 3c6a31f..1e07acd 100644
--- a/export.c
+++ b/export.c
@@ -115,7 +115,7 @@ static int exportHTMLBody(
 	FILE *file, struct List *section,
 	const struct BodyPart *structure, struct Data body
 ) {
-	int error;
+	int error = 0;
 	if (structure->multipart) {
 		// TODO: Choose a part from multipart/alternative.
 		for (size_t i = 0; i < structure->parts.len; ++i) {
@@ -133,9 +133,13 @@ static int exportHTMLBody(
 			|| htmlMessageOpen(file, structure->message.envelope)
 			|| exportHTMLBody(file, section, structure->message.structure, body)
 			|| htmlMessageClose(file);
-	} else {
-		// TODO: Content.
-		error = 0;
+	} else if (bodyPartType(structure, "text", "plain")) {
+		// TODO: Check if not inline.
+		const char *content = dataCheck(body, String).string;
+		error = 0
+			|| htmlInlineOpen(file, structure)
+			|| decodeContent(file, escapeXML, structure, content)
+			|| htmlInlineClose(file);
 	}
 	return error;
 }
diff --git a/html.c b/html.c
index 677bed0..b977137 100644
--- a/html.c
+++ b/html.c
@@ -144,6 +144,27 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope) {
 	return error;
 }
 
+int htmlInlineOpen(FILE *file, const struct BodyPart *part) {
+	// TODO: Include Content-Id as id?
+	const char *template = TEMPLATE(
+		<pre lang="[lang]">
+	);
+	const char *lang = "";
+	// FIXME: part->language should be more structured.
+	if (part->language.len && part->language.ptr[0].type == String) {
+		lang = part->language.ptr[0].string;
+	}
+	struct Variable vars[] = {
+		{ "lang", lang },
+		{0},
+	};
+	return templateRender(file, template, vars, escapeXML);
+}
+
+int htmlInlineClose(FILE *file) {
+	return templateRender(file, TEMPLATE(</pre>), NULL, NULL);
+}
+
 int htmlMessageClose(FILE *file) {
 	return templateRender(file, TEMPLATE(</article>), NULL, NULL);
 }