date and time created 83/02/11 15:44:29 by rrh
[unix-history] / usr / src / usr.bin / mail / cmd1.c
index 8577de8..942d5db 100644 (file)
@@ -8,7 +8,7 @@
  * User commands.
  */
 
  * User commands.
  */
 
-static char *SccsId = "@(#)cmd1.c      1.5 %G%";
+static char *SccsId = "@(#)cmd1.c      2.10 %G%";
 
 /*
  * Print the current active headings.
 
 /*
  * Print the current active headings.
@@ -22,15 +22,17 @@ headers(msgvec)
 {
        register int n, mesg, flag;
        register struct message *mp;
 {
        register int n, mesg, flag;
        register struct message *mp;
+       int size;
 
 
+       size = screensize();
        n = msgvec[0];
        if (n != 0)
        n = msgvec[0];
        if (n != 0)
-               screen = (n-1)/SCREEN;
+               screen = (n-1)/size;
        if (screen < 0)
                screen = 0;
        if (screen < 0)
                screen = 0;
-       mp = &message[screen * SCREEN];
+       mp = &message[screen * size];
        if (mp >= &message[msgCount])
        if (mp >= &message[msgCount])
-               mp = &message[msgCount - SCREEN];
+               mp = &message[msgCount - size];
        if (mp < &message[0])
                mp = &message[0];
        flag = 0;
        if (mp < &message[0])
                mp = &message[0];
        flag = 0;
@@ -41,7 +43,7 @@ headers(msgvec)
                mesg++;
                if (mp->m_flag & MDELETED)
                        continue;
                mesg++;
                if (mp->m_flag & MDELETED)
                        continue;
-               if (flag++ >= SCREEN)
+               if (flag++ >= size)
                        break;
                printhead(mesg);
                sreset();
                        break;
                printhead(mesg);
                sreset();
@@ -53,6 +55,36 @@ headers(msgvec)
        return(0);
 }
 
        return(0);
 }
 
+/*
+ * Set the list of alternate names for out host.
+ */
+local(namelist)
+       char **namelist;
+{
+       register int c;
+       register char **ap, **ap2, *cp;
+
+       c = argcount(namelist) + 1;
+       if (c == 1) {
+               if (localnames == 0)
+                       return(0);
+               for (ap = localnames; *ap; ap++)
+                       printf("%s ", *ap);
+               printf("\n");
+               return(0);
+       }
+       if (localnames != 0)
+               cfree((char *) localnames);
+       localnames = (char **) calloc(c, sizeof (char *));
+       for (ap = namelist, ap2 = localnames; *ap; ap++, ap2++) {
+               cp = (char *) calloc(strlen(*ap) + 1, sizeof (char));
+               strcpy(cp, *ap);
+               *ap2 = cp;
+       }
+       *ap2 = 0;
+       return(0);
+}
+
 /*
  * Scroll to the next/previous screen
  */
 /*
  * Scroll to the next/previous screen
  */
@@ -60,16 +92,17 @@ headers(msgvec)
 scroll(arg)
        char arg[];
 {
 scroll(arg)
        char arg[];
 {
-       register int s;
+       register int s, size;
        int cur[1];
 
        cur[0] = 0;
        int cur[1];
 
        cur[0] = 0;
+       size = screensize();
        s = screen;
        switch (*arg) {
        case 0:
        case '+':
                s++;
        s = screen;
        switch (*arg) {
        case 0:
        case '+':
                s++;
-               if (s*SCREEN > msgCount) {
+               if (s * size > msgCount) {
                        printf("On last screenful of messages\n");
                        return(0);
                }
                        printf("On last screenful of messages\n");
                        return(0);
                }
@@ -91,6 +124,32 @@ scroll(arg)
        return(headers(cur));
 }
 
        return(headers(cur));
 }
 
+/*
+ * Compute what the screen size should be.
+ * We use the following algorithm:
+ *     If user specifies with screen option, use that.
+ *     If baud rate < 1200, use  5
+ *     If baud rate = 1200, use 10
+ *     If baud rate > 1200, use 20
+ */
+screensize()
+{
+       register char *cp;
+       register int s;
+
+       if ((cp = value("screen")) != NOSTR) {
+               s = atoi(cp);
+               if (s > 0)
+                       return(s);
+       }
+       if (baud < B1200)
+               s = 5;
+       else if (baud == B1200)
+               s = 10;
+       else
+               s = 20;
+       return(s);
+}
 
 /*
  * Print out the headlines for each message
 
 /*
  * Print out the headlines for each message
@@ -149,8 +208,10 @@ printhead(mesg)
                dispc = 'N';
        if ((mp->m_flag & (MREAD|MNEW)) == 0)
                dispc = 'U';
                dispc = 'N';
        if ((mp->m_flag & (MREAD|MNEW)) == 0)
                dispc = 'U';
+       if (mp->m_flag & MBOX)
+               dispc = 'M';
        parse(headline, &hl, pbuf);
        parse(headline, &hl, pbuf);
-       sprintf(wcount, " %d/%d", mp->m_lines, mp->m_size);
+       sprintf(wcount, " %d/%ld", mp->m_lines, mp->m_size);
        s = strlen(wcount);
        cp = wcount + s;
        while (s < 7)
        s = strlen(wcount);
        cp = wcount + s;
        while (s < 7)
@@ -158,10 +219,10 @@ printhead(mesg)
        *cp = '\0';
        if (subjline != NOSTR)
                printf("%c%c%3d %-8s %16.16s %s \"%s\"\n", curind, dispc, mesg,
        *cp = '\0';
        if (subjline != NOSTR)
                printf("%c%c%3d %-8s %16.16s %s \"%s\"\n", curind, dispc, mesg,
-                   nameof(mp), hl.l_date, wcount, subjline);
+                   nameof(mp, 0), hl.l_date, wcount, subjline);
        else
                printf("%c%c%3d %-8s %16.16s %s\n", curind, dispc, mesg,
        else
                printf("%c%c%3d %-8s %16.16s %s\n", curind, dispc, mesg,
-                   nameof(mp), hl.l_date, wcount);
+                   nameof(mp, 0), hl.l_date, wcount);
 }
 
 /*
 }
 
 /*
@@ -200,12 +261,31 @@ pcmdlist()
 }
 
 /*
 }
 
 /*
- * Type out the messages requested.
+ * Type out messages, honor ignored fields.
  */
  */
+type(msgvec)
+       int *msgvec;
+{
+
+       return(type1(msgvec, 1));
+}
 
 
+/*
+ * Type out messages, even printing ignored fields.
+ */
+Type(msgvec)
+       int *msgvec;
+{
+
+       return(type1(msgvec, 0));
+}
+
+/*
+ * Type out the messages requested.
+ */
 jmp_buf        pipestop;
 
 jmp_buf        pipestop;
 
-type(msgvec)
+type1(msgvec, doign)
        int *msgvec;
 {
        register *ip;
        int *msgvec;
 {
        register *ip;
@@ -219,10 +299,10 @@ type(msgvec)
        obuf = stdout;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
        obuf = stdout;
        if (setjmp(pipestop)) {
                if (obuf != stdout) {
-                       pclose(obuf);
                        pipef = NULL;
                        pipef = NULL;
+                       pclose(obuf);
                }
                }
-               signal(SIGPIPE, SIG_DFL);
+               sigset(SIGPIPE, SIG_DFL);
                return(0);
        }
        if (intty && outtty && (cp = value("crt")) != NOSTR) {
                return(0);
        }
        if (intty && outtty && (cp = value("crt")) != NOSTR) {
@@ -236,7 +316,7 @@ type(msgvec)
                        }
                        else {
                                pipef = obuf;
                        }
                        else {
                                pipef = obuf;
-                               signal(SIGPIPE, brokpipe);
+                               sigset(SIGPIPE, brokpipe);
                        }
                }
        }
                        }
                }
        }
@@ -245,13 +325,13 @@ type(msgvec)
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
                touch(mesg);
                mp = &message[mesg-1];
                dot = mp;
-               print(mp, obuf);
+               print(mp, obuf, doign);
        }
        }
-       signal(SIGPIPE, SIG_DFL);
        if (obuf != stdout) {
        if (obuf != stdout) {
-               pclose(obuf);
                pipef = NULL;
                pipef = NULL;
+               pclose(obuf);
        }
        }
+       sigset(SIGPIPE, SIG_DFL);
        return(0);
 }
 
        return(0);
 }
 
@@ -262,8 +342,11 @@ type(msgvec)
 
 brokpipe()
 {
 
 brokpipe()
 {
-
-       signal(SIGPIPE, SIG_IGN);
+# ifdef VMUNIX
+       sigrelse(SIGPIPE);
+# else
+       signal(SIGPIPE, brokpipe);
+# endif
        longjmp(pipestop, 1);
 }
 
        longjmp(pipestop, 1);
 }
 
@@ -271,7 +354,7 @@ brokpipe()
  * Print the indicated message on standard output.
  */
 
  * Print the indicated message on standard output.
  */
 
-print(mp, obuf)
+print(mp, obuf, doign)
        register struct message *mp;
        FILE *obuf;
 {
        register struct message *mp;
        FILE *obuf;
 {
@@ -279,7 +362,7 @@ print(mp, obuf)
        if (value("quiet") == NOSTR)
                fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1);
        touch(mp - &message[0] + 1);
        if (value("quiet") == NOSTR)
                fprintf(obuf, "Message %2d:\n", mp - &message[0] + 1);
        touch(mp - &message[0] + 1);
-       send(mp, obuf);
+       send(mp, obuf, doign);
 }
 
 /*
 }
 
 /*
@@ -344,3 +427,50 @@ stouch(msgvec)
        }
        return(0);
 }
        }
        return(0);
 }
+
+/*
+ * Make sure all passed messages get mboxed.
+ */
+
+mboxit(msgvec)
+       int msgvec[];
+{
+       register int *ip;
+
+       for (ip = msgvec; *ip != 0; ip++) {
+               dot = &message[*ip-1];
+               dot->m_flag |= MTOUCH|MBOX;
+               dot->m_flag &= ~MPRESERVE;
+       }
+       return(0);
+}
+
+/*
+ * List the folders the user currently has.
+ */
+folders()
+{
+       char dirname[BUFSIZ], cmd[BUFSIZ];
+       int pid, s, e;
+
+       if (getfold(dirname) < 0) {
+               printf("No value set for \"folder\"\n");
+               return(-1);
+       }
+       switch ((pid = fork())) {
+       case 0:
+               sigchild();
+               execlp("ls", "ls", dirname, 0);
+               clrbuf(stdout);
+               exit(1);
+
+       case -1:
+               perror("fork");
+               return(-1);
+
+       default:
+               while ((e = wait(&s)) != -1 && e != pid)
+                       ;
+       }
+       return(0);
+}