From 0d60e9751433e3416d6c63c22c3f2f4a44895a89 Mon Sep 17 00:00:00 2001 From: therealfun 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 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'