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