Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!columbia!chris
From: chris@columbia.UUCP (Chris Maio)
Newsgroups: news.software.b
Subject: Re: handling of moderated newsgroups in 2.11
Message-ID: <4096@columbia.UUCP>
Date: Sun, 14-Dec-86 23:57:15 EST
Article-I.D.: columbia.4096
Posted: Sun Dec 14 23:57:15 1986
Date-Received: Tue, 16-Dec-86 04:27:21 EST
References: <9732@sun.uucp> <2476@diamond.Diamond.BBN.COM> <9781@sun.uucp> <1354@munnari.oz> <10428@sun.uucp>
Reply-To: chris@columbia.edu (Chris Maio)
Organization: Columbia University CS Department
Lines: 236

Bill,

I had the same problems with 2.11's handling of moderated groups, and there are
problems with Robert Elz's suggestion, so I've been using the following setup
instead.  It requires modifying sendmail.cf and two inews source files, but
it's conceptually simpler to use once it's set up.

The changes below get rid of the extra headers inserted into articles (e.g.
"Subject: Submission to ...") posted to local moderated groups, and provide a
simpler alternative to recnews that allows inserting "approved" articles into
local moderated aliases.  Also, with these changes, there's no need to add
entries to /usr/lib/aliases or the sys file to forward messages between
newsgroups and mailing lists.

The sendmail.cf changes will have to be tweaked a bit to match your particular
configuration; but the news source changes and the shell script included are
site-independent.
						Chris

: This is a shar archive.  Extract with sh, not csh.
: The rest of this file will extract: README mail-to-inews news-patches
echo x - README
sed 's/^X//' > README << '//go.sysin dd *'
XFirst off, recnews is an inconvenient way to insert articles into newsgroups,
Xbecause (a) it requires a separate entry in /usr/lib/aliases for each
Xnewsgroup, (b) it only does a half-hearted job at hiding the differences
Xbetween mail and news articles (e.g. inserting a From: header into the body
Xof the message), and (c) it doesn't let you insert messages into moderated
Xgroups.  I got around this by adding a few lines to sendmail.cf, and writing
Xa simple shell script to replace recnews.  The sendmail mechanism below is
Xintended only to be used by "moderators" (be they human or just mail
Xreflectors), but you could duplicate it using a different naming convention
Xto provide something similar which doesn't "approve" articles on their way to
Xinews.  Briefly, when sendmail sees a local recipient address in the form
X"news.x.y" and "x.y" is a local newsgroup, the message is "approved" and
Xpassed to inews with the command "inews -a daemon@thishost -d x -n x.y -h".
X
XIn sendmail.cf, I use the following mailer definition to define an
Xinterface to inews from sendmail:
X
X	# The "inews" mailer provides an interface to netnews from mail.
X	# The "mail-to-inews" shell script provides a "Subject:" header if
X	# necessary and deletes the headers a little to make inews happy.
X	Minews,	P=/usr/lib/news/mail-to-inews, F=nF, S=14, M=50000,
X		A=inews -a daemon@$j -d $h -n $u -h
X
XThis rule says that mail delivered with this mailer is passed to the shell
Xscript "mail-to-inews", with arguments "-a daemon@thishost" to specify that
Xit's been "approved", with the Distribution: and Newsgroups: headers set from
Xthe hostname and username passed to the mailer.  S=14 says to use the TCP
Xruleset to rewrite the sender addresses appropriately.  The shell script just
Xdiddles the headers a little and invokes inews with the same arguments.
X
XThen add a rule to ruleset zero which invokes this "mailer" when an address
Xmatches a certain format, and define a class containing the allowable
Xtop-level groups.  For instance, the following statements:
X
X	# allow posting by mail to cu.all,cs.all (at top of sendmail.cf)
X	CN cu cs
X
X	# check for mail bound for inews (in ruleset zero, right before
X	# the comment "remaining names must be local")
X	Rnews.$=N.$*		$#inews$@$1$:$1.$2	news.cs.bboard
X
Xsay that articles mailed to "news.x.y" get posted to newsgroup "x.y" with
Xdistribution "x" as "approved" articles, iff "x" is one of the local
Xtop-level groups specified in the "CN..." statement (so randoms can't use
Xthis to post articles to non-local moderated groups).  To use this mechanism,
Xa human moderator (or mailing list) sends messages to "news.cs.bboard" to
Xinsert an "approved" article into the moderated "cs.bboard" newsgroup.  You
Xcan change the "$@$1" to "$@sun" to always specify "Distribution: sun" if
Xyour top-level newsgroup names don't correspond to your distributions.
X
XThe mail-to-inews shell script should be installed in /usr/lib/news, or
Xwherever you specified in the sendmail.cf file.  You may want to modify it to
Xchange the set of headers which is deleted, or reject messages with no
XSubject: header, etc.
X
XThe inews changes are relatively simple, and include a couple of bug fixes
Xfor From:/Path: header handling as well the modifications to how postings to
Xlocal moderated groups are handled.  Let me know if you have any questions
Xabout them.
//go.sysin dd *
echo x - mail-to-inews
sed 's/^X//' > mail-to-inews << '//go.sysin dd *'
X#!/bin/sh
Xinews=/usr/lib/news/inews
X
X# this script deletes empty and useless headers and inserts a dummy Subject:
X# header if necessary to clean up a mail message before passing it to inews.
Xawk 'BEGIN		{ subject = 0; body = 0; skipping = 0 }
Xbody == 1		{ print; next }
X/[A-Za-z-]*:[ ]*$/	{ next }
X/^$/		        {
X			    if (!body && !subject)
X				print "Subject: (none)"; 
X			    print; body = 1; next
X			}
X/^Subject: /		{ subject = 1; skipping = 0; print; next }
X/^Apparently-To:|^Received:|^From |^Return-Path:/ {
X				skipping = 1; next }
X/^[ 	]/		{ if (skipping) next }
X			{ print }
X' | $inews $*
Xexit 0
//go.sysin dd *
chmod +x mail-to-inews
echo x - news-patches
sed 's/^X//' > news-patches << '//go.sysin dd *'
XThe following diffs to the news 2.11 source (assuming patch #1 has
Xbeen applied) contain some minor bugfixes and changes to make sure that the
XFrom: headers passed by sendmail are converted into news-format From: and Path:
Xheaders properly.  Also, the handling for moderated groups is changed so that
Xunapproved articles posted to local moderated groups are mailed verbatim to the
Xaddress specified in the mailpaths file, rather than mailing the article with
Xthose funny headers prepended to an address built from the name of the
Xnewsgroup with all "."'s changed to "-"'s.  The behavior for postings to
Xmoderated groups not specifically mentioned in the mailpaths file is unchanged.
X
XRCS file: header.c,v
Xretrieving revision 1.1
Xdiff -c -r1.1 header.c
X*** /tmp/,RCSt1005952	Sun Dec 14 22:02:47 1986
X--- header.c	Sun Dec  7 17:48:54 1986
X***************
X*** 109,114 ****
X--- 109,118 ----
X  			fixfrom(hp);
X  	}
X  
X+ 	/* cm - call fixfrom anyway in case article was mailed, not posted */
X+ 	if (!wholething && hp->from[0] != '\0')
X+ 	    fixfrom(hp);
X+ 
X  	return fp;
X  }
X  
X***************
X*** 312,317 ****
X--- 316,323 ----
X  
X  	skin(pathbuf, fullname, hp->path);	/* remove RFC822-style comments */
X  	if (fullname[0] != '\0') {
X+ 		/* make sure fullname plus " ()" will fit */
X+ 		fullname[sizeof (fullname) - strlen (hp->from) + 3 - 1] = '\0';
X  		strcat(hp->from, " (");
X  		(void) strcat(hp->from, fullname);
X  		strcat(hp->from, ")");
X***************
X*** 336,341 ****
X--- 342,349 ----
X  
X  	skin(frombuf, fullname, hp->from);	/* remove RFC822-style comments */
X  	if (fullname[0] != '\0') {
X+ 		/* make sure fullname plus " ()" will fit */
X+ 		fullname[sizeof (fullname) - strlen (frombuf) + 3 - 1] = '\0';
X  		strcat(frombuf, " (");
X  		strcat(frombuf, fullname);
X  		strcat(frombuf, ")");
X***************
X*** 533,542 ****
X  	if (ptr == NULL)
X  		return FALSE;
X  	if (its("From: "))
X! 		if (index(ptr, '@') || !index(ptr, '!'))
X! 			return FROM;
X! 		else
X! 			return PATH;
X  	if (its("Path: "))
X  		return PATH;
X  	if (its("Newsgroups: "))
X--- 541,547 ----
X  	if (ptr == NULL)
X  		return FALSE;
X  	if (its("From: "))
X! 		return FROM;
X  	if (its("Path: "))
X  		return PATH;
X  	if (its("Newsgroups: "))
X===================================================================
XRCS file: inews.c,v
Xretrieving revision 1.1
Xdiff -c -r1.1 inews.c
X*** /tmp/,RCSt1005952	Sun Dec 14 22:02:58 1986
X--- inews.c	Sun Dec  7 23:49:06 1986
X***************
X*** 373,379 ****
X  			else if (!header.path[0]) {
X  				(void) strcpy(header.path, forgedname);
X  
X! 				if ((p1 = strpbrk(header.path, "@ (<")) != NULL)
X  					*p1 = '\0';
X  			}
X  			if (!Mflag && !strpbrk(forgedname, "@ (<"))
X--- 373,380 ----
X  			else if (!header.path[0]) {
X  				(void) strcpy(header.path, forgedname);
X  
X! 				/* cm - took "@" out of break char set */
X! 				if ((p1 = strpbrk(header.path, " (<")) != NULL)
X  					*p1 = '\0';
X  			}
X  			if (!Mflag && !strpbrk(forgedname, "@ (<"))
X***************
X*** 771,776 ****
X--- 772,798 ----
X  					LIBDIR);
X  		} while (strcmp(bfr, "backbone") != 0 && !ngmatch(is_mod, bfr));
X  		(void) fclose(mfd);
X+ 
X+ 		/* cm - begin addition */
X+ 		/* local moderated groups are handled a bit differently */
X+ 		if (strcmp (bfr, "backbone") != 0) {
X+ 		    FILE *mhopen ();
X+ 		    /* fake a header for mhopen to derive a sender from */
X+ 		    bzero (&mhdr, sizeof mhdr);
X+ 		    sprintf (mhdr.path, modadd, is_mod);
X+ 		    if ((mfd = mhopen (&mhdr)) != NULL) {
X+ 			hwrite (&header, mfd);
X+ 			while ((c = getc(infp)) != EOF)
X+ 			    putc(c, mfd);
X+ 			mclose(mfd);
X+ 			log("Article mailed to %s", mhdr.path);
X+ 			xxit(0);
X+ 		    }
X+ 		    else
X+ 			xerror("Can't send mail to %s", mhdr.path);
X+ 		}
X+ 		/* cm - end addition */
X+ 
X  		/* fake a header for mailhdr */
X  		mhdr.from[0] = '\0';
X  		mhdr.replyto[0] = '\0';
X
//go.sysin dd *
exit