static char sccsid
[] = "@(#)rmail.c 4.9 (Berkeley) %G%";
* RMAIL -- UUCP mail server.
* This program reads the >From ... remote from ... lines that
* UUCP is so fond of and turns them into something reasonable.
* It calls sendmail giving it a -f option built from these lines.
char *Domain
= "UUCP"; /* Default "Domain" */
#define MAILER "/usr/lib/sendmail"
char lbuf
[1024]; /* one line of the message */
char from
[512]; /* accumulated path of sender */
char ufrom
[512]; /* user on remote system */
char sys
[512]; /* a system in path */
char fsys
[512]; /* first system in path */
char junk
[1024]; /* scratchpad */
char *args
[100]; /* arguments to mailer command */
register char *uf
= NULL
; /* ptr into ufrom */
if (argc
> 1 && strcmp(argv
[1], "-T") == 0) {
fprintf(stderr
, "Usage: rmail user ...\n");
if (argc
> 2 && strncmp(argv
[1], "-D", 2) == 0) {
(void) strcpy(ufrom
, "/dev/null");
for (position
= 0;; position
= ftell(stdin
)) {
(void) fgets(lbuf
, sizeof lbuf
, stdin
);
if (strncmp(lbuf
, "From ", 5) != 0 &&
strncmp(lbuf
, ">From ", 6) != 0)
(void) sscanf(lbuf
, "%s %s", junk
, ufrom
);
register char *p
= rindex(uf
, '!');
break; /* no "remote from" found */
if (strncmp(cp
, "remote from ", 12) == 0)
(void) sscanf(cp
, "remote from %s", sys
);
(void) strcpy(fsys
, sys
);
(void) strcat(from
, sys
);
(void) strcat(from
, "!");
printf("ufrom='%s', sys='%s', from now '%s'\n", uf
, sys
, from
);
if (uf
== NULL
) { /* No From line was provided */
fprintf(stderr
, "No From line in rmail\n");
(void) lseek(0, position
, L_SET
);
* Now we rebuild the argument list and chain to sendmail. Note that
* the above lseek might fail on irregular files, but we check for
if (index(fsys
, '.') == NULL
) {
(void) strcat(fsys
, ".");
(void) strcat(fsys
, Domain
);
(void) sprintf(junk2
, "-oMs%s", fsys
);
(void) sprintf(junk
, "-oMr%s", Domain
);
(void) sprintf(junk2
, "-f%s", from
);
for (; *++argv
!= NULL
; i
++) {
for (i
= 0; args
[i
]; i
++)
if ((sbuf
.st_mode
& S_IFMT
) != S_IFREG
) {
* If we were not called with standard input on a regular
* file, then we have to fork another process to send the
* first line down the pipe.
printf("Not a regular file!\n");
* Child: send the message down the pipe.
out
= fdopen(pipefd
[1], "w");
while (fgets(lbuf
, sizeof lbuf
, stdin
))
* Parent: call sendmail with pipe as standard input
fprintf(stderr
, "Exec of %s failed!\n", MAILER
);