about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--archive.h8
-rw-r--r--atom.c8
-rw-r--r--concat.c4
-rw-r--r--export.c16
4 files changed, 24 insertions, 12 deletions
diff --git a/archive.h b/archive.h
index 541c03c..ffe1561 100644
--- a/archive.h
+++ b/archive.h
@@ -190,7 +190,7 @@ int htmlThreadOpen(FILE *file);
 int htmlThreadClose(FILE *file);
 int htmlThreadTail(FILE *file);
 
-int atomEntryHead(FILE *file, const struct Envelope *envelope);
-int atomEntryTail(FILE *file);
-int atomFeedHead(FILE *file, const struct Envelope *envelope);
-int atomFeedTail(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/atom.c b/atom.c
index bf4b456..83a4457 100644
--- a/atom.c
+++ b/atom.c
@@ -30,7 +30,7 @@ static char *atomID(const char *messageID) {
 	return templateURL("mailto:?Message-Id=[messageID]", vars);
 }
 
-int atomEntryHead(FILE *file, const struct Envelope *envelope) {
+int atomEntryOpen(FILE *file, const struct Envelope *envelope) {
 	char *id = atomID(envelope->messageID);
 	char date[sizeof("0000-00-00T00:00:00Z")];
 	strftime(date, sizeof(date), "%FT%TZ", gmtime(&envelope->utc));
@@ -58,12 +58,12 @@ int atomEntryHead(FILE *file, const struct Envelope *envelope) {
 	return error;
 }
 
-int atomEntryTail(FILE *file) {
+int atomEntryClose(FILE *file) {
 	int n = fprintf(file, "</entry>\n");
 	return (n < 0 ? n : 0);
 }
 
-int atomFeedHead(FILE *file, const struct Envelope *envelope) {
+int atomFeedOpen(FILE *file, const struct Envelope *envelope) {
 	char *id = atomID(envelope->messageID);
 	char date[sizeof("0000-00-00T00:00:00Z")];
 	strftime(date, sizeof(date), "%FT%TZ", gmtime(&(time_t) { time(NULL) }));
@@ -93,7 +93,7 @@ int atomFeedHead(FILE *file, const struct Envelope *envelope) {
 	return error;
 }
 
-int atomFeedTail(FILE *file) {
+int atomFeedClose(FILE *file) {
 	int n = fprintf(file, "</feed>\n");
 	return (n < 0 ? n : 0);
 }
diff --git a/concat.c b/concat.c
index 07d1f6f..5e8be3d 100644
--- a/concat.c
+++ b/concat.c
@@ -145,7 +145,7 @@ void concatData(struct List threads, struct List items) {
 		FILE *file = fopen(dst, "w");
 		if (!file) err(EX_CANTCREAT, "%s", dst);
 
-		error = atomFeedHead(file, &envelope);
+		error = atomFeedOpen(file, &envelope);
 		if (error) err(EX_IOERR, "%s", dst);
 
 		for (size_t i = 0; i < flat.len; ++i) {
@@ -154,7 +154,7 @@ void concatData(struct List threads, struct List items) {
 			if (error) err(EX_IOERR, "%s", dst);
 		}
 
-		error = atomFeedTail(file) || fclose(file);
+		error = atomFeedClose(file) || fclose(file);
 		if (error) err(EX_IOERR, "%s", dst);
 	}
 
diff --git a/export.c b/export.c
index 411b70c..8e97370 100644
--- a/export.c
+++ b/export.c
@@ -71,8 +71,8 @@ static void exportEnvelope(uint32_t uid, const struct Envelope *envelope) {
 	file = fopen(pathUID(path, uid, "atom"), "w");
 	if (!file) err(EX_CANTCREAT, "%s", path);
 	error = 0
-		|| atomEntryHead(file, envelope)
-		|| atomEntryTail(file)
+		|| atomEntryOpen(file, envelope)
+		|| atomEntryClose(file)
 		|| fclose(file);
 	if (error) err(EX_IOERR, "%s", path);
 }
@@ -98,6 +98,12 @@ static void exportRaw(
 	if (error) err(EX_CANTCREAT, "%s", dst);
 }
 
+static void exportBodyPart(
+	uint32_t uid, const struct BodyPart *structure,
+	const struct BodyPart *part, const char *content
+) {
+}
+
 bool exportData(FILE *imap, enum Atom tag, struct List items) {
 	uint32_t uid = 0;
 	struct Envelope envelope = {0};
@@ -145,6 +151,12 @@ bool exportData(FILE *imap, enum Atom tag, struct List items) {
 	exportRaw(uid, &envelope, header, body);
 	exportEnvelope(uid, &envelope);
 
+	if (structure.multipart) {
+		// TODO: FETCH each body part.
+	} else {
+		exportBodyPart(uid, &structure, &structure, body);
+	}
+
 	envelopeFree(envelope);
 	bodyPartFree(structure);
 	return false;