home *** CD-ROM | disk | FTP | other *** search
- /* $Header: uucp.c,v 1.1 88/06/06 09:39:42 chip Exp $
- *
- * Handle mail destined for other hosts via UUCP.
- * Deliver is intended as a very low-level program, so we don't
- * do anything fancy here. We just hand the message to uux.
- *
- * $Log: uucp.c,v $
- * Revision 1.1 88/06/06 09:39:42 chip
- * Initial revision
- *
- */
-
- #include "deliver.h"
- #include <sys/types.h>
- #include <sys/stat.h>
-
- /*
- * Local functions.
- */
-
- static int uucp_copy();
-
- /*----------------------------------------------------------------------
- * Send mail to UUCP addresses (if any).
- * This is a simple implementation: invoke uux once per address.
- */
-
- uucp_deliver()
- {
- struct stat st;
- DEST *d;
- char *uux;
- static char uux1[] = "/bin/uux";
- static char uux2[] = "/usr/bin/uux";
-
- if (stat(uux1, &st) == 0)
- uux = uux1;
- else if (stat(uux2, &st) == 0)
- uux = uux2;
- else
- {
- error("can't find uux!?\n");
- return;
- }
-
- for (d = first_dest(); d; d = next_dest(d))
- {
- FILE *uux_fp;
- char *bang;
- char *av[5];
- char rmail[40];
- char who[BUFSIZ];
-
- if (d->class != CL_UUCP || d->state != ST_WORKING)
- continue;
-
- if (printaddrs)
- (void) printf("%s\n", d->name);
-
- if (dryrun)
- {
- d->state = ST_DONE;
- continue;
- }
-
- bang = strchr(d->name, '!');
- *bang = 0;
- (void) sprintf(rmail, "%s!rmail", d->name);
- *bang++ = '!';
- (void) sprintf(who, "(%s)", bang);
-
- av[0] = "uux";
- av[1] = "-";
- av[2] = rmail;
- av[3] = who;
- av[4] = NULL;
- if ((uux_fp = ct_popenv(eff_ct, uux, av, "w")) == NULL)
- continue;
-
- if (uucp_copy(uux_fp) < 0)
- {
- d->state = ST_ERROR;
- d->error = "Error piping to uux";
- }
-
- if (ct_pclose(uux_fp))
- {
- /* Overrides any problems with uucp_copy() */
-
- d->state = ST_ERROR;
- d->error = "UUCP not available to that host";
- }
- else
- d->state = ST_DONE;
- }
- }
-
- /*----------------------------------------------------------------------
- * Write the message for UUCP transmission to the given file.
- */
-
- static int
- uucp_copy(ofp)
- FILE *ofp;
- {
- FILE *ifp;
- char *p;
- register int c;
- int fd;
- char buf[BUFSIZ];
-
- if ((fd = dup(tfd[T_HEADER])) == -1)
- {
- syserr("can't dup header fd");
- return -1;
- }
- (void) lseek(fd, 0L, 0);
- if ((ifp = fdopen(fd, "r")) == NULL)
- {
- error("can't fdopen header fd");
- return -1;
- }
-
- /*
- * Copy the header, but tack "remote from" onto the end of the
- * From_ line. (If it weren't for dealing with the From_ line,
- * I'd skip stream I/O altogether and use read/write. Maybe
- * I should save the length of the From_ line when I copy it...)
- */
-
- (void) fgets(buf, GETSIZE(buf), ifp);
- if ((p = strchr(buf, '\n')) != NULL)
- *p = 0;
- (void) fprintf(ofp, "%s remote from %s\n", buf, hostname);
-
- while ((c = getc(ifp)) != EOF)
- (void) putc(c, ofp);
-
- (void) fclose(ifp);
-
- /*
- * Copy the body
- */
-
- if ((fd = dup(tfd[T_BODY])) == -1)
- {
- syserr("can't dup body fd");
- return -1;
- }
- (void) lseek(fd, 0L, 0);
- if ((ifp = fdopen(fd, "r")) == NULL)
- {
- error("can't fdopen body fd");
- (void) close(fd);
- return -1;
- }
-
- while ((c = getc(ifp)) != EOF)
- (void) putc(c, ofp);
-
- (void) fclose(ifp);
- return 0;
- }
-