bug fixes and changes from Rick Adams
[unix-history] / usr / src / usr.bin / uucp / libuu / mailst.c
index 49c667f..9fc02ff 100644 (file)
@@ -1,12 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)mailst.c   5.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)mailst.c   5.3 (Berkeley) %G%";
 #endif
 
 #include "uucp.h"
 
 #endif
 
 #include "uucp.h"
 
-/*******
- *     mailst(user, str, file)
- *
+/*
  *     mailst  -  this routine will fork and execute
  *     a mail command sending string (str) to user (user).
  *     If file is non-null, the file is also sent.
  *     mailst  -  this routine will fork and execute
  *     a mail command sending string (str) to user (user).
  *     If file is non-null, the file is also sent.
@@ -17,20 +15,18 @@ mailst(user, str, file)
 char *user, *str, *file;
 {
        register FILE *fp, *fi;
 char *user, *str, *file;
 {
        register FILE *fp, *fi;
-       char cmd[100], buf[BUFSIZ];
-       register int nc;
+       char buf[BUFSIZ];
+       register int c;
 
 
-       sprintf(cmd, "mail %s", user);
-       if ((fp = rpopen(cmd, "w")) == NULL)
-               return;
-       fprintf(fp, "%s", str);
-
-       if (*file != '\0' && (fi = fopen(subfile(file), "r")) != NULL) {
-               while ((nc = fread(buf, sizeof (char), BUFSIZ, fi)) > 0)
-                       fwrite(buf, sizeof (char), nc, fp);
-               fclose(fi);
+       sprintf(buf, "%s %s", MAIL, user);
+       if ((fp = rpopen(buf, "w")) != NULL) {
+               fprintf(fp, "From: uucp\nTo: %s\nSubject: %s\n\n", user, str);
+               if (file && *file != '\0' && (fi = fopen(subfile(file), "r")) != NULL) {
+                       while ((c = getc(fi)) != EOF)
+                               putc(c, fp);
+                       putc('\n', fp);
+                       fclose(fi);
+               }
+               rpclose(fp);
        }
        }
-
-       pclose(fp);
-       return;
 }
 }