install correct aliases file
[unix-history] / usr / src / usr.bin / mail / quit.c
index 7b233ee..09044f0 100644 (file)
@@ -1,6 +1,23 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)quit.c      2.9 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)quit.c     5.10 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "rcv.h"
 #include <sys/stat.h>
 
 #include "rcv.h"
 #include <sys/stat.h>
@@ -26,7 +43,7 @@ quit()
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
        register int c;
        extern char tempQuit[], tempResid[];
        struct stat minfo;
-       char *id;
+       char *mbox;
 
        /*
         * If we are read only, we can't do anything,
 
        /*
         * If we are read only, we can't do anything,
@@ -43,22 +60,12 @@ quit()
         * Delete all untouched messages to keep them out of mbox.
         * If all the messages are to be preserved, just exit with
         * a message.
         * Delete all untouched messages to keep them out of mbox.
         * If all the messages are to be preserved, just exit with
         * a message.
-        *
-        * If the luser has sent mail to himself, refuse to do
-        * anything with the mailbox, unless mail locking works.
         */
 
        fbuf = fopen(mailname, "r");
        if (fbuf == NULL)
                goto newmail;
        flock(fileno(fbuf), LOCK_EX);
         */
 
        fbuf = fopen(mailname, "r");
        if (fbuf == NULL)
                goto newmail;
        flock(fileno(fbuf), LOCK_EX);
-#ifndef CANLOCK
-       if (selfsent) {
-               printf("You have new mail.\n");
-               fclose(fbuf);
-               return;
-       }
-#endif
        rbuf = NULL;
        if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
                printf("New mail has arrived.\n");
        rbuf = NULL;
        if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
                printf("New mail has arrived.\n");
@@ -119,18 +126,17 @@ quit()
                if (mp->m_flag & MODIFY)
                        modify++;
                if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
                if (mp->m_flag & MODIFY)
                        modify++;
                if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
-                       id = hfield("article-id", mp);
-                       if (id != NOSTR)
+                       char *id;
+
+                       if ((id = hfield("article-id", mp)) != NOSTR)
                                fprintf(readstat, "%s\n", id);
                }
        }
        if (Tflag != NOSTR)
                fclose(readstat);
        if (p == msgCount && !modify && !anystat) {
                                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);
-               else
-                       printf("Held %2d messages in %s\n", p, mailname);
+               printf("Held %d message%s in %s\n",
+                       p, p == 1 ? "" : "s", mailname);
                fclose(fbuf);
                return;
        }
                fclose(fbuf);
                return;
        }
@@ -150,6 +156,7 @@ quit()
         * just copy saveable entries at the end.
         */
 
         * just copy saveable entries at the end.
         */
 
+       mbox = expand("&");
        mcount = c;
        if (value("append") == NOSTR) {
                if ((obuf = fopen(tempQuit, "w")) == NULL) {
        mcount = c;
        if (value("append") == NOSTR) {
                if ((obuf = fopen(tempQuit, "w")) == NULL) {
@@ -186,15 +193,17 @@ quit()
                        return;
                }
        }
                        return;
                }
        }
-       if (value("append") != NOSTR)
+       if (value("append") != NOSTR) {
                if ((obuf = fopen(mbox, "a")) == NULL) {
                        perror(mbox);
                        fclose(fbuf);
                        return;
                }
                if ((obuf = fopen(mbox, "a")) == NULL) {
                        perror(mbox);
                        fclose(fbuf);
                        return;
                }
+               fchmod(fileno(obuf), 0600);
+       }
        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) < 0) {
+                       if (send(mp, obuf, saveignore, NOSTR) < 0) {
                                perror(mbox);
                                fclose(ibuf);
                                fclose(obuf);
                                perror(mbox);
                                fclose(ibuf);
                                fclose(obuf);
@@ -299,7 +308,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) < 0) {
+                       if (send(mp, obuf, (struct ignoretab *)0, NOSTR) < 0) {
                                perror(mailname);
                                fclose(obuf);
                                return(-1);
                                perror(mailname);
                                fclose(obuf);
                                return(-1);