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

* Re: Match messages without a specific header when "mgrep -v header:match" is used
  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
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: leahneukirchen @ 2021-02-04 11:45 UTC (permalink / raw)
  To: ml

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

New comment by leahneukirchen on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#issuecomment-773247203

Comment:
I need to think about whether this is a good semantics change.

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

* Re: [PR REVIEW] Match messages without a specific header when "mgrep -v header:match" is used
  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 ` leahneukirchen
  2021-02-04 11:48 ` leahneukirchen
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: leahneukirchen @ 2021-02-04 11:46 UTC (permalink / raw)
  To: ml

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

New review comment by leahneukirchen on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#discussion_r570160740

Comment:
This is inside a !vflag if, so not needed right?

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

* Re: [PR REVIEW] Match messages without a specific header when "mgrep -v header:match" is used
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: leahneukirchen @ 2021-02-04 11:48 UTC (permalink / raw)
  To: ml

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

New review comment by leahneukirchen on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#discussion_r570161387

Comment:
would "else if (vflag) printf..." not be easier here?

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

* Re: [PR REVIEW] Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (2 preceding siblings ...)
  2021-02-04 11:48 ` leahneukirchen
@ 2021-02-04 11:49 ` leahneukirchen
  2021-02-04 14:01 ` therealfun
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: leahneukirchen @ 2021-02-04 11:49 UTC (permalink / raw)
  To: ml

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

New review comment by leahneukirchen on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#discussion_r570162019

Comment:
aha but then we have duplicate logic for cflag etc.

We need more test cases for this.

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

* Re: [PR REVIEW] Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (3 preceding siblings ...)
  2021-02-04 11:49 ` leahneukirchen
@ 2021-02-04 14:01 ` therealfun
  2021-02-04 14:18 ` therealfun
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: therealfun @ 2021-02-04 14:01 UTC (permalink / raw)
  To: ml

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

New review comment by therealfun on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#discussion_r570245351

Comment:
Right! This is the point where it will exit if the header is not found.
Without pondering much, it was easier to reach `match()` where the magic happens (see the check on `s`).


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

* Re: Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (4 preceding siblings ...)
  2021-02-04 14:01 ` therealfun
@ 2021-02-04 14:18 ` therealfun
  2021-02-04 14:19 ` therealfun
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: therealfun @ 2021-02-04 14:18 UTC (permalink / raw)
  To: ml

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

New comment by therealfun on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#issuecomment-773339502

Comment:
Maybe because I'm new to mblaze, I think I'll be fine without `magrep` when I search headers. Extracting the headers with `mhdr`, prefixed with the filename (-H), and piping through `|grep | awk'{print $1}'|sort -u`.


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

* Re: Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (5 preceding siblings ...)
  2021-02-04 14:18 ` therealfun
@ 2021-02-04 14:19 ` therealfun
  2021-02-04 14:54 ` Duncaen
  2021-02-04 17:31 ` therealfun
  8 siblings, 0 replies; 10+ messages in thread
From: therealfun @ 2021-02-04 14:19 UTC (permalink / raw)
  To: ml

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

New comment by therealfun on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#issuecomment-773339502

Comment:
Maybe because I'm new to mblaze, I think I'll be fine without `magrep` when I search headers. Extracting the headers with `mhdr`, prefixed with the filename (-H), and piping through `|grep | awk'{print $1}'|sort -u` should be enough. 


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

* Re: Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (6 preceding siblings ...)
  2021-02-04 14:19 ` therealfun
@ 2021-02-04 14:54 ` Duncaen
  2021-02-04 17:31 ` therealfun
  8 siblings, 0 replies; 10+ messages in thread
From: Duncaen @ 2021-02-04 14:54 UTC (permalink / raw)
  To: ml

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

New comment by Duncaen on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#issuecomment-773369078

Comment:
If you need even more complex searches, `mpick` would also be an alternative.

    mpick -t '"to".addr != "mail@duncano.de" && "cc".addr != "mail@duncano.de"'

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

* Re: Match messages without a specific header when "mgrep -v header:match" is used
  2021-01-29 14:21 [PR PATCH] Match messages without a specific header when "mgrep -v header:match" is used therealfun
                   ` (7 preceding siblings ...)
  2021-02-04 14:54 ` Duncaen
@ 2021-02-04 17:31 ` therealfun
  8 siblings, 0 replies; 10+ messages in thread
From: therealfun @ 2021-02-04 17:31 UTC (permalink / raw)
  To: ml

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

New comment by therealfun on mblaze repository

https://github.com/leahneukirchen/mblaze/pull/201#issuecomment-773480308

Comment:
> I need to think about whether this is a good semantics change.

It was surprising for me to find that `magrep -v header:pattern` doesn't match messages if that header is missing. If this was your intention, maybe you should leave it as it is.
I see that I have at least two methods for my use-case :)

^ 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).