changed calls to signal to sigset/sigsys
[unix-history] / usr / src / usr.bin / mail / quit.c
index 4dc515c..b64ad3b 100644 (file)
@@ -9,7 +9,7 @@
  * Termination processing.
  */
 
  * Termination processing.
  */
 
-static char *SccsId = "@(#)quit.c      1.1 %G%";
+static char *SccsId = "@(#)quit.c      1.5 %G%";
 
 /*
  * Save all of the undetermined messages at the top of "mbox"
 
 /*
  * Save all of the undetermined messages at the top of "mbox"
@@ -19,13 +19,20 @@ static char *SccsId = "@(#)quit.c   1.1 %G%";
 
 quit()
 {
 
 quit()
 {
-       int mcount, p, modify;
+       int mcount, p, modify, autohold, anystat, holdbit;
        FILE *ibuf, *obuf, *fbuf, *rbuf;
        register struct message *mp;
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
 
        FILE *ibuf, *obuf, *fbuf, *rbuf;
        register struct message *mp;
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
 
+       /*
+        * If we are read only, we can't do anything,
+        * so just return quickly.
+        */
+
+       if (readonly)
+               return;
        /*
         * See if there any messages to save in mbox.  If no, we
         * can save copying mbox to /tmp and back.
        /*
         * See if there any messages to save in mbox.  If no, we
         * can save copying mbox to /tmp and back.
@@ -73,22 +80,36 @@ quit()
                        goto newmail;
                remove(tempResid);
        }
                        goto newmail;
                remove(tempResid);
        }
+
+       /*
+        * Adjust the message flags in each message.
+        */
+
+       anystat = 0;
+       autohold = value("hold") != NOSTR;
+       holdbit = autohold ? MPRESERVE : MBOX;
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
-               if (mp->m_flag & MDELETED)
-                       mp->m_flag = MDELETED|MTOUCH;
+               if (mp->m_flag & MNEW) {
+                       mp->m_flag &= ~MNEW;
+                       mp->m_flag |= MSTATUS;
+               }
+               if (mp->m_flag & MSTATUS)
+                       anystat++;
                if ((mp->m_flag & MTOUCH) == 0)
                if ((mp->m_flag & MTOUCH) == 0)
-                       mp->m_flag |= MDELETED;
+                       mp->m_flag |= MPRESERVE;
+               if ((mp->m_flag & (MBOX|MSAVED|MDELETED|MPRESERVE)) == 0)
+                       mp->m_flag |= holdbit;
        }
        modify = 0;
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
        }
        modify = 0;
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
-               if ((mp->m_flag & (MSAVED|MDELETED|MPRESERVE)) == 0)
+               if (mp->m_flag & MBOX)
                        c++;
                        c++;
-               if ((mp->m_flag & MPRESERVE) || (mp->m_flag & MTOUCH) == 0)
+               if (mp->m_flag & MPRESERVE)
                        p++;
                if (mp->m_flag & MODIFY)
                        modify++;
        }
                        p++;
                if (mp->m_flag & MODIFY)
                        modify++;
        }
-       if (p == msgCount && !modify) {
+       if (p == msgCount && !modify && !anystat) {
                if (p == 1)
                        printf("Held 1 message in %s\n", mailname);
                else
                if (p == 1)
                        printf("Held 1 message in %s\n", mailname);
                else
@@ -155,7 +176,7 @@ quit()
                        return;
                }
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                        return;
                }
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
-               if ((mp->m_flag & (MDELETED|MSAVED|MPRESERVE)) == 0)
+               if (mp->m_flag & MBOX)
                        if (send(mp, obuf) < 0) {
                                perror(mbox);
                                fclose(ibuf);
                        if (send(mp, obuf) < 0) {
                                perror(mbox);
                                fclose(ibuf);