magrep: add search in body

pull/2/head
Christian Neukirchen 8 years ago
parent 27b21d7e20
commit b451fe788b

@ -5,7 +5,7 @@ ALL = maddr magrep mdeliver mdirs mflag mgenmid mhdr minc mlist mmime mpick msca
all: $(ALL)
maddr: maddr.o blaze822.o seq.o rfc2047.o mymemmem.o
magrep: magrep.o blaze822.o seq.o rfc2047.o mymemmem.o
magrep: magrep.o blaze822.o seq.o rfc2045.o rfc2047.o mymemmem.o
mdeliver: mdeliver.o blaze822.o mymemmem.o
mdirs: mdirs.o
mflag: mflag.o blaze822.o seq.o mymemmem.o

@ -21,6 +21,7 @@ static long matches;
static regex_t pattern;
static char *header;
static char *curfile;
int
match(char *file, char *s)
@ -37,6 +38,49 @@ match(char *file, char *s)
return 0;
}
blaze822_mime_action
match_part(int depth, struct message *msg, char *body, size_t bodylen)
{
(void) depth;
char *ct = blaze822_hdr(msg, "content-type");
blaze822_mime_action r = MIME_CONTINUE;
if (!ct || strncmp(ct, "text/plain", 10) == 0) {
char *charset = 0, *cs, *cse;
if (blaze822_mime_parameter(ct, "charset", &cs, &cse))
charset = strndup(cs, cse-cs);
if (!charset ||
strcasecmp(charset, "utf-8") == 0 ||
strcasecmp(charset, "utf8") == 0 ||
strcasecmp(charset, "us-ascii") == 0) {
(void) bodylen; /* XXX */
if (match(curfile, body))
r = MIME_STOP;
} else {
/* XXX decode here */
}
free(charset);
}
return r;
}
void
match_body(char *file)
{
curfile = file;
while (*curfile == ' ' || *curfile == '\t')
curfile++;
struct message *msg = blaze822_file(curfile);
if (!msg)
return;
blaze822_walk_mime(msg, 0, match_part);
}
void
magrep(char *file)
{
@ -45,6 +89,9 @@ magrep(char *file)
if (flags)
match(file, flags+3);
return;
} else if (strcmp(header, "/") == 0) {
match_body(file);
return;
}
char *filename = file;

@ -20,12 +20,22 @@ where the value of
.Ar header
matches the POSIX Extended Regular Expression
.Ar regex .
.Pp
If
.Ar header
is empty,
.Nm
will instead match against the Maildir flags of the messages.
.Pp
If
.Ar header
is
.Sq Li "/" ,
.Nm
will instead match inside the text parts of the
.Em body
of the messages.
.Pp
See
.Xr mmsg 7
for the message argument syntax.

Loading…
Cancel
Save