date and time created 83/07/02 17:57:17 by sam
[unix-history] / usr / src / usr.bin / uucp / libuu / mailst.c
CommitLineData
c635088c
SL
1#ifndef lint
2static char sccsid[] = "@(#)mailst.c 5.1 (Berkeley) %G%";
3#endif
4
5#include "uucp.h"
6
7/*******
8 * mailst(user, str, file)
9 *
10 * mailst - this routine will fork and execute
11 * a mail command sending string (str) to user (user).
12 * If file is non-null, the file is also sent.
13 * (this is used for mail returned to sender.)
14 */
15
16mailst(user, str, file)
17char *user, *str, *file;
18{
19 register FILE *fp, *fi;
20 extern FILE *popen(), *pclose();
21 char cmd[100], buf[BUFSIZ];
22 register int nc;
23
24 sprintf(cmd, "mail %s", user);
25 if ((fp = popen(cmd, "w")) == NULL)
26 return;
27 fprintf(fp, "%s", str);
28
29 if (*file != '\0' && (fi = fopen(subfile(file), "r")) != NULL) {
30 while ((nc = fread(buf, sizeof (char), BUFSIZ, fi)) > 0)
31 fwrite(buf, sizeof (char), nc, fp);
32 fclose(fi);
33 }
34
35 pclose(fp);
36 return;
37}