* Copyright (c) 1992 Eric P. Allman
* Copyright (c) 1992 Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1992 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)mldistrib.c 5.6 (Berkeley) %G%";
#define CHARNULL ((char *) NULL)
enum copymode
{RETAIN
, DISCARD
};
char *mailer_opts
[MAXMAILOPTS
+1];
char **next_opt
= mailer_opts
;
extern FILE *openmailer();
extern char *readheadertag();
extern void copyheader();
extern void dropheader();
if (strcmp(argv
[0], "-d") == 0)
if (next_opt
>= &mailer_opts
[MAXMAILOPTS
])
"%s: too many mailer options\n", myname
);
"Usage: %s [-mailopts ...] listname ownername member...\n",
/* consume and discard leading "From_" line */
while ((c
= fgetc(stdin
)) != EOF
&& c
!= '\n')
/* open the connection to the mailer */
mailfp
= openmailer(ml_owner
, next_opt
- mailer_opts
, mailer_opts
,
/* output the Resent-xxx: fields */
fprintf(mailfp
, "Resent-To: %s\n", ml_name
);
fprintf(mailfp
, "Resent-From: %s\n", ml_owner
);
fprintf(mailfp
, "Sender: %s\n", ml_owner
);
** Precedence: retain; mark that it has been seen
while ((p
= readheadertag(stdin
)) != CHARNULL
)
if (sameword(p
, "errors-to", 10))
if (sameword(p
, "precedence", 11))
if (sameword(p
, "return-path", 12) ||
sameword(p
, "received", 9) ||
sameword(p
, "resent-", 7))
if (sameword(p
, "sender", 7))
if (sameword(p
, "via", 4))
if (sameword(p
, "x-mailer", 9))
fprintf(mailfp
, "%s", p
);
copyheader(stdin
, mailfp
);
/* if no precedence was given, make it bulk mail */
fprintf(mailfp
, "Precedence: bulk\n");
/* copy the body of the message */
/* clean up the connection */
exit (my_pclose(mailfp
));
** OPENMAILER -- open a connection to the mailer
openmailer(from
, nopts
, opts
, argc
, argv
)
static char mailer
[] = _PATH_SENDMAIL
;
extern char *malloc(), *rindex();
* allocate space for argv; 4 args below, a null,
* and options and arguments from caller.
args
= (char **) malloc((nopts
+ argc
+ 5) * sizeof(char *));
if (args
== (char **) NULL
)
"%s: arg list too long; can't allocate memory!?\n", myname
);
if ((name
= rindex(mailer
, '/')) != CHARNULL
)
bcopy((char *) opts
, (char *) argp
, nopts
* sizeof(*opts
));
bcopy((char *) argv
, (char *) argp
, argc
* sizeof(*argv
));
printf("| %s, args:\n", _PATH_SENDMAIL
);
for (argp
= args
; *argp
; argp
++)
mailfp
= my_popen(mailer
, args
, "w");
fprintf(stderr
, "%s: Unable to popen %s\n", myname
,
** DROPHEADER -- drop a single header field
while ((c
= fgetc(infp
)) != EOF
)
/* look at next character to check for continuation */
if (c
== ' ' || c
== '\t')
** COPYHEADER -- copy a single header field
while ((c
= fgetc(infp
)) != EOF
)
/* look at next character to check for continuation */
if (c
== ' ' || c
== '\t')
** READHEADERTAG -- read and return the name of a header field
static char buf
[MAXHDRTAG
+ 1];
} while (--i
> 0 && c
!= EOF
&& c
!= '\0' &&
strchr(" \t\n:", c
) == CHARNULL
);
** COPYBODY -- copy the body of a message
while ((c
= fgetc(infp
)) != EOF
)
** SAMEWORD -- return true if two words are identical. The first
** word is case insignificant; the second must be lower case.
for (; --len
>= 0; test
++, pat
++)
if (isupper(*test
) && tolower(*test
) == *pat
)
static char sccsid[] = "@(#)popen.c 5.12 (Berkeley) 4/6/90";
* This code is derived from software written by Ken Arnold and
* published in UNIX Review, Vol. 6, No. 8.
* modified to avoid sh, be safe for setuid/setgid programs,
* and simplified to support only one popen'ed stream.
my_popen(program
, args
, type
)
if (*type
!= 'r' && *type
!= 'w' || type
[1])
if (pdes
[1] != STDOUT_FILENO
) {
(void)dup2(pdes
[1], STDOUT_FILENO
);
if (pdes
[0] != STDIN_FILENO
) {
(void)dup2(pdes
[0], STDIN_FILENO
);
/* parent; assume fdopen can't fail... */
iop
= fdopen(pdes
[0], type
);
iop
= fdopen(pdes
[1], type
);
omask
= sigblock(sigmask(SIGINT
)|sigmask(SIGQUIT
)|sigmask(SIGHUP
));
wpid
= waitpid(pid
, &pstat
, 0);
} while (wpid
== -1 && errno
== EINTR
);
return (pid
== -1 ? -1 : pstat
);