From bdc0d8cc842348a6ee6143bbf0159ce7a94039f8 Mon Sep 17 00:00:00 2001 From: "Dave A. Borman" Date: Thu, 20 Apr 1995 17:39:26 -0800 Subject: [PATCH] Add support for the special case of searchheaders, so that ``/To:y'' will search for the field ``y'' in not just the ``To'' field, but also in the ``Cc'' and ``Bcc'' fields. SCCS-vsn: usr.bin/mail/list.c 8.3 SCCS-vsn: usr.bin/mail/mail.1 8.6 --- usr/src/usr.bin/mail/list.c | 46 ++++++++++++++++++++++++++++++++++++- usr/src/usr.bin/mail/mail.1 | 5 +++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/usr/src/usr.bin/mail/list.c b/usr/src/usr.bin/mail/list.c index b59d6a0857..fe96a90825 100644 --- a/usr/src/usr.bin/mail/list.c +++ b/usr/src/usr.bin/mail/list.c @@ -6,7 +6,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)list.c 8.2 (Berkeley) %G%"; +static char sccsid[] = "@(#)list.c 8.3 (Berkeley) %G%"; #endif /* not lint */ #include "rcv.h" @@ -644,6 +644,46 @@ matchsender(str, mesg) return(*cp == 0); } +/* + * See if the passed name received the passed message number. Return true + * if so. + */ + +static char *to_fields[] = { "to", "cc", "bcc", 0 }; + +matchto(str, mesg) + char *str; +{ + register struct message *mp; + register char *cp, *cp2, *backup, **to; + + str++; + + if (*str == 0) /* null string matches nothing instead of everything */ + return(0); + + mp = &message[mesg-1]; + + for (to = to_fields; *to; to++) { + cp = str; + cp2 = hfield(*to, mp); + if (cp2 != NOSTR) { + backup = cp2; + while (*cp2) { + if (*cp == 0) + return(1); + if (raise(*cp++) != raise(*cp2++)) { + cp2 = ++backup; + cp = str; + } + } + if (*cp == 0) + return(1); + } + } + return(0); +} + /* * See if the given string matches inside the subject field of the * given message. For the purpose of the scan, we ignore case differences. @@ -673,6 +713,10 @@ matchsubj(str, mesg) */ if (value("searchheaders") && (cp = index(str, ':'))) { + /* Check for special case "/To:" */ + if (raise(str[0]) == 'T' && raise(str[1]) == 'O' && + str[2] == ':') + return(matchto(cp, mesg)); *cp++ = '\0'; cp2 = hfield(str, mp); cp[-1] = ':'; diff --git a/usr/src/usr.bin/mail/mail.1 b/usr/src/usr.bin/mail/mail.1 index fe1c4f6c37..071ca41cda 100644 --- a/usr/src/usr.bin/mail/mail.1 +++ b/usr/src/usr.bin/mail/mail.1 @@ -3,7 +3,7 @@ .\" .\" %sccs.include.redist.roff% .\" -.\" @(#)mail.1 8.5 (Berkeley) %G% +.\" @(#)mail.1 8.6 (Berkeley) %G% .\" .Dd .Dt MAIL 1 @@ -873,6 +873,9 @@ Suppresses the printing of the version when first invoked. If this option is set, then a message-list specifier in the form ``/x:y'' will expand to all messages containing the substring ``y'' in the header field ``x''. The string search is case insensitive. +The form ``/To:y'' is a special case, and will expand +to all messages containing the substring ``y'' in the ``To'', ``Cc'' +or ``Bcc'' header fields. .It Ar verbose Setting the option .Ar verbose -- 2.20.1