Github messages for mblaze
 help / color / mirror / Atom feed
From: therealfun <therealfun@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used
Date: Fri, 29 Jan 2021 15:21:24 +0100	[thread overview]
Message-ID: <gh-mailinglist-notifications-fa6558a0-26e0-48f6-803f-f5a8af34f6a8-mblaze-201@inbox.vuxu.org> (raw)

[-- 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'

             reply	other threads:[~2021-01-29 14:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29 14:21 therealfun [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=gh-mailinglist-notifications-fa6558a0-26e0-48f6-803f-f5a8af34f6a8-mblaze-201@inbox.vuxu.org \
    --to=therealfun@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).