From f701024cc28f2a9730dd1f392ab586e73b1c1dd3 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Tue, 7 Apr 2020 14:48:09 -0400 Subject: Simplify mboxrd output --- imbox.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/imbox.c b/imbox.c index 96bce08..24ac67b 100644 --- a/imbox.c +++ b/imbox.c @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -40,36 +39,22 @@ # endif #endif -static void compile(regex_t *regex, const char *pattern) { - if (regex->re_nsub) return; - int error = regcomp(regex, pattern, REG_EXTENDED | REG_NEWLINE); - if (!error) return; - char buf[256]; - regerror(error, regex, buf, sizeof(buf)); - errx(EX_SOFTWARE, "regcomp: %s: %s", buf, pattern); -} - -static void printLines(const char *lines) { - static regex_t regex; - compile(®ex, "^>*From "); - while (*lines) { - size_t len = strcspn(lines, "\r\n"); - regmatch_t match; - if (!regexec(®ex, lines, 1, &match, 0) && !match.rm_so) { - printf(">%.*s\n", (int)len, lines); +static void mboxrd(char *headers, char *body) { + printf("From mboxrd@z Thu Jan 1 00:00:00 1970\n"); + for (char *crlf; (crlf = strstr(headers, "\r\n")); headers = &crlf[2]) { + *crlf = '\0'; + printf("%s\n", headers); + } + for (char *crlf; (crlf = strstr(body, "\r\n")); body = &crlf[2]) { + *crlf = '\0'; + char *from = body; + while (*from == '>') from++; + if (!strncmp(from, "From ", 5)) { + printf(">%s\n", body); } else { - printf("%.*s\n", (int)len, lines); + printf("%s\n", body); } - lines += len; - if (*lines == '\r') lines++; - if (*lines == '\n') lines++; } -} - -static void mboxrd(const char *headers, const char *body) { - printf("From mboxrd@z Thu Jan 1 00:00:00 1970\n"); - printLines(headers); - printLines(body); printf("\n"); } -- cgit 1.4.1