* Copyright (c) 1981, 1988 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1981, 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)rmail.c 4.13 (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" */
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
, _PATH_DEVNULL
);
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
args
[i
++] = _PATH_SENDMAIL
;
args
[i
++] = "-oee"; /* no errors, just status */
args
[i
++] = "-odq"; /* queue it, don't try to deliver */
args
[i
++] = "-oi"; /* ignore '.' on a line by itself */
if (fsys
[0] != '\0') { /* set sender's host name */
if (index(fsys
, '.') == NULL
) {
(void) strcat(fsys
, ".");
(void) strcat(fsys
, Domain
);
(void) sprintf(junk2
, "-oMs%s", fsys
);
(void) sprintf(junk
, "-oMr%s", Domain
);
if (from
[0] != '\0') { /* set name of ``from'' person */
(void) sprintf(junk2
, "-f%s", from
);
for (; *++argv
!= NULL
; i
++) {
* don't copy arguments beginning with - as they will
* be passed to sendmail and could be interpreted as flags
* should be fixed in sendmail by using getopt(3), and
* just passing "--" before regular args.
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
execv(_PATH_SENDMAIL
, args
);
fprintf(stderr
, "Exec of %s failed!\n", _PATH_SENDMAIL
);