summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-07 14:48:09 -0400
committerJune McEnroe <june@causal.agency>2020-04-07 14:48:09 -0400
commitf701024cc28f2a9730dd1f392ab586e73b1c1dd3 (patch)
tree6c93606e6c46f205d859952fdb12f7af403f34e8
parentDon't bother generating real From lines (diff)
downloadimbox-f701024cc28f2a9730dd1f392ab586e73b1c1dd3.tar.gz
imbox-f701024cc28f2a9730dd1f392ab586e73b1c1dd3.zip
Simplify mboxrd output 1.0p2
-rw-r--r--imbox.c41
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(&regex, "^>*From ");
-	while (*lines) {
-		size_t len = strcspn(lines, "\r\n");
-		regmatch_t match;
-		if (!regexec(&regex, 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");
 }