about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--maddr.c76
-rw-r--r--man/maddr.160
-rw-r--r--man/mmsg.71
4 files changed, 139 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index cbbbf62..0f57775 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,10 @@
 CFLAGS=-g -O1 -Wall -Wno-switch -Wextra -fstack-protector-strong -D_FORTIFY_SOURCE=2
 
-ALL = mdirs mflag mhdr minc mlist mmime mscan mseq mshow msort mthread
+ALL = maddr mdirs mflag mhdr minc mlist mmime mscan mseq mshow msort mthread
 
 all: $(ALL)
 
+maddr: maddr.o blaze822.o seq.o rfc2047.o
 mdirs: mdirs.o
 mflag: mflag.o blaze822.o seq.o
 mhdr: mhdr.o blaze822.o seq.o rfc2047.o
diff --git a/maddr.c b/maddr.c
new file mode 100644
index 0000000..fc87763
--- /dev/null
+++ b/maddr.c
@@ -0,0 +1,76 @@
+#include <sys/types.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "blaze822.h"
+
+static char defaulthflags[] = "from:sender:reply-to:to:cc:bcc:"
+    "resent-from:resent-sender:resent-to:resent-cc:resent-bcc:";
+static char *hflag = defaulthflags;
+
+void
+addr(char *file)
+{
+	while (*file == ' ' || *file == '\t')
+		file++;
+	
+	struct message *msg = blaze822(file);
+        if (!msg)
+		return;
+
+	char *h = hflag;
+	char *v;
+	while (*h) {
+		char *n = strchr(h, ':');
+		if (n)
+			*n = 0;
+		v = blaze822_chdr(msg, h);
+		if (v) {
+			char *disp, *addr;
+			while ((v = blaze822_addr(v, &disp, &addr))) {
+				if (disp && addr && strcmp(disp, addr) == 0)
+					disp = 0;
+				if (disp && addr) {
+					char dispdec[1024];
+					blaze822_decode_rfc2047(dispdec, disp,
+					    sizeof dispdec - 1, "UTF-8");
+					dispdec[sizeof dispdec - 1] = 0;
+
+					printf("%s <%s>\n", dispdec, addr);
+				} else if (addr) {
+					printf("%s\n", addr);
+				}
+			}
+		}
+		if (n) {
+			*n = ':';
+			h = n + 1;
+		} else {
+			break;
+		}
+	}
+}
+
+int
+main(int argc, char *argv[])
+{
+        int c;
+        while ((c = getopt(argc, argv, "h:")) != -1)
+                switch(c) {
+                case 'h': hflag = optarg; break;
+                default:
+                        // XXX usage
+                        exit(1);
+                }			
+
+        if (argc == optind && isatty(0))
+                blaze822_loop1(":", addr);
+        else
+		blaze822_loop(argc-optind, argv+optind, addr);
+
+        return 0;
+}
diff --git a/man/maddr.1 b/man/maddr.1
new file mode 100644
index 0000000..71dd41d
--- /dev/null
+++ b/man/maddr.1
@@ -0,0 +1,60 @@
+.Dd July 22, 2016
+.Dt MADDR 1
+.Os
+.Sh NAME
+.Nm maddr
+.Nd show mail addresses in messages
+.Sh SYNOPSIS
+.Nm
+.Op Fl h Ar headers
+.Op Ar msgs\ ...
+.Sh DESCRIPTION
+.Nm
+prints all mail addresses mentioned in the
+.Ar headers
+of the given
+.Ar msgs ,
+line by line.
+See
+.Xr mmsg 7
+for the message argument syntax.
+.Pp
+If no
+.Ar msgs
+are passed,
+and
+.Nm
+is used interactively,
+.Nm
+will default to the current sequence.
+Else,
+.Nm
+will read filenames from standard input.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl h Ar headers
+Only search the colon-seperated list of
+.Ar headers
+for mail addresses.
+Default:
+.Sq Li from:sender:reply-to:to:cc:bcc:
+and the same with
+.Sq Li resent- .
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr mmsg 7
+.Sh AUTHORS
+.An Christian Neukirchen Aq Mt chneukirchen@gmail.com
+.Sh LICENSE
+.Nm
+is in the public domain.
+.Pp
+To the extent possible under law,
+the creator of this work
+has waived all copyright and related or
+neighboring rights to this work.
+.Pp
+.Lk http://creativecommons.org/publicdomain/zero/1.0/
diff --git a/man/mmsg.7 b/man/mmsg.7
index 3ee4d47..a6ff28e 100644
--- a/man/mmsg.7
+++ b/man/mmsg.7
@@ -7,6 +7,7 @@
 .Sh DESCRIPTION
 This manpage documents the message syntax used
 by the tools
+.Xr maddr 1 ,
 .Xr mflag 1 ,
 .Xr mhdr 1 ,
 .Xr mless 1 ,