summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-14 15:40:57 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-14 15:40:57 +0200
commit8b8f3910520abb917a052ad66c1a526c1d097906 (patch)
treead7c29283a87e304b03cec48d71f3e11b55103c1
parent54f695dddf65bc8270825fdf08ed0ddc34a58ec3 (diff)
downloadmblaze-8b8f3910520abb917a052ad66c1a526c1d097906.tar.gz
mblaze-8b8f3910520abb917a052ad66c1a526c1d097906.tar.xz
mblaze-8b8f3910520abb917a052ad66c1a526c1d097906.zip
hdr: use -HEADER to only display the header, else print all headers
-rw-r--r--hdr.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/hdr.c b/hdr.c
index 03ac985..6caeb38 100644
--- a/hdr.c
+++ b/hdr.c
@@ -30,21 +30,51 @@ header(char *file)
 		printf("%s\n", v);
 }
 
+static void
+printhdr(char *hdr)
+{
+	int uc = 1;
+
+	while (*hdr && *hdr != ':') {
+		putc(uc ? toupper(*hdr) : *hdr, stdout);
+		uc = (*hdr == '-');
+		hdr++;
+	}
+	fputs(hdr, stdout);
+	fputc('\n', stdout);
+}
+
+void
+headerall(char *file)
+{
+	struct message *msg;
+
+	msg = blaze822(file);
+	if (!msg)
+		return;
+
+	char *h = 0;
+	while (h = blaze822_next_header(msg, h))
+		printhdr(h);
+}
+
 int
 main(int argc, char *argv[])
 {
-	l = strlen(argv[1])+2;
-        hdr = malloc(l);
-	hdr[0] = 0;
-	char *s = hdr+1;
-	char *t = argv[1];
-	while (*t)
-		*s++ = tolower(*t++);
-	*s = ':';
-
-	int i = blaze822_loop(argc-2, argv+2, header);
-	
-	printf("%d mails scanned\n", i);
+	if (argv[1] && argv[1][0] == '-') {
+		l = strlen(argv[1])+1;
+		hdr = malloc(l);
+		hdr[0] = 0;
+		char *s = hdr+1;
+		char *t = argv[1]+1;
+		while (*t)
+			*s++ = tolower(*t++);
+		*s = ':';
+
+		blaze822_loop(argc-2, argv+2, header);
+	} else {
+		blaze822_loop(argc-1, argv+1, headerall);
+	}
 	
 	return 0;
 }