* Copyright (c) 1981, 1988 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
"@(#) Copyright (c) 1981, 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)rmail.c 4.15 (Berkeley) 5/31/90";
* 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
)) {
if (fgets(lbuf
, sizeof lbuf
, stdin
) == NULL
)
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
);