about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--imbox.c38
1 files changed, 7 insertions, 31 deletions
diff --git a/imbox.c b/imbox.c
index 22d4775..96bce08 100644
--- a/imbox.c
+++ b/imbox.c
@@ -50,12 +50,12 @@ static void compile(regex_t *regex, const char *pattern) {
 }
 
 static void printLines(const char *lines) {
-	static regex_t fromRegex;
-	compile(&fromRegex, "^>*From ");
+	static regex_t regex;
+	compile(&regex, "^>*From ");
 	while (*lines) {
 		size_t len = strcspn(lines, "\r\n");
 		regmatch_t match;
-		if (!regexec(&fromRegex, lines, 1, &match, 0) && !match.rm_so) {
+		if (!regexec(&regex, lines, 1, &match, 0) && !match.rm_so) {
 			printf(">%.*s\n", (int)len, lines);
 		} else {
 			printf("%.*s\n", (int)len, lines);
@@ -67,34 +67,10 @@ static void printLines(const char *lines) {
 }
 
 static void mboxrd(const char *headers, const char *body) {
-#define MATCH(str, match) \
-	(int)((match).rm_eo - (match).rm_so), &(str)[(match).rm_so]
-	static regex_t fromRegex, dateRegex;
-
-	compile(&fromRegex, "^From: ([^\r]|\r\n[ \t])*<([^>]+)>");
-	regmatch_t from[3];
-	int error = regexec(&fromRegex, headers, 3, from, 0);
-	if (error) errx(EX_DATAERR, "missing From header");
-	printf("From %.*s ", MATCH(headers, from[2]));
-
-	// Day, Date Month Year Time -> Day Month Date Time Year
-	compile(&dateRegex, "^Date: (...), (..) (...) (....) (.{8})");
-	regmatch_t date[6];
-	error = regexec(&dateRegex, headers, 6, date, 0);
-	if (error) errx(EX_DATAERR, "missing Date header");
-	printf(
-		"%.*s %.*s %.*s %.*s %.*s\n",
-		MATCH(headers, date[1]),
-		MATCH(headers, date[3]),
-		MATCH(headers, date[2]),
-		MATCH(headers, date[5]),
-		MATCH(headers, date[4])
-	);
-
+	printf("From mboxrd@z Thu Jan  1 00:00:00 1970\n");
 	printLines(headers);
 	printLines(body);
 	printf("\n");
-#undef MATCH
 }
 
 static void lookup(const char **host, const char **port, const char *domain) {
@@ -165,7 +141,7 @@ static void lookup(const char **host, const char **port, const char *domain) {
 
 static bool verbose;
 
-int tlsRead(void *_tls, char *ptr, int len) {
+static int tlsRead(void *_tls, char *ptr, int len) {
 	struct tls *tls = _tls;
 	ssize_t ret;
 	do {
@@ -176,7 +152,7 @@ int tlsRead(void *_tls, char *ptr, int len) {
 	return ret;
 }
 
-int tlsWrite(void *_tls, const char *ptr, int len) {
+static int tlsWrite(void *_tls, const char *ptr, int len) {
 	struct tls *tls = _tls;
 	ssize_t ret;
 	do {
@@ -187,7 +163,7 @@ int tlsWrite(void *_tls, const char *ptr, int len) {
 	return ret;
 }
 
-int tlsClose(void *_tls) {
+static int tlsClose(void *_tls) {
 	struct tls *tls = _tls;
 	int error = tls_close(tls);
 	if (error) errx(EX_IOERR, "tls_close: %s", tls_error(tls));