date and time created 83/02/24 12:55:54 by mckusick
[unix-history] / usr / src / usr.bin / mail / quit.c
index 3f64787..4006bf4 100644 (file)
@@ -9,7 +9,7 @@
  * Termination processing.
  */
 
  * Termination processing.
  */
 
-static char *SccsId = "@(#)quit.c      2.1 %G%";
+static char *SccsId = "@(#)quit.c      2.4 %G%";
 
 /*
  * Save all of the undetermined messages at the top of "mbox"
 
 /*
  * Save all of the undetermined messages at the top of "mbox"
@@ -19,12 +19,13 @@ static char *SccsId = "@(#)quit.c   2.1 %G%";
 
 quit()
 {
 
 quit()
 {
-       int mcount, p, modify, autohold, anystat, holdbit;
-       FILE *ibuf, *obuf, *fbuf, *rbuf;
+       int mcount, p, modify, autohold, anystat, holdbit, nohold;
+       FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat;
        register struct message *mp;
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
        register struct message *mp;
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
+       char *id;
 
        /*
         * If we are read only, we can't do anything,
 
        /*
         * If we are read only, we can't do anything,
@@ -88,6 +89,9 @@ quit()
        anystat = 0;
        autohold = value("hold") != NOSTR;
        holdbit = autohold ? MPRESERVE : MBOX;
        anystat = 0;
        autohold = value("hold") != NOSTR;
        holdbit = autohold ? MPRESERVE : MBOX;
+       nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
+       if (value("keepsave") != NOSTR)
+               nohold &= ~MSAVED;
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW) {
                        mp->m_flag &= ~MNEW;
        for (mp = &message[0]; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW) {
                        mp->m_flag &= ~MNEW;
@@ -97,10 +101,14 @@ quit()
                        anystat++;
                if ((mp->m_flag & MTOUCH) == 0)
                        mp->m_flag |= MPRESERVE;
                        anystat++;
                if ((mp->m_flag & MTOUCH) == 0)
                        mp->m_flag |= MPRESERVE;
-               if ((mp->m_flag & (MBOX|MSAVED|MDELETED|MPRESERVE)) == 0)
+               if ((mp->m_flag & nohold) == 0)
                        mp->m_flag |= holdbit;
        }
        modify = 0;
                        mp->m_flag |= holdbit;
        }
        modify = 0;
+       if (Tflag != NOSTR) {
+               if ((readstat = fopen(Tflag, "w")) == NULL)
+                       Tflag = NOSTR;
+       }
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MBOX)
                        c++;
        for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MBOX)
                        c++;
@@ -108,7 +116,14 @@ quit()
                        p++;
                if (mp->m_flag & MODIFY)
                        modify++;
                        p++;
                if (mp->m_flag & MODIFY)
                        modify++;
+               if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
+                       id = hfield("article-id", mp);
+                       if (id != NOSTR)
+                               fprintf(readstat, "%s\n", id);
+               }
        }
        }
+       if (Tflag != NOSTR)
+               fclose(readstat);
        if (p == msgCount && !modify && !anystat) {
                if (p == 1)
                        printf("Held 1 message in %s\n", mailname);
        if (p == msgCount && !modify && !anystat) {
                if (p == 1)
                        printf("Held 1 message in %s\n", mailname);
@@ -177,7 +192,7 @@ quit()
                }
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MBOX)
                }
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if (mp->m_flag & MBOX)
-                       if (send(mp, obuf) < 0) {
+                       if (send(mp, obuf, 0) < 0) {
                                perror(mbox);
                                fclose(ibuf);
                                fclose(obuf);
                                perror(mbox);
                                fclose(ibuf);
                                fclose(obuf);
@@ -259,7 +274,6 @@ newmail:
  * saved.  On any error, just return -1.  Else return 0.
  * Incorporate the any new mail that we found.
  */
  * saved.  On any error, just return -1.  Else return 0.
  * Incorporate the any new mail that we found.
  */
-
 writeback(res)
        register FILE *res;
 {
 writeback(res)
        register FILE *res;
 {
@@ -280,7 +294,7 @@ writeback(res)
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
                        p++;
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
                if ((mp->m_flag&MPRESERVE)||(mp->m_flag&MTOUCH)==0) {
                        p++;
-                       if (send(mp, obuf) < 0) {
+                       if (send(mp, obuf, 0) < 0) {
                                perror(mailname);
                                fclose(obuf);
                                return(-1);
                                perror(mailname);
                                fclose(obuf);
                                return(-1);