diff options
-rw-r--r-- | imbox.c | 41 |
1 files 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 <ctype.h> #include <err.h> -#include <regex.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -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"); } |