[net.sources] the rest of vnews

chuqui@nsc.UUCP (06/10/84)

#! /bin/sh
# The rest of this file is a shell script which will extract:
# vnews.help follow reply recmail.c
echo x - vnews.help
cat >vnews.help <<'!!ChuquiCo!!Software!!'
Vnews commands:    (each may be preceded by a non-negative )

CR  Next page or article                D   Decrypt a rot 13 joke
n   Go to next article                  A   Go to article numbered count
e   Mark current article as unread      <   Go to article with given ID
+   Go forwards count articles          p   Go to parent article
b   Go to previous article              ug  Unsubscribe to this group
^B  Go backwards count pages            ^L  Redraw screen
^N  Go forward count lines              v   Print netnews version
^P  Go backwards count lines            q   Quit
^D  Go forward half a page              ^\  Quit without updating .newsrc
^U  Go backwards half a page            c   Cancel the current article
h   Display article header              ?   Display this message
!   Escape to shell			K   Punt rest of newsgroup
r   Reply to article
f   Post a followup article
l   Display article (use after !, r, f, or ?)
s   Save article in file
w   Save without header
N   Go to newsgroup (next is default)

[Press l to see article again]
!!ChuquiCo!!Software!!
echo x - follow
cat >follow <<'!!ChuquiCo!!Software!!'
trap : 2 3
/bin/cp $1 /tmp/fol$$a
A=$2 ${EDITOR-ed} $1 $2
if /bin/cmp -s $1 /tmp/fol$$a
then	/bin/rm -f $1 /tmp/fol$$a
	exit 22
fi
(
	trap '' 1 2 3
	inews -h < $1
	x=$?
	sleep 60	# wait for inews to finish
	if test -s /tmp/fol$$b -o $x != 0
	then	(
			/bin/echo 'Subject: followup failed'
			/bin/echo ''
			/bin/cat /tmp/fol$$b
			/bin/echo ''
			/bin/echo 'Your article follows:'
			/bin/cat $1
		) | mail "${LOGNAME-$USER}"
	fi
	/bin/rm -f $1 /tmp/fol$$a /tmp/fol$$b

) > /tmp/fol$$b 2>&1 &
exit 0
!!ChuquiCo!!Software!!
echo x - reply
cat >reply <<'!!ChuquiCo!!Software!!'
trap : 2 3
/bin/cp $1 /tmp/mailr$$a
A=$2 ${EDITOR-ed} $1 $2
if /bin/cmp -s $1 /tmp/mailr$$a
then	rm -f $1 /tmp/mailr$$a
	exit 22
fi
(
	trap '' 1 2 3
	/usr/lib/news/recmail <$1
	x=$?
	if test $x != 0
	then	(
			/bin/echo 'Subject: reply command failed'
			/bin/echo ''
			/bin/cat /tmp/mailr$$b
			/bin/echo ''
			/bin/echo 'Your letter follows:'
			/bin/cat $1
		) | mail "${LOGNAME-$USER}"
	fi
	rm -f $1 /tmp/mailr$$a /tmp/mailr$$b
) > /tmp/mailr$$b 2>&1 &
exit 0
!!ChuquiCo!!Software!!
echo x - recmail.c
cat >recmail.c <<'!!ChuquiCo!!Software!!'
/*
 * recmail: read a mail message on stdin, grab all addresses in To and Cc
 * lines, and pass the full message to all addressees.  This is useful to
 * send the output of a recently edited mail message (with headers edited too).
 * It is similar to sendmail -t, but only assumes /bin/mail.
 * To use your own mailer, e. g. nmail, compile with -DMAILER=my_mailer.
 */
static char *sccsid = "@(#)recmail.c	1.2	3/30/83";

#include <stdio.h>
#include <ctype.h>

#ifndef MAILER
#define MAILER "mail"
#endif

#define MAXRECIPS 100
char *recips[MAXRECIPS];
int nrecips = 0;

main(argc, argv)
char **argv;
{
	FILE *fd;
	char *tmpf;
	char linebuf[1024];
	char *mailer = MAILER;
	int i, pid, wpid;
	int exstat;
	char *mypath;
	int goodcnt, badcnt;
	char *mktemp(), *getenv();
/* variables for .signature append code */
	FILE *infp;
	int c;
	char bfr[BUFSIZ];

	tmpf = mktemp("/tmp/rmXXXXXX");
	close(creat(tmpf,0666));
	fd = fopen(tmpf, "w");
	goodcnt = badcnt = 0;

	while (fgets(linebuf, sizeof linebuf, stdin) != NULL) {
		if (fputs(linebuf, fd) == EOF) {
werror:			printf("write error on temp file\n");
			exit(2);
		}
		if (linebuf[0] == '\n')
			break;
		if (strncmp(linebuf, "To: ", 4) == 0 ||
		    strncmp(linebuf, "to: ", 4) == 0 ||
		    strncmp(linebuf, "TO: ", 4) == 0 ||
		    strncmp(linebuf, "Cc: ", 4) == 0 ||
		    strncmp(linebuf, "cc: ", 4) == 0 ||
		    strncmp(linebuf, "CC: ", 4) == 0)
			addrecips(linebuf+4);
	}
	if (!feof(stdin)) {
		while (fgets(linebuf, sizeof linebuf, stdin) != NULL)
			if (fputs(linebuf, fd) == EOF)
				goto werror;
	}
/* This section of code will append your .signature file to mail replies
 * so that they are consistent with followups and so you don't need to 
 * hassle trying to do so yourself. 
 *
 * This should probably be turned on and off by an environment variable,
 * but who really cares?
 */
	sprintf(bfr, "%s/%s", getenv("HOME"), ".signature");
	if ((infp = fopen(bfr,"r")))
	{
	    fprintf(fd,"--- \n");
	    while ((c = getc(infp)) != EOF)
		putc(c,fd);
	    fclose(infp);
	}
	fclose(fd);

	/*
	 * Force the path to only consider /bin and /usr/bin, since
	 * that's the version of mail we want (not /usr/ucb/mail)
	 * This code will probably cause a core dump some day.
	 */
	mypath = getenv("PATH");
	if (mypath)
		strcpy(mypath, "/bin:/usr/bin");

	/*
	 * We send the copies out separately, because of a bug in
	 * USG's /bin/mail which will generate ANOTHER To: line,
	 * even though we already have one, if there are at least
	 * two recipients.
	 */
	for (i=0; i<nrecips; i++) {
		/*
		 * mail recips[i] < tmpf
		 */
		while ((pid = fork()) == -1) {
			fprintf(stderr, "fork failed, waiting...\r\n");
			sleep(60);
		}
		if (pid == 0) {
			close(0);
			open(tmpf, 0);
			execlp(mailer, mailer, recips[i], 0);
			perror(mailer);
			exit(1);
		}
		exstat = -1;
		while ((wpid = wait(&exstat)) >= 0 && wpid != pid)
			;
		if (exstat == 0)
			goodcnt++;
		else
			badcnt++;
	}
	if (badcnt) {
		if (goodcnt)
			printf("recmail: couldn't send mail to all recipients\n");
		else
			printf("recmail: couldn't send mail\n");
		exit(1);
	} else if (goodcnt == 0) {
		printf("no 'To:' line\n");
		exit (2);
	}
	exit (0);
}

#define isok(c) (isprint(c) && (c) != ' ' && c != ',')
addrecips(line)
char *line;
{
	char *front, *back, *tail;
	char *malloc();

	tail = line + strlen(line);
	for (front=line; front < tail; ) {
		while (!isok(*front) && front < tail)
			front++;
		for (back=front; isok(*back); back++)
			;
		*back=0;
		if (nrecips >= MAXRECIPS) {
			printf("Too many destinations\n");
			exit(2);
		}
		if ((recips[nrecips] = malloc(strlen(front) + 1)) == NULL) {
			printf("Out of space\n");
			exit(2);
		}
		strcpy(recips[nrecips], front);
		nrecips++;
		front = back+1;
	}
}
!!ChuquiCo!!Software!!
-- 
>From the ledge of the seventh cornice:			Chuq Von Rospach
{amd70,fortune,hplabs,ihnp4}!nsc!chuqui			(408) 733-2600 x242

If you let a smile be your umbrella you will get rain up your nose.