mirror of
https://github.com/leahneukirchen/mblaze
synced 2024-11-11 13:10:32 +00:00
magrep: add -l flag
This commit is contained in:
parent
817a111909
commit
57b6afb019
22
magrep.c
22
magrep.c
@ -15,6 +15,7 @@ static int aflag;
|
||||
static int cflag;
|
||||
static int dflag;
|
||||
static int iflag;
|
||||
static int lflag;
|
||||
static int oflag;
|
||||
static int pflag;
|
||||
static int qflag;
|
||||
@ -29,7 +30,7 @@ static char *curfile;
|
||||
int
|
||||
match(char *file, char *hdr, char *s)
|
||||
{
|
||||
if (oflag && !cflag && !qflag && !vflag) {
|
||||
if (oflag && !cflag && !qflag && !vflag && !lflag) {
|
||||
regmatch_t pmatch;
|
||||
int len, matched;
|
||||
matched = 0;
|
||||
@ -118,22 +119,23 @@ match_body(char *file)
|
||||
blaze822_walk_mime(msg, 0, match_part);
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
match_value(char *file, char *h, char *v)
|
||||
{
|
||||
if (dflag) {
|
||||
char d[4096];
|
||||
blaze822_decode_rfc2047(d, v, sizeof d, "UTF-8");
|
||||
match(file, h, d);
|
||||
return match(file, h, d);
|
||||
} else if (aflag) {
|
||||
char *disp, *addr;
|
||||
while ((v = blaze822_addr(v, &disp, &addr))) {
|
||||
if (addr && match(file, h, addr))
|
||||
break;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
match(file, h, v);
|
||||
return match(file, h, v);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -163,14 +165,15 @@ magrep(char *file)
|
||||
char *v = strchr(hdr, ':');
|
||||
if (v) {
|
||||
*v = 0;
|
||||
match_value(file, hdr, v + 1 + (v[1] == ' '));
|
||||
if (match_value(file, hdr, v + 1 + (v[1] == ' ')) && lflag)
|
||||
break;
|
||||
*v = ':';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
char *v = blaze822_chdr(msg, header);
|
||||
if (v)
|
||||
match_value(file, header, v);
|
||||
(void)match_value(file, header, v);
|
||||
}
|
||||
|
||||
blaze822_free(msg);
|
||||
@ -180,12 +183,13 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
while ((c = getopt(argc, argv, "acdim:opqv")) != -1)
|
||||
while ((c = getopt(argc, argv, "acdilm:opqv")) != -1)
|
||||
switch (c) {
|
||||
case 'a': aflag = 1; break;
|
||||
case 'c': cflag = 1; break;
|
||||
case 'd': dflag = 1; break;
|
||||
case 'i': iflag = REG_ICASE; break;
|
||||
case 'l': lflag = 1; break;
|
||||
case 'm': mflag = atol(optarg); break;
|
||||
case 'o': oflag = 1; break;
|
||||
case 'p': pflag = 1; break;
|
||||
@ -194,7 +198,7 @@ main(int argc, char *argv[])
|
||||
default:
|
||||
usage:
|
||||
fprintf(stderr,
|
||||
"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-a|-d] header:regex [msgs...]\n");
|
||||
"Usage: magrep [-c|-o|-p|-q|-m max] [-v] [-i] [-l] [-a|-d] header:regex [msgs...]\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
.Dd February 15, 2017
|
||||
.Dd July 7, 2018
|
||||
.Dt MAGREP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -9,6 +9,7 @@
|
||||
.Op Fl c | Fl q | Fl m Ar max
|
||||
.Op Fl v
|
||||
.Op Fl i
|
||||
.Op Fl l
|
||||
.Op Fl a | Fl d
|
||||
.Ar header Ns Cm \&: Ns Ar regex
|
||||
.Op Ar msgs\ ...
|
||||
@ -78,6 +79,8 @@ according to RFC 2047 prior to searching.
|
||||
Match
|
||||
.Ar regex
|
||||
case insensitively.
|
||||
.It Fl l
|
||||
Only search a message until a match has been found.
|
||||
.It Fl m Ar max
|
||||
Do not show more than
|
||||
.Ar max
|
||||
|
Loading…
Reference in New Issue
Block a user