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.
pull/201/head
therealfun 3 years ago committed by GitHub
parent ff7537f6a7
commit 0d60e97514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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);

Loading…
Cancel
Save