From 9032566beb37bc907ed21cf0446ee427a82bdcb0 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 13 Apr 2020 14:58:53 -0400 Subject: Export content to Atom Temporarily disabling HTML output... --- export.c | 64 ++++++++++++++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 36 deletions(-) (limited to 'export.c') 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); -- cgit 1.4.1