From mit-eddie!edg.cv.co.uk!kquinlan Mon Aug 12 02:26:54 1991
Return-Path: <mit-eddie!edg.cv.co.uk!kquinlan>
Received: by minya.uucp (/\=-/\ Smail3.1.18.1 #18.16)
	id <m0k9Vjn-0005vcC@minya.uucp>; Mon, 12 Aug 91 02:26 EDT
Received:  by EDDIE.MIT.EDU with UUCP (5.65/25-eef)
	id AA20569; Mon, 12 Aug 91 00:40:37 -0400
Received: from relay2.UU.NET by rutgers.edu (5.59/SMI4.0/RU1.4/3.08) 
	id AA16439; Fri, 9 Aug 91 13:30:06 EDT
Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
	(5.61/UUNET-internet-primary) id AA21652; Fri, 9 Aug 91 13:30:06 -0400
Received: from mcsun.UUCP by uunet.uu.net with UUCP/RMAIL
	(queueing-rmail) id 132949.4457; Fri, 9 Aug 1991 13:29:49 EDT
Received: from kestrel.ukc.ac.uk by mcsun.EU.net with SMTP;
	id AA28916 (5.65a/CWI-2.101); Fri, 9 Aug 1991 19:24:41 +0200
Received: from brunel.ac.uk by kestrel.Ukc.AC.UK   via Janet (UKC CAMEL FTP)
           id aa12010; 9 Aug 91 18:20 BST
Received: from edg.cv.co.uk by Echo.brunel.ac.uk via JANET with NIFTP (PP) 
          id <11541-0@Echo.brunel.ac.uk>; Fri, 9 Aug 1991 18:19:35 +0100
Received: from haley.Prime.COM by cvedg.Prime.COM; Fri, 9 Aug 91 18:19:14 +0100
Received: by haley.Prime.COM (4.1/SMI-3.0DEV3) id AA00827;
          Fri, 9 Aug 91 18:19:10 BST
Date: Fri, 9 Aug 91 18:19:10 BST
From: Kevin Quinlan <mit-eddie!edg.cv.co.uk!kquinlan>
Message-Id: <9108091719.AA00827@haley.Prime.COM>
X-Address: Prime Computervision R&D, Penn St., Amersham, Bucks., HP7 0PX, UK
X-Telephone: +44 494 714771
X-Fax: +44 494 716078
To: mit-eddie!minya!jc
Subject: Re: How to forward mail to news?
Newsgroups: news.software.b
In-Reply-To: <1001@minya.UUCP>
Cc: 
Sender: mit-eddie!edg.cv.co.uk!kquinlan


Here is a script that comes with the uk-sendmail (a sendmail.cf "compiler").
It is copyright but freely distributable.  Simply pipe your mail
message through this script (on a machine that can run inews!)

I also have a hacked version of this script a little to get news into
mail, for some people here who want the contents of some internal
newsgroups in their mailboxes. 

If you run sendmail you may be interested to know that uk-sendmail.2.1
allows you to specify a news "channel" where you can post news merely
by sending mail to a newsgroup, so to post a message to
news.software.b I simply say "mail news.software.b" and sendmail
eventually calls the attached script (called "mail-news") re-formats
the message and puts in into news"

I think Cnews also has a mailtonews script in the distribution kit.

Good Luck


Kevin Quinlan

------------------------------- CUT HERE -------------------------------
#!/bin/sh
#
#	mail-news release 2.0	Copyright Jem Taylor 1988
#
#	Remove To: Cc: Received: and Via: fields,
#	ensure that there is a Subject: line or make Subject: (none),
#	re-order header lines to give
#	From:
#	Subject:
#	Message-ID:
#	Date:
#	Sender:
#	and move any other header lines to after these
#

/bin/awk '
BEGIN {	true=1; false=0; head=true; subject="Subject: (none)"
	gateway="X-Mailer: mail-news 2.0.3"
	}
# From: and Sender: lines must be login@host (real name)
#			instead of real name <login@host>
# assume that <username> is one word - no quoted space - and at end of line
/^From:.*>$/ {	if (head==true)
	{	user=substr ( $NF, 2, length($NF) -2 )
		real = $2
		for ( i=3; i<NF; i++ ) real = real " " $i
		from =  "From: " user " (" real ")"
		next
	}
	}
/^Sender:.*>$/ { if (head==true)
	{	user=substr ( $NF, 2, length($NF) -2 )
		real = $2
		for ( i=3; i<NF; i++ ) real = real " " $i
		sender =  "Sender: " user " (" real ")"
		next
	}
	}
/^From:/	{ if (head==true) { from = $0 ; next } }
/^Sender:/	{ if (head==true) { sender = $0 ; next } }
/^Message-ID:/	{ if (head==true) { messageid = $0 ; next } }
/^Date:/	{ if (head==true) { date = $0 ; next } }

##insist Subject: has something in it!
/^Subject:.*[-=:)a-zA-Z@#!]/ {
			if (head==true) { subject=$0; next } }

## discard these and header continuation lines
/^Received:/||/^Via:/|| \
/^To:/||/^Cc:/||\
/^	/||/^ /	{ if (head==true) next }

## move any other header lines to end of header
/^.*:/		{ if (head==true) { others[++ocnt]=$0; next } }

## break between head and body - ensure subject in head
/^$/	{ if (head==true)
	{	head=false;
		if (from!="") print from
		print subject
		if (messageid!="") print messageid
		if (date!="") print date
		if (sender!="") print sender
		for (i=1;i<=ocnt;i++) print others[i]
		print gateway
		print ""
		next
	}
	}

## change inclusion mark since sender is not on hand ...
/^>/	{ if (head==false)
	{	print "|" substr( $0, 2, length - 1 )
		next
	}
	}

## all lines including body - unless explicitly skipped above
	{ print $0 }
' | /usr/local/lib/news/inews $@

