Add support for the special case of searchheaders,
authorDave A. Borman <dab@ucbvax.Berkeley.EDU>
Fri, 21 Apr 1995 01:39:26 +0000 (17:39 -0800)
committerDave A. Borman <dab@ucbvax.Berkeley.EDU>
Fri, 21 Apr 1995 01:39:26 +0000 (17:39 -0800)
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
usr/src/usr.bin/mail/mail.1

index b59d6a0..fe96a90 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #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"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -644,6 +644,46 @@ matchsender(str, mesg)
        return(*cp == 0);
 }
 
        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.
 /*
  * 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, ':'))) {
         */
 
        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] = ':';
                *cp++ = '\0';
                cp2 = hfield(str, mp);
                cp[-1] = ':';
index fe1c4f6..071ca41 100644 (file)
@@ -3,7 +3,7 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"    @(#)mail.1      8.5 (Berkeley) %G%
+.\"    @(#)mail.1      8.6 (Berkeley) %G%
 .\"
 .Dd 
 .Dt MAIL 1
 .\"
 .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.
 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
 .It Ar verbose
 Setting the option
 .Ar verbose