Github messages for mblaze
 help / color / mirror / Atom feed
* [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used
@ 2021-01-29 14:21 therealfun
  2021-02-04 11:45 ` leahneukirchen
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: therealfun @ 2021-01-29 14:21 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 494 bytes --]

There is a new pull request by therealfun against master on the mblaze repository

https://github.com/therealfun/mblaze magrep-invert
https://github.com/leahneukirchen/mblaze/pull/201

Match messages without a specific header when "mgrep -v header:match" is used
My main usage is to pipe messages through `mlist ... |magrep -v to:addr |magrep -v cc:addr`.

I'm not sure the patch is complete, but still...

A patch file from https://github.com/leahneukirchen/mblaze/pull/201.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-magrep-invert-201.patch --]
[-- Type: text/x-diff, Size: 2354 bytes --]

From 0d60e9751433e3416d6c63c22c3f2f4a44895a89 Mon Sep 17 00:00:00 2001
From: therealfun <therealfun@users.noreply.github.com>
Date: Fri, 29 Jan 2021 14:12:05 +0000
Subject: [PATCH 1/2] magrep: catch missing headers with -v

While "magrep cc:address" shows the matching messages having "address" in the CC header, "magrep -v cc:address" should show not only the messages not having "address" in the CC header, but those not having the CC header too.
---
 magrep.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/magrep.c b/magrep.c
index 72ce1bb..3faec90 100644
--- a/magrep.c
+++ b/magrep.c
@@ -37,7 +37,7 @@ match(char *file, char *hdr, char *s)
 		regmatch_t pmatch = {0};
 		int len, matched;
 		matched = 0;
-		while (*s && regexec(&pattern, s, 1, &pmatch, 0) == 0) {
+		while (s && *s && regexec(&pattern, s, 1, &pmatch, 0) == 0) {
 			s += pmatch.rm_so;
 			if (!(len = pmatch.rm_eo-pmatch.rm_so)) {
 				s += 1;
@@ -52,7 +52,7 @@ match(char *file, char *hdr, char *s)
 			matched++;
 		}
 		return (matched && matches++);
-	} else if (vflag ^ (regexec(&pattern, s, 0, 0, 0) == 0)) {
+	} else if (vflag ^ (s && regexec(&pattern, s, 0, 0, 0) == 0)) {
 		if (qflag)
 			exit(0);
 		matches++;
@@ -183,6 +183,8 @@ magrep(char *file)
 		char *v = blaze822_chdr(msg, header);
 		if (v)
 			(void)match_value(file, header, v);
+		else
+			(void)match(file, header, 0);
 	}
 
 	blaze822_free(msg);

From 3a8555b2a656f977742ebfcb42c904844c63499e Mon Sep 17 00:00:00 2001
From: therealfun <therealfun@users.noreply.github.com>
Date: Fri, 29 Jan 2021 14:15:05 +0000
Subject: [PATCH 2/2] t/3000-magrep.t: add test to catch missing header with -v

---
 t/3000-magrep.t | 1 +
 1 file changed, 1 insertion(+)

diff --git a/t/3000-magrep.t b/t/3000-magrep.t
index f20cbb6..e54ba86 100644
--- a/t/3000-magrep.t
+++ b/t/3000-magrep.t
@@ -175,6 +175,7 @@ export MAILSEQ=seq
 check_test 'subject' -eq 1 'magrep subject:nice : | wc -l'
 check_test 'ignorecase' -eq 1 'magrep -i subject:NICE : | wc -l'
 check_test 'invert' -eq 2 'magrep -v subject:nice : | wc -l'
+check_test 'invert missing' -eq 1 'magrep -v subject:i : | wc -l'
 check_test 'max matches' -eq 2 'magrep -m 2 from:Piet : | wc -l'
 check_test 'long subject' -eq 1 'magrep subject:aliqua : | wc -l'
 check_test 'decode large rfc2047 header' -eq 1 'magrep -d to:John : | wc -l'

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-02-04 17:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
2021-02-04 11:45 ` leahneukirchen
2021-02-04 11:46 ` [PR REVIEW] " leahneukirchen
2021-02-04 11:48 ` leahneukirchen
2021-02-04 11:49 ` leahneukirchen
2021-02-04 14:01 ` therealfun
2021-02-04 14:18 ` therealfun
2021-02-04 14:19 ` therealfun
2021-02-04 14:54 ` Duncaen
2021-02-04 17:31 ` therealfun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).