From 51480739874ea7070d37a7a09b0df09efedbae83 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sun, 2 Aug 2015 13:04:42 +0200 Subject: sfeed_mbox: improvements - don't xmlencode HTML, show as is. - mangle "From " mboxrd-style. Content-Length would be cleaner but would require extra buffering. --- sfeed_mbox.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 5c531e3..10b31c8 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -13,6 +13,48 @@ static char *line = NULL; static size_t linesize = 0; +/* Unescape / decode fields printed by string_print_encoded() + * "\\" to "\", "\t", to TAB, "\n" to newline. Unrecognised escape sequences + * are ignored: "\z" etc. Mangle "From " in mboxrd style (always prefix >). */ +static void +printcontent(const char *s, FILE *fp) +{ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + + for (; *s; s++) { +read: + switch (*s) { + case '\\': + switch (*(++s)) { + case '\0': return; /* ignore */ + case '\\': fputc('\\', fp); break; + case 't': fputc('\t', fp); break; + case 'n': + fputc('\n', fp); + for (s++; *s && *s == '>'; s++) + fputc('>', fp); + /* escape "From ", mboxrd-style. */ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + goto read; + } + break; + case '\0': return; /* ignore */ + case '\n': + fputc((int)*s, fp); + for (s++; *s && *s == '>'; s++) + fputc('>', fp); + /* escape "From ", mboxrd-style. */ + if (!strncmp(s, "From ", 5)) + fputc('>', fp); + goto read; + default: + fputc((int)*s, fp); + } + } +} + static void printfeed(FILE *fp, const char *feedname) { @@ -61,14 +103,14 @@ printfeed(FILE *fp, const char *feedname) if (!strcmp(fields[FieldContentType], "html")) { fputs("

Link: ", stdout); fputs(fields[FieldLink], stdout); fputs("

\n\n", stdout); - decodefield(fields[FieldContent], stdout, fputc); + printcontent(fields[FieldContent], stdout); } else { printf("Link: %s\n\n", fields[FieldLink]); - decodefield(fields[FieldContent], stdout, fputc); + printcontent(fields[FieldContent], stdout); } fputs("\n\n", stdout); } -- cgit v1.2.3