[news.software.b] Mail -> News gateway

john@jwt.UUCP (John Temples) (11/22/89)

I'd like to be able to route incoming mail from a mailing list into a local
newsgroup.  Is there software available to do this?  I tried using
'deliver' to do this, by grepping the "Subject:" and "Reply-To:"
headers from the mail message, adding "Newsgroups:" and
"Distribution:", and feeding the result into inews -h.  This works, but
has a couple of problems: my .signature gets appended to all of the
articles, and when Rnmail is invoked via "R" from rn, it ignores the
"Reply-To" header and sends the mail back to me.  Any suggestions?
-- 
John Temples -- UUCP: uunet!jwt!john

chip@ateng.com (Chip Salzenberg) (11/23/89)

According to john@jwt.UUCP (John Temples):
>I'd like to be able to route incoming mail from a mailing list into a local
>newsgroup.  Is there software available to do this?  I tried using 'deliver'
>[... but:] my .signature gets appended to all of the articles, and when
>Rnmail is invoked via "R" from rn, it ignores the "Reply-To" header and
> sends the mail back to me.  Any suggestions?

I earlier posted a version of my "del.news" script, which can be used with
Deliver to gateways mail to news.  However, it had some faults.  The version
I've enclosed below deals with:

	Newsgroups, Distribution, Subject
	From, Sender
	Message-ID, References

Note that this script retains the mail's Message-Id.  It also translates the
In-Reply-To header into a one-item References header, for use with modern
newsreaders.

It also changes the HOME directory of the inews program to somewhere that
it won't find a ".signature" file.

(Thanks to Bret Orsburn <bret@codonics.COM> for prodding me to fix the
From handling.)

This New and Improved del.news script, along with a sample post-user
delivery file that calls it, is sharchived below.  If you use the enclosed
post-user file, mail to "news-newsgroup" is posted to "newsgroup".

Shar and enjoy.

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  del.p.news del.news
# Wrapped by chip@ateng on Wed Nov 22 14:16:12 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'del.p.news' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'del.p.news'\"
else
echo shar: Extracting \"'del.p.news'\" \(617 characters\)
sed "s/^X//" >'del.p.news' <<'END_OF_FILE'
X: del.p.news
X# A post-user delivery file to demonstrate news delivery.
X# Requires the "del.news" script.
X
X# Handle normal addresses, and accumulate newsgroup names.
X
XGROUPS=
X
Xfor u
Xdo
X    case "$u" in
X    news[\-\.]*)
X	group=`echo $u | sed -e 's/^news.//' -e 'y/-/./'`
X	if [ "$GROUPS" ]
X	then
X	    GROUPS="${NEWSGROUPS},${group}"
X	else
X	    GROUPS="${group}"
X	fi
X	;;
X    *)
X	echo "$u"
X	;;
X    esac
Xdone
X
X# Post to any newsgroup(s).
X
Xif [ "$GROUPS" ]
Xthen
X    case "$DELFLAGS" in
X    *[dA]*)
X	# Dry Run
X	echo >&2 "$0: post to $GROUPS"
X	;;
X    *)
X	/usr/local/lib/del.news local "$GROUPS"
X	;;
X    esac
X
X    echo DROP
Xfi
END_OF_FILE
if test 617 -ne `wc -c <'del.p.news'`; then
    echo shar: \"'del.p.news'\" unpacked with wrong size!
fi
# end of 'del.p.news'
fi
if test -f 'del.news' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'del.news'\"
else
echo shar: Extracting \"'del.news'\" \(2265 characters\)
sed "s/^X//" >'del.news' <<'END_OF_FILE'
X: del.news
X# Shell script run by post-user delivery file.
X
Xif [ $# -ne 2 ]
Xthen
X    echo >&2 "usage: $0 distribution newsgroups"
X    exit 1
Xfi
X
XDIST="$1"
XGROUPS="$2"
X
X#-----------------------------------------------------------------------
X# Configuration
X#-----------------------------------------------------------------------
X
XMAILNAME=/usr/lib/news/mailname     # C News -- mail name of org/host
XFAKEHOME=/usr/local/lib             # Fake HOME for inews - no signature
X
X[ -s $MAILNAME ] && MHOST=`sed 1q $MAILNAME`
X[ "$MHOST" ] || MHOST=$HOST.UUCP
X
X#-----------------------------------------------------------------------
X# Figure out who is posting it.
X# That's the user name if local; otherwise, the Usenet owner.
X# Export this value as LOGNAME, so inews can use it.
X#-----------------------------------------------------------------------
X
Xcase "$SENDER" in
X*!*)    LOGNAME=news ;;
X*)      LOGNAME=$SENDER ;;
Xesac
Xexport LOGNAME
X
X#-----------------------------------------------------------------------
X# Generate the news article and feed it to inews.
X#-----------------------------------------------------------------------
X
X(
X    # Newsgroups
X    echo "Newsgroups: $GROUPS"
X
X    # Distribution (if not world)
X    [ "$DIST" = "world" ] || echo "Distribution: $DIST"
X
X    # Subject
X    header -n -f Subject $HEADER
X
X    # From
X    from=`header -f From $HEADER`
X    case "$from" in
X    *@*)
X	echo "From: $from" ;;
X    *)
X	case "$SENDER" in
X	*!*)
X	    u=`expr "$SENDER" : '.*!\(.*\)$'`
X	    h=`expr "!$SENDER" : '.*!\([^!]*\)![^!]*$'`
X	    case "$h" in
X	    *.*)    ;;
X	    *)      h="$h.UUCP" ;;
X	    esac
X	    ;;
X	*)
X	    u="$SENDER"
X	    h=$MHOST
X	    ;;
X	esac
X	c=`expr "$from" : '.*\( ([^)]*)\).*$'`
X	echo "From: $u@$h$c"
X	;;
X    esac
X
X    # Sender
X    echo "Sender: usenet@$MHOST"
X
X    # Message-ID (optional)
X    x=`header -f message-id $HEADER`
X    [ "$x" ] && echo "Message-ID: $x"
X
X    # References (optional)
X    x=`header -f in-reply-to $HEADER`
X    x=`expr "$x" : '.*\(<[^>]*>\).*$'`
X    [ "$x" ] && echo "References: $x"
X
X    # Separator
X    echo ""
X
X    # Body (without gratuitous blank line at the end)
X    sed '${/^$/d;}' $BODY
X) |
X    HOME=$FAKEHOME /usr/lib/news/inews -h
X
X## Save a copy of the mail for debugging purposes
X#echo news:Posted
END_OF_FILE
if test 2265 -ne `wc -c <'del.news'`; then
    echo shar: \"'del.news'\" unpacked with wrong size!
fi
chmod +x 'del.news'
# end of 'del.news'
fi
echo shar: End of shell archive.
exit 0
-- 
You may redistribute this article only to those who may freely do likewise.
Chip Salzenberg at A T Engineering;  <chip@ateng.com> or <uunet!ateng!chip>
    "Did I ever tell you the Jim Gladding story about the binoculars?"

jthomp@texsun.Central.Sun.COM (Jim Thompson ) (12/02/89)

In article <476@jwt.UUCP> john@jwt.UUCP (John Temples) writes:
>
>I'd like to be able to route incoming mail from a mailing list into a local
>newsgroup.  Is there software available to do this?  I tried using
>'deliver' to do this, by grepping the "Subject:" and "Reply-To:"
>headers from the mail message, adding "Newsgroups:" and
>"Distribution:", and feeding the result into inews -h.  This works, but
>has a couple of problems: my .signature gets appended to all of the
>articles, and when Rnmail is invoked via "R" from rn, it ignores the
>"Reply-To" header and sends the mail back to me.  Any suggestions?

Two suggestions:

1) Use the software written by either Erik Fair or Rich $alz
that does this.  Erik wrote it for the 'inet' group gateway
he runs.  Rich rewrote much of Erik's work in 'C'.

2) Do what I do and hack 'recnews' enough that it
gets the Reply-To, Path, and References headers right

Combine this with a custom (sendmail) mailer on the gateway machine
that recognizes the incomming group names and calls the above recnews
with appropriate args.  (After munging the From: line into something
reasonable..)

I like the 2nd approach because it eliminates keeping 'both' 
sets of aliases up-to-date.  I use a simple 'news.group-name'
pattern in the bottom of ruleset 0.  (i.e. the prepended 'news.'
tells sendmail that "this is a newsgroup..")  You can even send to
multiple groups (cross-posting) with this method.

I do like some of the methodology in R$'s stuff, like the ability
to do really evil things like say "this user said 'want' in the
subject line, but posted to a 'forsale' group, so move it to 'foo.wanted'.
It also has the ability to filter 'please add me to this list' out
of the incomming stream.  (Oh yea, both Erik's and R$'s work will
post to multiple newsgroups as well.  I didn't mean to imply that
my method was better, just more convienent for me.)

Jim
--


Jim Thompson - Network Engineering - Sun Microsystems -	jthomp@central.sun.com
Member of the Fatalistic International Society for Hedonistic Youth (FISHY)
"I woudn't recommend sex, drugs, or unix for everyone, but they work for me."
					- Me (paraphrasing Hunter S. Thompson)