summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--magrep.c15
-rw-r--r--man/magrep.18
2 files changed, 17 insertions, 6 deletions
diff --git a/magrep.c b/magrep.c
index 83e1c49..44ef548 100644
--- a/magrep.c
+++ b/magrep.c
@@ -14,6 +14,7 @@
 static int aflag;
 static int cflag;
 static int dflag;
+static int hflag;
 static int iflag;
 static int lflag;
 static int oflag;
@@ -42,6 +43,8 @@ match(char *file, char *hdr, char *s)
 			}
 			if (pflag)
 				printf("%s: %s: ", file, hdr);
+			else if (hflag)
+				printf("%s: ", hdr);
 			printf("%.*s\n", len, s);
 			s += len;
 			matched++;
@@ -52,9 +55,12 @@ match(char *file, char *hdr, char *s)
 			exit(0);
 		matches++;
 		if (!cflag) {
-			printf("%s", file);
+			if (vflag || !hflag)
+				printf("%s", file);
 			if (pflag && !vflag)
 				printf(": %s: %s", hdr, s);
+			else if (hflag && !vflag)
+				printf("%s: %s", hdr, s);
 			putchar('\n');
 		}
 		if (mflag && matches >= mflag)
@@ -82,7 +88,7 @@ match_part(int depth, struct message *msg, char *body, size_t bodylen)
 		    strcasecmp(charset, "utf-8") == 0 ||
 		    strcasecmp(charset, "utf8") == 0 ||
 		    strcasecmp(charset, "us-ascii") == 0) {
-			if (pflag && !cflag && !oflag && !vflag) {
+			if ((hflag || pflag) && !cflag && !oflag && !vflag) {
 				char *s, *p;
 				for (p = s = body; p < body+bodylen+1; p++) {
 					if (*p == '\r' || *p == '\n') {
@@ -183,11 +189,12 @@ int
 main(int argc, char *argv[])
 {
 	int c;
-	while ((c = getopt(argc, argv, "acdilm:opqv")) != -1)
+	while ((c = getopt(argc, argv, "acdhilm:opqv")) != -1)
 		switch (c) {
 		case 'a': aflag = 1; break;
 		case 'c': cflag = 1; break;
 		case 'd': dflag = 1; break;
+		case 'h': hflag = 1; break;
 		case 'i': iflag = REG_ICASE; break;
 		case 'l': lflag = 1; break;
 		case 'm': mflag = atol(optarg); break;
@@ -198,7 +205,7 @@ main(int argc, char *argv[])
 		default:
 usage:
 			fprintf(stderr,
-"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
+"Usage: magrep [-c|-h|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
 			exit(2);
 		}
 
diff --git a/man/magrep.1 b/man/magrep.1
index 4cb7985..313244d 100644
--- a/man/magrep.1
+++ b/man/magrep.1
@@ -1,4 +1,4 @@
-.Dd July 7, 2018
+.Dd September 10, 2018
 .Dt MAGREP 1
 .Os
 .Sh NAME
@@ -6,7 +6,7 @@
 .Nd search messages matching a pattern
 .Sh SYNOPSIS
 .Nm
-.Op Fl c | Fl q | Fl m Ar max
+.Op Fl c | Fl h | Fl o | Fl p | Fl q | Fl m Ar max
 .Op Fl v
 .Op Fl i
 .Op Fl l
@@ -75,6 +75,10 @@ count non-matching headers instead.
 Decode the
 .Ar header
 according to RFC 2047 prior to searching.
+.It Fl h
+Like
+.Fl p
+but do not print the file name.
 .It Fl i
 Match
 .Ar regex