converted man page
[unix-history] / usr / src / bin / rmail / rmail.c
index 307ac08..c54cdde 100644 (file)
@@ -1,6 +1,19 @@
+/*
+ * Copyright (c) 1981, 1988 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)rmail.c    4.9 (Berkeley) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1981, 1988 The Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)rmail.c    4.15 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * RMAIL -- UUCP mail server.
 
 /*
  * RMAIL -- UUCP mail server.
@@ -10,11 +23,12 @@ static char sccsid[] =      "@(#)rmail.c    4.9 (Berkeley) %G%";
  *     It calls sendmail giving it a -f option built from these lines. 
  */
 
  *     It calls sendmail giving it a -f option built from these lines. 
  */
 
-#include <stdio.h>
 #include <sysexits.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/stat.h>
 #include <sysexits.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/stat.h>
+#include <stdio.h>
+#include <paths.h>
 # include "conf.h"
 
 typedef char bool;
 # include "conf.h"
 
 typedef char bool;
@@ -26,8 +40,6 @@ extern char *rindex();
 
 char *Domain = "UUCP";         /* Default "Domain" */
 
 
 char *Domain = "UUCP";         /* Default "Domain" */
 
-#define MAILER "/usr/lib/sendmail"
-
 main(argc, argv)
        int argc;
        char **argv;
 main(argc, argv)
        int argc;
        char **argv;
@@ -65,10 +77,11 @@ main(argc, argv)
        }
        from[0] = '\0';
        fsys[0] = '\0';
        }
        from[0] = '\0';
        fsys[0] = '\0';
-       (void) strcpy(ufrom, "/dev/null");
+       (void) strcpy(ufrom, _PATH_DEVNULL);
 
        for (position = 0;; position = ftell(stdin)) {
 
        for (position = 0;; position = ftell(stdin)) {
-               (void) fgets(lbuf, sizeof lbuf, stdin);
+               if (fgets(lbuf, sizeof lbuf, stdin) == NULL)
+                       exit(EX_DATAERR);
                if (strncmp(lbuf, "From ", 5) != 0 &&
                    strncmp(lbuf, ">From ", 6) != 0)
                        break;
                if (strncmp(lbuf, "From ", 5) != 0 &&
                    strncmp(lbuf, ">From ", 6) != 0)
                        break;
@@ -123,9 +136,11 @@ main(argc, argv)
         * that case below. 
         */
        i = 0;
         * that case below. 
         */
        i = 0;
-       args[i++] = MAILER;
-       args[i++] = "-ee";
-       if (fsys[0] != '\0') {
+       args[i++] = _PATH_SENDMAIL;
+       args[i++] = "-oee";             /* no errors, just status */
+       args[i++] = "-odq";             /* queue it, don't try to deliver */
+       args[i++] = "-oi";              /* ignore '.' on a line by itself */
+       if (fsys[0] != '\0') {          /* set sender's host name */
                static char junk2[512];
 
                if (index(fsys, '.') == NULL) {
                static char junk2[512];
 
                if (index(fsys, '.') == NULL) {
@@ -135,16 +150,24 @@ main(argc, argv)
                (void) sprintf(junk2, "-oMs%s", fsys);
                args[i++] = junk2;
        }
                (void) sprintf(junk2, "-oMs%s", fsys);
                args[i++] = junk2;
        }
+                                       /* set protocol used */
        (void) sprintf(junk, "-oMr%s", Domain);
        args[i++] = junk;
        (void) sprintf(junk, "-oMr%s", Domain);
        args[i++] = junk;
-       if (from[0] != '\0') {
+       if (from[0] != '\0') {          /* set name of ``from'' person */
                static char junk2[512];
 
                (void) sprintf(junk2, "-f%s", from);
                args[i++] = junk2;
        }
        for (; *++argv != NULL; i++) {
                static char junk2[512];
 
                (void) sprintf(junk2, "-f%s", from);
                args[i++] = junk2;
        }
        for (; *++argv != NULL; i++) {
-               args[i] = *argv;
+               /*
+                * don't copy arguments beginning with - as they will
+                * be passed to sendmail and could be interpreted as flags
+                * should be fixed in sendmail by using getopt(3), and
+                * just passing "--" before regular args.
+                */
+               if (**argv != '-')
+                       args[i] = *argv;
        }
        args[i] = NULL;
 #ifdef DEBUG
        }
        args[i] = NULL;
 #ifdef DEBUG
@@ -162,10 +185,10 @@ main(argc, argv)
                 * first line down the pipe. 
                 */
                int pipefd[2];
                 * first line down the pipe. 
                 */
                int pipefd[2];
-# ifdef DEBUG
+#ifdef DEBUG
                if (Debug)
                        printf("Not a regular file!\n");
                if (Debug)
                        printf("Not a regular file!\n");
-# endif DEBUG
+#endif
                if (pipe(pipefd) < 0)
                        exit(EX_OSERR);
                if (fork() == 0) {
                if (pipe(pipefd) < 0)
                        exit(EX_OSERR);
                if (fork() == 0) {
@@ -188,7 +211,7 @@ main(argc, argv)
                close(pipefd[1]);
                dup2(pipefd[0], 0);
        }
                close(pipefd[1]);
                dup2(pipefd[0], 0);
        }
-       execv(MAILER, args);
-       fprintf(stderr, "Exec of %s failed!\n", MAILER);
+       execv(_PATH_SENDMAIL, args);
+       fprintf(stderr, "Exec of %s failed!\n", _PATH_SENDMAIL);
        exit(EX_OSERR);
 }
        exit(EX_OSERR);
 }