Flush out the last dregs in the terminal before quitting when
[unix-history] / usr / src / usr.bin / mail / collect.c
index 25fb896..ac1f105 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -94,7 +94,7 @@ collect(hp, printheaders)
        t = GTO|GSUBJECT|GCC|GNL;
        getsub = 0;
        if (hp->h_subject == NOSTR && value("interactive") != NOSTR &&
        t = GTO|GSUBJECT|GCC|GNL;
        getsub = 0;
        if (hp->h_subject == NOSTR && value("interactive") != NOSTR &&
-           value("ask"))
+           (value("ask") != NOSTR || value("asksub") != NOSTR))
                t &= ~GNL, getsub++;
        if (printheaders) {
                puthead(hp, stdout, t);
                t &= ~GNL, getsub++;
        if (printheaders) {
                puthead(hp, stdout, t);
@@ -230,7 +230,7 @@ cont:
                        hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
                        break;
                case 'd':
                        hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
                        break;
                case 'd':
-                       strcpy(linebuf + 2, deadletter);
+                       strcpy(linebuf + 2, getdeadletter());
                        /* fall into . . . */
                case 'r':
                        /*
                        /* fall into . . . */
                case 'r':
                        /*
@@ -276,7 +276,7 @@ cont:
                         * Write the message on a file.
                         */
                        cp = &linebuf[2];
                         * Write the message on a file.
                         */
                        cp = &linebuf[2];
-                       while (any(*cp, " \t"))
+                       while (*cp == ' ' || *cp == '\t')
                                cp++;
                        if (*cp == '\0') {
                                fprintf(stderr, "Write what file!?\n");
                                cp++;
                        if (*cp == '\0') {
                                fprintf(stderr, "Write what file!?\n");
@@ -301,10 +301,7 @@ cont:
                                printf("No messages to send from!?!\n");
                                break;
                        }
                                printf("No messages to send from!?!\n");
                                break;
                        }
-                       cp = &linebuf[2];
-                       while (any(*cp, " \t"))
-                               cp++;
-                       if (forward(cp, collf, c) < 0)
+                       if (forward(linebuf + 2, collf, c) < 0)
                                goto err;
                        goto cont;
                case '?':
                                goto err;
                        goto cont;
                case '?':
@@ -487,7 +484,7 @@ forward(ms, fp, f)
        char ms[];
        FILE *fp;
 {
        char ms[];
        FILE *fp;
 {
-       register int *msgvec, *ip;
+       register int *msgvec;
        extern char tempMail[];
        struct ignoretab *ig;
        char *tabst;
        extern char tempMail[];
        struct ignoretab *ig;
        char *tabst;
@@ -497,7 +494,7 @@ forward(ms, fp, f)
                return(0);
        if (getmsglist(ms, msgvec, 0) < 0)
                return(0);
                return(0);
        if (getmsglist(ms, msgvec, 0) < 0)
                return(0);
-       if (*msgvec == NULL) {
+       if (*msgvec == 0) {
                *msgvec = first(0, MMNORM);
                if (*msgvec == NULL) {
                        printf("No appropriate messages\n");
                *msgvec = first(0, MMNORM);
                if (*msgvec == NULL) {
                        printf("No appropriate messages\n");
@@ -511,10 +508,12 @@ forward(ms, fp, f)
                tabst = "\t";
        ig = isupper(f) ? NULL : ignore;
        printf("Interpolating:");
                tabst = "\t";
        ig = isupper(f) ? NULL : ignore;
        printf("Interpolating:");
-       for (ip = msgvec; *ip != NULL; ip++) {
-               touch(*ip);
-               printf(" %d", *ip);
-               if (send(&message[*ip-1], fp, ig, tabst) < 0) {
+       for (; *msgvec != 0; msgvec++) {
+               struct message *mp = message + *msgvec - 1;
+
+               touch(mp);
+               printf(" %d", *msgvec);
+               if (send(mp, fp, ig, tabst) < 0) {
                        perror(tempMail);
                        return(-1);
                }
                        perror(tempMail);
                        return(-1);
                }
@@ -543,23 +542,14 @@ collcont(s)
  */
 collrub(s)
 {
  */
 collrub(s)
 {
-       register FILE *dbuf;
-       register int c;
 
        if (s == SIGINT && hadintr == 0) {
                hadintr = 1;
                longjmp(coljmp, 1);
        }
        rewind(collf);
 
        if (s == SIGINT && hadintr == 0) {
                hadintr = 1;
                longjmp(coljmp, 1);
        }
        rewind(collf);
-       if (s == SIGINT && value("nosave") != NOSTR || fsize(collf) == 0)
-               goto done;
-       if ((dbuf = fopen(deadletter, "w")) == NULL)
-               goto done;
-       chmod(deadletter, 0600);
-       while ((c = getc(collf)) != EOF)
-               putc(c, dbuf);
-       fclose(dbuf);
-done:
+       if (s != SIGINT || value("nosave") == NOSTR)
+               savedeadletter(collf);
        fclose(collf);
        signal(SIGINT, saveint);
        signal(SIGHUP, savehup);
        fclose(collf);
        signal(SIGINT, saveint);
        signal(SIGHUP, savehup);
@@ -573,6 +563,27 @@ done:
                exit(1);
 }
 
                exit(1);
 }
 
+savedeadletter(fp)
+       register FILE *fp;
+{
+       register FILE *dbuf;
+       register int c;
+       char *cp;
+
+       if (fsize(fp) == 0)
+               return;
+       cp = getdeadletter();
+       c = umask(077);
+       dbuf = fopen(cp, "a");
+       umask(c);
+       if (dbuf == NULL)
+               return;
+       while ((c = getc(fp)) != EOF)
+               putc(c, dbuf);
+       fclose(dbuf);
+       rewind(fp);
+}
+
 /*
  * Acknowledge an interrupt signal from the tty by typing an @
  */
 /*
  * Acknowledge an interrupt signal from the tty by typing an @
  */