added -c -b -t flags, end echo with newline,
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 11 Jun 1988 16:15:56 +0000 (08:15 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 11 Jun 1988 16:15:56 +0000 (08:15 -0800)
from Tom Newcomb (newcomb@arpa)

SCCS-vsn: usr.bin/mail/lex.c 5.9
SCCS-vsn: usr.bin/mail/send.c 5.7
SCCS-vsn: usr.bin/mail/cmd3.c 5.6
SCCS-vsn: usr.bin/mail/main.c 5.6
SCCS-vsn: usr.bin/mail/def.h 5.7

usr/src/usr.bin/mail/cmd3.c
usr/src/usr.bin/mail/def.h
usr/src/usr.bin/mail/lex.c
usr/src/usr.bin/mail/main.c
usr/src/usr.bin/mail/send.c

index 51a4973..8da669b 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #ifdef notdef
  */
 
 #ifdef notdef
-static char sccsid[] = "@(#)cmd3.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd3.c     5.6 (Berkeley) %G%";
 #endif /* notdef */
 
 #include "rcv.h"
 #endif /* notdef */
 
 #include "rcv.h"
@@ -287,6 +287,7 @@ _respond(msgvec)
                }
        }
        head.h_bcc = NOSTR;
                }
        }
        head.h_bcc = NOSTR;
+       head.h_smopts = NOSTR;
        mail1(&head);
        return(0);
 }
        mail1(&head);
        return(0);
 }
@@ -692,9 +693,14 @@ echo(argv)
 
        for (ap = argv; *ap != NOSTR; ap++) {
                cp = *ap;
 
        for (ap = argv; *ap != NOSTR; ap++) {
                cp = *ap;
-               if ((cp = expand(cp)) != NOSTR)
-                       printf("%s ", cp);
+               if ((cp = expand(cp)) != NOSTR) {
+                       if (ap != argv)
+                               putchar(' ');
+                       printf("%s", cp);
+               }
        }
        }
+       putchar('\n');
+
        return(0);
 }
 
        return(0);
 }
 
@@ -751,6 +757,7 @@ _Respond(msgvec)
                head.h_seq++;
        head.h_cc = NOSTR;
        head.h_bcc = NOSTR;
                head.h_seq++;
        head.h_cc = NOSTR;
        head.h_bcc = NOSTR;
+       head.h_smopts = NOSTR;
        mail1(&head);
        return(0);
 }
        mail1(&head);
        return(0);
 }
index b203b77..9e1fa11 100644 (file)
@@ -9,7 +9,7 @@
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  *
  * software without specific prior written permission. This software
  * is provided ``as is'' without express or implied warranty.
  *
- *     @(#)def.h       5.6 (Berkeley) %G%
+ *     @(#)def.h       5.7 (Berkeley) %G%
  */
 
 #include <sys/param.h>         /* includes <sys/types.h> */
  */
 
 #include <sys/param.h>         /* includes <sys/types.h> */
@@ -148,6 +148,7 @@ struct header {
        char    *h_subject;             /* Subject string */
        char    *h_cc;                  /* Carbon copies string */
        char    *h_bcc;                 /* Blind carbon copies */
        char    *h_subject;             /* Subject string */
        char    *h_cc;                  /* Carbon copies string */
        char    *h_bcc;                 /* Blind carbon copies */
+       char    *h_smopts;              /* Sendmail options */
        int     h_seq;                  /* Sequence for optimization */
 };
 
        int     h_seq;                  /* Sequence for optimization */
 };
 
index c15e921..1ed9ca2 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #ifdef notdef
  */
 
 #ifdef notdef
-static char sccsid[] = "@(#)lex.c      5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)lex.c      5.9 (Berkeley) %G%";
 #endif /* notdef */
 
 #include "rcv.h"
 #endif /* notdef */
 
 #include "rcv.h"
@@ -166,7 +166,8 @@ top:
                        printf(prompt);
                }
                fflush(stdout);
                        printf(prompt);
                }
                fflush(stdout);
-               sreset();
+               if (!sourcing)
+                       sreset();
 
                /*
                 * Read a line of commands from the current input
 
                /*
                 * Read a line of commands from the current input
index ca7921d..3a500f6 100644 (file)
@@ -17,7 +17,7 @@ char copyright[] =
 #endif /* notdef */
 
 #ifdef notdef
 #endif /* notdef */
 
 #ifdef notdef
-static char sccsid[] = "@(#)main.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.6 (Berkeley) %G%";
 #endif /* notdef */
 
 #include "rcv.h"
 #endif /* notdef */
 
 #include "rcv.h"
@@ -45,10 +45,13 @@ jmp_buf     hdrjmp;
 main(argc, argv)
        char **argv;
 {
 main(argc, argv)
        char **argv;
 {
-       register char *ef;
-       register int i, argp;
-       int mustsend, hdrstop(), (*prevint)(), f;
+       register char *ef, opt;
+       register int i;
+       struct name *to, *cc, *bcc, *smopts;
+       int  mustsend, hdrstop(), (*prevint)(), f;
        struct sgttyb tbuf;
        struct sgttyb tbuf;
+       extern int getopt(), optind, opterr;
+       extern char *optarg;
 
        /*
         * Set up a reasonable environment.
 
        /*
         * Set up a reasonable environment.
@@ -79,66 +82,41 @@ main(argc, argv)
         */
 
        ef = NOSTR;
         */
 
        ef = NOSTR;
-       argp = -1;
+       to = NULL;
+       cc = NULL;
+       bcc = NULL;
+       smopts = NULL;
        mustsend = 0;
        if (argc > 0 && **argv == 'r')
                rmail++;
        mustsend = 0;
        if (argc > 0 && **argv == 'r')
                rmail++;
-       for (i = 1; i < argc; i++) {
-
-               /*
-                * If current argument is not a flag, then the
-                * rest of the arguments must be recipients.
-                */
-
-               if (*argv[i] != '-') {
-                       argp = i;
-                       break;
-               }
-               switch (argv[i][1]) {
+       while ((opt = getopt(argc, argv, "INT:b:c:dfh:inr:s:u:v")) != EOF) {
+               switch (opt) {
                case 'r':
                        /*
                         * Next argument is address to be sent along
                         * to the mailer.
                         */
                case 'r':
                        /*
                         * Next argument is address to be sent along
                         * to the mailer.
                         */
-                       if (i >= argc - 1) {
-                               fprintf(stderr, "Address required after -r\n");
-                               exit(1);
-                       }
                        mustsend++;
                        mustsend++;
-                       rflag = argv[i+1];
-                       i++;
+                       rflag = optarg;
                        break;
                        break;
-
                case 'T':
                        /*
                         * Next argument is temp file to write which
                         * articles have been read/deleted for netnews.
                         */
                case 'T':
                        /*
                         * Next argument is temp file to write which
                         * articles have been read/deleted for netnews.
                         */
-                       if (i >= argc - 1) {
-                               fprintf(stderr, "Name required after -T\n");
-                               exit(1);
-                       }
-                       Tflag = argv[i+1];
+                       Tflag = optarg;
                        if ((f = creat(Tflag, 0600)) < 0) {
                                perror(Tflag);
                                exit(1);
                        }
                        close(f);
                        if ((f = creat(Tflag, 0600)) < 0) {
                                perror(Tflag);
                                exit(1);
                        }
                        close(f);
-                       i++;
                        break;
                        break;
-
                case 'u':
                        /*
                         * Next argument is person to pretend to be.
                         */
                case 'u':
                        /*
                         * Next argument is person to pretend to be.
                         */
-                       if (i >= argc - 1) {
-                               fprintf(stderr, "Missing user name for -u\n");
-                               exit(1);
-                       }
-                       strcpy(myname, argv[i+1]);
-                       i++;
+                       strcpy(myname, optarg);
                        break;
                        break;
-
                case 'i':
                        /*
                         * User wants to ignore interrupts.
                case 'i':
                        /*
                         * User wants to ignore interrupts.
@@ -146,11 +124,9 @@ main(argc, argv)
                         */
                        assign("ignore", "");
                        break;
                         */
                        assign("ignore", "");
                        break;
-
                case 'd':
                        debug++;
                        break;
                case 'd':
                        debug++;
                        break;
-
                case 'h':
                        /*
                         * Specified sequence number for network.
                case 'h':
                        /*
                         * Specified sequence number for network.
@@ -158,102 +134,107 @@ main(argc, argv)
                         * far (count of times message has been
                         * forwarded) to help avoid infinite mail loops.
                         */
                         * far (count of times message has been
                         * forwarded) to help avoid infinite mail loops.
                         */
-                       if (i >= argc - 1) {
-                               fprintf(stderr, "Number required for -h\n");
-                               exit(1);
-                       }
                        mustsend++;
                        mustsend++;
-                       hflag = atoi(argv[i+1]);
+                       hflag = atoi(optarg);
                        if (hflag == 0) {
                                fprintf(stderr, "-h needs non-zero number\n");
                                exit(1);
                        }
                        if (hflag == 0) {
                                fprintf(stderr, "-h needs non-zero number\n");
                                exit(1);
                        }
-                       i++;
                        break;
                        break;
-
                case 's':
                        /*
                         * Give a subject field for sending from
                         * non terminal
                         */
                case 's':
                        /*
                         * Give a subject field for sending from
                         * non terminal
                         */
-                       if (i >= argc - 1) {
-                               fprintf(stderr, "Subject req'd for -s\n");
-                               exit(1);
-                       }
                        mustsend++;
                        mustsend++;
-                       sflag = argv[i+1];
-                       i++;
+                       sflag = optarg;
                        break;
                        break;
-
                case 'f':
                        /*
                         * User is specifying file to "edit" with Mail,
                         * as opposed to reading system mailbox.
                         * If no argument is given after -f, we read his
                         * mbox file in his home directory.
                case 'f':
                        /*
                         * User is specifying file to "edit" with Mail,
                         * as opposed to reading system mailbox.
                         * If no argument is given after -f, we read his
                         * mbox file in his home directory.
+                        *
+                        * getopt() can't handle optional arguments, so here
+                        * is an ugly hack to get around it.
                         */
                         */
-                       if (i >= argc - 1)
-                               ef = mbox;
+                       if ((argv[optind]) && (argv[optind][0] != '-')) 
+                               ef = argv[optind++];
                        else
                        else
-                               ef = argv[i + 1];
-                       i++;
+                               ef = mbox;
                        break;
                        break;
-
                case 'n':
                        /*
                         * User doesn't want to source /usr/lib/Mail.rc
                         */
                        nosrc++;
                        break;
                case 'n':
                        /*
                         * User doesn't want to source /usr/lib/Mail.rc
                         */
                        nosrc++;
                        break;
-
                case 'N':
                        /*
                         * Avoid initial header printing.
                         */
                        noheader++;
                        break;
                case 'N':
                        /*
                         * Avoid initial header printing.
                         */
                        noheader++;
                        break;
-
                case 'v':
                        /*
                         * Send mailer verbose flag
                         */
                        assign("verbose", "");
                        break;
                case 'v':
                        /*
                         * Send mailer verbose flag
                         */
                        assign("verbose", "");
                        break;
-
                case 'I':
                        /*
                         * We're interactive
                         */
                        intty = 1;
                        break;
                case 'I':
                        /*
                         * We're interactive
                         */
                        intty = 1;
                        break;
-
-               default:
-                       fprintf(stderr, "Unknown flag: %s\n", argv[i]);
+               case 'c':
+                       /*
+                        * Get Carbon Copy Recipient list
+                        */
+                       cc = cat(cc, nalloc(optarg));
+                       mustsend++;
+                       break;
+               case 'b':
+                       /*
+                        * Get Blind Carbon Copy Recipient list
+                        */
+                       bcc = cat(bcc, nalloc(optarg));
+                       mustsend++;
+                       break;
+               case '?':
+                       fputs("Usage: XXX\n", stderr);
                        exit(1);
                }
        }
                        exit(1);
                }
        }
-
+       for (i = optind; (argv[i]) && (*argv[i] != '-'); i++) 
+               to = cat(to, nalloc(argv[i]));
+       for (; argv[i]; i++)
+               smopts = cat(smopts, nalloc(argv[i]));
        /*
         * Check for inconsistent arguments.
         */
        /*
         * Check for inconsistent arguments.
         */
-
-       if (ef != NOSTR && argp != -1) {
+       if (!to && (cc || bcc)) {
+               fputs("You must also specify direct recipients of mail.\n", stderr);
+               exit(1);
+       }
+       if ((ef != NOSTR) && to) {
                fprintf(stderr, "Cannot give -f and people to send to.\n");
                exit(1);
        }
                fprintf(stderr, "Cannot give -f and people to send to.\n");
                exit(1);
        }
-       if (mustsend && argp == -1) {
+       if (mustsend && !to) {
                fprintf(stderr, "The flags you gave make no sense since you're not sending mail.\n");
                exit(1);
        }
        tinit();
        setscreensize();
        input = stdin;
                fprintf(stderr, "The flags you gave make no sense since you're not sending mail.\n");
                exit(1);
        }
        tinit();
        setscreensize();
        input = stdin;
-       rcvmode = argp == -1;
+       rcvmode = !to;
        if (!nosrc)
                load(MASTER);
        load(mailrc);
        if (!nosrc)
                load(MASTER);
        load(mailrc);
-       if (argp != -1) {
-               mail(&argv[argp]);
+       if (!rcvmode) {
+               mail(to, cc, bcc, smopts);
 
                /*
                 * why wait?
 
                /*
                 * why wait?
index 268ff3b..2fc9b3b 100644 (file)
@@ -11,7 +11,7 @@
  */
 
 #ifdef notdef
  */
 
 #ifdef notdef
-static char sccsid[] = "@(#)send.c     5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)send.c     5.7 (Berkeley) %G%";
 #endif /* notdef */
 
 #include "rcv.h"
 #endif /* notdef */
 
 #include "rcv.h"
@@ -183,29 +183,16 @@ statusput(mp, obuf)
  * which does all the dirty work.
  */
 
  * which does all the dirty work.
  */
 
-mail(people)
-       char **people;
+mail(to, cc, bcc, smopts)
+       struct name *to, *cc, *bcc, *smopts;
 {
 {
-       register char *cp2;
-       register int s;
-       char *buf, **ap;
        struct header head;
 
        struct header head;
 
-       for (s = 0, ap = people; *ap != 0; ap++)
-               s += strlen(*ap) + 1;
-       buf = salloc(s+1);
-       cp2 = buf;
-       for (ap = people; *ap != 0; ap++) {
-               cp2 = copy(*ap, cp2);
-               *cp2++ = ' ';
-       }
-       if (cp2 != buf)
-               cp2--;
-       *cp2 = '\0';
-       head.h_to = buf;
+       head.h_to = detract(to, 0);
        head.h_subject = NOSTR;
        head.h_subject = NOSTR;
-       head.h_cc = NOSTR;
-       head.h_bcc = NOSTR;
+       head.h_cc = detract(cc, 0);
+       head.h_bcc = detract(bcc, 0);
+       head.h_smopts = detract(smopts, 0);
        head.h_seq = 0;
        (void) mail1(&head);
        return(0);
        head.h_seq = 0;
        (void) mail1(&head);
        return(0);
@@ -229,6 +216,7 @@ sendmail(str)
        head.h_subject = NOSTR;
        head.h_cc = NOSTR;
        head.h_bcc = NOSTR;
        head.h_subject = NOSTR;
        head.h_cc = NOSTR;
        head.h_bcc = NOSTR;
+       head.h_smopts = NOSTR;
        head.h_seq = 0;
        (void) mail1(&head);
        return(0);
        head.h_seq = 0;
        (void) mail1(&head);
        return(0);
@@ -258,11 +246,11 @@ mail1(hp)
         */
 
        pid = -1;
         */
 
        pid = -1;
+       if (hp->h_subject == NOSTR)
+               hp->h_subject = sflag;
        if ((mtf = collect(hp)) == NULL)
                return(-1);
        hp->h_seq = 1;
        if ((mtf = collect(hp)) == NULL)
                return(-1);
        hp->h_seq = 1;
-       if (hp->h_subject == NOSTR)
-               hp->h_subject = sflag;
        if (intty && value("askcc") != NOSTR)
                grabh(hp, GCC);
        else if (intty) {
        if (intty && value("askcc") != NOSTR)
                grabh(hp, GCC);
        else if (intty) {
@@ -278,7 +266,7 @@ mail1(hp)
 
        senderr = 0;
        to = usermap(cat(extract(hp->h_bcc, GBCC),
 
        senderr = 0;
        to = usermap(cat(extract(hp->h_bcc, GBCC),
-           cat(extract(hp->h_to, GTO), extract(hp->h_cc, GCC))));
+               cat(extract(hp->h_to, GTO), extract(hp->h_cc, GCC))));
        if (to == NIL) {
                printf("No recipients specified\n");
                goto topdog;
        if (to == NIL) {
                printf("No recipients specified\n");
                goto topdog;
@@ -324,7 +312,7 @@ topdog:
                        return(-1);
                }
        }
                        return(-1);
                }
        }
-       namelist = unpack(to);
+       namelist = unpack(cat(extract(hp->h_smopts, 0), to));
        if (debug) {
                printf("Recipients of message:\n");
                for (t = namelist; *t != NOSTR; t++)
        if (debug) {
                printf("Recipients of message:\n");
                for (t = namelist; *t != NOSTR; t++)
@@ -421,6 +409,7 @@ fixhead(hp, tolist)
                fprintf(stderr, "Should be inserting commas in recip lists\n");
        hp->h_to = detract(tolist, GTO|f);
        hp->h_cc = detract(tolist, GCC|f);
                fprintf(stderr, "Should be inserting commas in recip lists\n");
        hp->h_to = detract(tolist, GTO|f);
        hp->h_cc = detract(tolist, GCC|f);
+       hp->h_bcc = detract(tolist, GBCC|f);
 }
 
 /*
 }
 
 /*
@@ -448,7 +437,7 @@ infix(hp, fi)
                return(fi);
        }
        (void) remove(tempMail);
                return(fi);
        }
        (void) remove(tempMail);
-       (void) puthead(hp, nfo, GTO|GSUBJECT|GCC|GNL);
+       (void) puthead(hp, nfo, GTO|GSUBJECT|GCC|GBCC|GNL);
        c = getc(fi);
        while (c != EOF) {
                (void) putc(c, nfo);
        c = getc(fi);
        while (c != EOF) {
                (void) putc(c, nfo);