about summary refs log tree commit diff
path: root/hdr.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-11 16:11:52 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-11 16:11:52 +0200
commit3d70bd5927759d4d09dfeddd05a94e369d5d54fc (patch)
tree0bff9c6c1ab1d1d525fefc77cb00e79a7c915385 /hdr.c
parentcec286dad2496deebd409887a006dc3c5664235a (diff)
downloadmblaze-3d70bd5927759d4d09dfeddd05a94e369d5d54fc.tar.gz
mblaze-3d70bd5927759d4d09dfeddd05a94e369d5d54fc.tar.xz
mblaze-3d70bd5927759d4d09dfeddd05a94e369d5d54fc.zip
add hdr
Diffstat (limited to 'hdr.c')
-rw-r--r--hdr.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/hdr.c b/hdr.c
new file mode 100644
index 0000000..63485b4
--- /dev/null
+++ b/hdr.c
@@ -0,0 +1,64 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <wchar.h>
+
+#include "blaze822.h"
+
+void
+header(char *hdr, size_t l, char *file)
+{
+	struct message *msg;
+
+	msg = blaze822(file);
+	if (!msg)
+		return;
+
+	char *v = blaze822_hdr_(msg, hdr, l);
+	if (v)
+		printf("%s\n", v);
+}
+
+int
+main(int argc, char *argv[])
+{
+	char *line = 0;
+	size_t linelen = 0;
+	int read;
+
+	int i = 0;
+
+	size_t l = strlen(argv[1])+2;
+        char *hdr = malloc(l);
+	hdr[0] = 0;
+	char *s = hdr+1;
+	char *t = argv[1];
+	while (*t)
+		*s++ = tolower(*t++);
+	*s = ':';
+
+	if (argc == 2 || (argc == 3 && strcmp(argv[1], "-") == 0)) {
+		while ((read = getdelim(&line, &linelen, '\n', stdin)) != -1) {
+			if (line[read-1] == '\n') line[read-1] = 0;
+			header(hdr, l, line);
+			i++;
+		}
+	} else {
+		for (i = 2; i < argc; i++) {
+			header(hdr, l, argv[i]);
+		}
+		i--;
+	}
+
+	printf("%d mails scanned\n", i);
+	
+	return 0;
+}