[-- 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'
[-- 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.
[-- 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?
[-- 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?
[-- 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.
[-- 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`).
[-- 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`.
[-- 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.
[-- 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"'
[-- 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 :)