diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-08-02 13:04:42 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2015-08-02 13:04:42 +0200 |
commit | 51480739874ea7070d37a7a09b0df09efedbae83 (patch) | |
tree | 1ae6c7806056c83ef45f9662c60083b9801e7ced | |
parent | c61b6bf465d94b1618acd5dfc5c3c01d65818061 (diff) |
sfeed_mbox: improvements
- don't xmlencode HTML, show as is.
- mangle "From " mboxrd-style. Content-Length would be cleaner but would
require extra buffering.
-rw-r--r-- | sfeed_mbox.c | 48 |
1 files 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("<p>Link: <a href=\"", stdout); - print(fields[FieldLink], stdout, xmlencode); + xmlencode(fields[FieldLink], stdout); fputs("\">", stdout); fputs(fields[FieldLink], stdout); fputs("</a></p>\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); } |