changed to disallow duplicate insertion of fields into the ignore list;
[unix-history] / usr / src / usr.bin / mail / main.c
index 6d2b46a..5ab4d3c 100644 (file)
@@ -9,7 +9,9 @@
  * Startup -- interface with user.
  */
 
  * Startup -- interface with user.
  */
 
-static char *SccsId = "@(#)main.c      1.2 %G%";
+static char *SccsId = "@(#)main.c      2.8 %G%";
+
+jmp_buf        hdrjmp;
 
 /*
  * Find out who the user is, copy his mail file (if exists) into
 
 /*
  * Find out who the user is, copy his mail file (if exists) into
@@ -27,9 +29,10 @@ main(argc, argv)
 {
        register char *ef;
        register int i, argp;
 {
        register char *ef;
        register int i, argp;
-       int mustsend, uflag;
+       int mustsend, uflag, hdrstop(), (*prevint)(), f;
        FILE *ibuf, *ftat;
        extern char _sobuf[];
        FILE *ibuf, *ftat;
        extern char _sobuf[];
+       struct sgttyb tbuf;
 
 #ifdef signal
        Siginit();
 
 #ifdef signal
        Siginit();
@@ -47,6 +50,12 @@ main(argc, argv)
        mypid = getpid();
        intty = isatty(0);
        outtty = isatty(1);
        mypid = getpid();
        intty = isatty(0);
        outtty = isatty(1);
+       if (outtty) {
+               gtty(1, &tbuf);
+               baud = tbuf.sg_ospeed;
+       }
+       else
+               baud = B9600;
        image = -1;
        setbuf(stdout, _sobuf);
 
        image = -1;
        setbuf(stdout, _sobuf);
 
@@ -90,13 +99,31 @@ main(argc, argv)
                        i++;
                        break;
 
                        i++;
                        break;
 
+               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];
+                       if ((f = creat(Tflag, 0600)) < 0) {
+                               perror(Tflag);
+                               exit(1);
+                       }
+                       close(f);
+                       i++;
+                       break;
+
                case 'u':
                        /*
                         * Next argument is person to pretend to be.
                         */
                        uflag++;
                        if (i >= argc - 1) {
                case 'u':
                        /*
                         * Next argument is person to pretend to be.
                         */
                        uflag++;
                        if (i >= argc - 1) {
-                               fprintf(stderr, "You obviously dont know what you're doing\n");
+                               fprintf(stderr, "Missing user name for -u\n");
                                exit(1);
                        }
                        strcpy(myname, argv[i+1]);
                                exit(1);
                        }
                        strcpy(myname, argv[i+1]);
@@ -170,6 +197,13 @@ main(argc, argv)
                        nosrc++;
                        break;
 
                        nosrc++;
                        break;
 
+               case 'N':
+                       /*
+                        * Avoid initial header printing.
+                        */
+                       noheader++;
+                       break;
+
                default:
                        fprintf(stderr, "Unknown flag: %s\n", argv[i]);
                        exit(1);
                default:
                        fprintf(stderr, "Unknown flag: %s\n", argv[i]);
                        exit(1);
@@ -180,13 +214,6 @@ main(argc, argv)
         * Check for inconsistent arguments.
         */
 
         * Check for inconsistent arguments.
         */
 
-       if (rflag != NOSTR && strcmp(rflag, "daemon") == 0) {
-               ftat = fopen("/crp/kas/gotcha", "a");
-               if (ftat != NULL) {
-                       fprintf(ftat, "user daemon, real uid %d\n", getuid());
-                       fclose(ftat);
-               }
-       }
        if (ef != NOSTR && argp != -1) {
                fprintf(stderr, "Cannot give -f and people to send to.\n");
                exit(1);
        if (ef != NOSTR && argp != -1) {
                fprintf(stderr, "Cannot give -f and people to send to.\n");
                exit(1);
@@ -196,8 +223,12 @@ main(argc, argv)
                exit(1);
        }
        tinit();
                exit(1);
        }
        tinit();
+       input = stdin;
+       rcvmode = argp == -1;
+       if (!nosrc)
+               load(MASTER);
+       load(mailrc);
        if (argp != -1) {
        if (argp != -1) {
-               commands();
                mail(&argv[argp]);
 
                /*
                mail(&argv[argp]);
 
                /*
@@ -213,15 +244,60 @@ main(argc, argv)
         * the system mailbox, and open up the right stuff.
         */
 
         * the system mailbox, and open up the right stuff.
         */
 
-       rcvmode++;
        if (ef != NOSTR) {
        if (ef != NOSTR) {
+               char *ename;
+
                edit++;
                edit++;
-               editfile = mailname = ef;
+               ename = expand(ef);
+               if (ename != ef) {
+                       ef = (char *) calloc(1, strlen(ename) + 1);
+                       strcpy(ef, ename);
+               }
+               editfile = ef;
+               strcpy(mailname, ef);
        }
        }
-       if (setfile(mailname, edit) < 0)
+       if (setfile(mailname, edit) < 0) {
+               if (edit)
+                       perror(mailname);
+               else
+                       fprintf(stderr, "No mail for %s\n", myname);
                exit(1);
                exit(1);
+       }
+       if (!edit && !noheader && value("noheader") == NOSTR) {
+               if (setjmp(hdrjmp) == 0) {
+                       if ((prevint = sigset(SIGINT, SIG_IGN)) != SIG_IGN)
+                               sigset(SIGINT, hdrstop);
+                       announce();
+                       fflush(stdout);
+                       sigset(SIGINT, prevint);
+               }
+       }
+       if (edit)
+               newfileinfo();
+       if (!edit && msgCount == 0) {
+               printf("No mail\n");
+               fflush(stdout);
+               exit(0);
+       }
        commands();
        commands();
-       if (!edit)
+       if (!edit) {
+               sigset(SIGHUP, SIG_IGN);
+               sigset(SIGINT, SIG_IGN);
+               sigset(SIGQUIT, SIG_IGN);
                quit();
                quit();
+       }
        exit(0);
 }
        exit(0);
 }
+
+/*
+ * Interrupt printing of the headers.
+ */
+hdrstop()
+{
+
+       clrbuf(stdout);
+       printf("\nInterrupt\n");
+       fflush(stdout);
+       sigrelse(SIGINT);
+       longjmp(hdrjmp, 1);
+}