document distributed with 4.2BSD
[unix-history] / usr / src / usr.bin / mail / cmd3.c
index 3f1d112..2aa78a6 100644 (file)
@@ -1,4 +1,12 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)cmd3.c      5.3 (Berkeley) %G%";
+#endif not lint
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -9,8 +17,6 @@
  * Still more user commands.
  */
 
  * Still more user commands.
  */
 
-static char *SccsId = "@(#)cmd3.c      2.9 %G%";
-
 /*
  * Process a shell escape by saving signals, ignoring signals,
  * and forking a sh -c
 /*
  * Process a shell escape by saving signals, ignoring signals,
  * and forking a sh -c
@@ -37,7 +43,7 @@ shell(str)
                for (t = 2; t < 4; t++)
                        if (sig[t-2] != SIG_IGN)
                                sigsys(t, SIG_DFL);
                for (t = 2; t < 4; t++)
                        if (sig[t-2] != SIG_IGN)
                                sigsys(t, SIG_DFL);
-               execl(Shell, Shell, "-c", cmd, 0);
+               execl(Shell, Shell, "-c", cmd, (char *)0);
                perror(Shell);
                _exit(1);
        }
                perror(Shell);
                _exit(1);
        }
@@ -71,7 +77,7 @@ dosh(str)
                for (t = 2; t < 4; t++)
                        if (sig[t-2] != SIG_IGN)
                                sigsys(t, SIG_DFL);
                for (t = 2; t < 4; t++)
                        if (sig[t-2] != SIG_IGN)
                                sigsys(t, SIG_DFL);
-               execl(Shell, Shell, 0);
+               execl(Shell, Shell, (char *)0);
                perror(Shell);
                _exit(1);
        }
                perror(Shell);
                _exit(1);
        }
@@ -149,7 +155,7 @@ help()
        register FILE *f;
 
        if ((f = fopen(HELPFILE, "r")) == NULL) {
        register FILE *f;
 
        if ((f = fopen(HELPFILE, "r")) == NULL) {
-               printf("No help just now.\n");
+               perror(HELPFILE);
                return(1);
        }
        while ((c = getc(f)) != EOF)
                return(1);
        }
        while ((c = getc(f)) != EOF)
@@ -181,19 +187,28 @@ schdir(str)
        return(0);
 }
 
        return(0);
 }
 
+respond(msgvec)
+       int *msgvec;
+{
+       if (value("Replyall") == NOSTR)
+               return (_respond(msgvec));
+       else
+               return (_Respond(msgvec));
+}
+
 /*
  * Reply to a list of messages.  Extract each name from the
  * message header and send them off to mail1()
  */
 
 /*
  * Reply to a list of messages.  Extract each name from the
  * message header and send them off to mail1()
  */
 
-respond(msgvec)
+_respond(msgvec)
        int *msgvec;
 {
        struct message *mp;
        int *msgvec;
 {
        struct message *mp;
-       char *cp, buf[2 * LINESIZE], *rcv, *replyto, **ap;
+       char *cp, *cp2, *cp3, *rcv, *replyto;
+       char buf[2 * LINESIZE], **ap;
        struct name *np;
        struct header head;
        struct name *np;
        struct header head;
-       char *netmap();
 
        if (msgvec[1] != 0) {
                printf("Sorry, can't reply to multiple messages at once\n");
 
        if (msgvec[1] != 0) {
                printf("Sorry, can't reply to multiple messages at once\n");
@@ -201,13 +216,19 @@ respond(msgvec)
        }
        mp = &message[msgvec[0] - 1];
        dot = mp;
        }
        mp = &message[msgvec[0] - 1];
        dot = mp;
-       rcv = nameof(mp, 1);
+       rcv = NOSTR;
+       cp = skin(nameof(mp, 1));
+       if (cp != NOSTR)
+           rcv = cp;
+       cp = skin(hfield("from", mp));
+       if (cp != NOSTR)
+           rcv = cp;
        replyto = skin(hfield("reply-to", mp));
        strcpy(buf, "");
        if (replyto != NOSTR)
                strcpy(buf, replyto);
        else {
        replyto = skin(hfield("reply-to", mp));
        strcpy(buf, "");
        if (replyto != NOSTR)
                strcpy(buf, replyto);
        else {
-               cp = hfield("to", mp);
+               cp = skin(hfield("to", mp));
                if (cp != NOSTR)
                        strcpy(buf, cp);
        }
                if (cp != NOSTR)
                        strcpy(buf, cp);
        }
@@ -218,10 +239,10 @@ respond(msgvec)
         * Delete my name from the reply list,
         * and with it, all my alternate names.
         */
         * Delete my name from the reply list,
         * and with it, all my alternate names.
         */
-       np = delname(np, myname);
-       if (altnames != 0)
+       np = delname(np, myname, icequal);
+       if (altnames)
                for (ap = altnames; *ap; ap++)
                for (ap = altnames; *ap; ap++)
-                       np = delname(np, *ap);
+                       np = delname(np, *ap, icequal);
        head.h_seq = 1;
        cp = detract(np, 0);
        if (cp != NOSTR && replyto == NOSTR) {
        head.h_seq = 1;
        cp = detract(np, 0);
        if (cp != NOSTR && replyto == NOSTR) {
@@ -248,10 +269,10 @@ respond(msgvec)
                if (cp != NOSTR) {
                        np = elide(extract(cp, GCC));
                        mapf(np, rcv);
                if (cp != NOSTR) {
                        np = elide(extract(cp, GCC));
                        mapf(np, rcv);
-                       np = delname(np, myname);
+                       np = delname(np, myname, icequal);
                        if (altnames != 0)
                                for (ap = altnames; *ap; ap++)
                        if (altnames != 0)
                                for (ap = altnames; *ap; ap++)
-                                       np = delname(np, *ap);
+                                       np = delname(np, *ap, icequal);
                        head.h_cc = detract(np, 0);
                }
        }
                        head.h_cc = detract(np, 0);
                }
        }
@@ -308,6 +329,22 @@ preserve(msgvec)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Mark all given messages as unread.
+ */
+unread(msgvec)
+       int     msgvec[];
+{
+       register int *ip;
+
+       for (ip = msgvec; *ip != NULL; ip++) {
+               dot = &message[*ip-1];
+               dot->m_flag &= ~(MREAD|MTOUCH);
+               dot->m_flag |= MSTATUS;
+       }
+       return(0);
+}
+
 /*
  * Print the size of each message.
  */
 /*
  * Print the size of each message.
  */
@@ -321,7 +358,7 @@ messize(msgvec)
        for (ip = msgvec; *ip != NULL; ip++) {
                mesg = *ip;
                mp = &message[mesg-1];
        for (ip = msgvec; *ip != NULL; ip++) {
                mesg = *ip;
                mp = &message[mesg-1];
-               printf("%d: %ld\n", mesg, mp->m_size);
+               printf("%d: %d/%ld\n", mesg, mp->m_lines, mp->m_size);
        }
        return(0);
 }
        }
        return(0);
 }
@@ -556,7 +593,7 @@ file(argv)
                perror(cp);
                return(-1);
        }
                perror(cp);
                return(-1);
        }
-       newfileinfo();
+       announce(0);
 }
 
 /*
 }
 
 /*
@@ -650,24 +687,36 @@ echo(argv)
        return(0);
 }
 
        return(0);
 }
 
+Respond(msgvec)
+       int *msgvec;
+{
+       if (value("Replyall") == NOSTR)
+               return (_Respond(msgvec));
+       else
+               return (_respond(msgvec));
+}
+
 /*
  * Reply to a series of messages by simply mailing to the senders
  * and not messing around with the To: and Cc: lists as in normal
  * reply.
  */
 
 /*
  * Reply to a series of messages by simply mailing to the senders
  * and not messing around with the To: and Cc: lists as in normal
  * reply.
  */
 
-Respond(msgvec)
+_Respond(msgvec)
        int msgvec[];
 {
        struct header head;
        struct message *mp;
        int msgvec[];
 {
        struct header head;
        struct message *mp;
-       register int s, *ap;
-       register char *cp, *subject;
+       register int i, s, *ap;
+       register char *cp, *cp2, *subject;
 
        for (s = 0, ap = msgvec; *ap != 0; ap++) {
                mp = &message[*ap - 1];
                dot = mp;
 
        for (s = 0, ap = msgvec; *ap != 0; ap++) {
                mp = &message[*ap - 1];
                dot = mp;
-               s += strlen(nameof(mp, 2)) + 1;
+               if ((cp = skin(hfield("from", mp))) != NOSTR)
+                   s+= strlen(cp) + 1;
+               else
+                   s += strlen(skin(nameof(mp, 2))) + 1;
        }
        if (s == 0)
                return(0);
        }
        if (s == 0)
                return(0);
@@ -675,7 +724,9 @@ Respond(msgvec)
        head.h_to = cp;
        for (ap = msgvec; *ap != 0; ap++) {
                mp = &message[*ap - 1];
        head.h_to = cp;
        for (ap = msgvec; *ap != 0; ap++) {
                mp = &message[*ap - 1];
-               cp = copy(nameof(mp, 2), cp);
+               if ((cp2 = skin(hfield("from", mp))) == NOSTR)
+                   cp2 = skin(nameof(mp, 2));
+               cp = copy(cp2, cp);
                *cp++ = ' ';
        }
        *--cp = 0;
                *cp++ = ' ';
        }
        *--cp = 0;