Subject: Re: mail-to-news gateway

From: Peter Marks <[email-masked]>
Date: Fri, 25 Feb 1994 01:19:55 -0800 (PST)

Here's my version of a mail-to-news gateway. I have an account set up on
"myhost" with the logname "mailnews". To post to a newsgroup, say alt.haha,
you either send mail with

  To: mailnews@myhost
  Newsgroups: alt.haha

or with

  To: mailnews@myhost (alt.haha)

[i.e., no need for the Newsgroups: field].  The latter form allows
newsgroups and email addresses to be freely intermixed (and is arguably
even in the spirit of RFC822:-) Multiple newsgroups are allowed, and two
conventions are additive.

Here's mailnews' .procmailrc. [The reason that the calculation of $GRPS
(the list of newsgroups) is broken up into so many steps is that sed breaks
when there is no terminal LF; so whenever I want to sed an 'unterminated'
string, I first pass it through echo it to append a LF.]

====== start of .procmailrc =====
PATH=/usr/local/bin:/usr/ucb:/usr/bin:/bin
MAILDIR=$HOME/News
LOGABSTRACT=no
LOGFILE=$MAILDIR/log
DEFAULT=$MAILDIR/mbox

POST=mailnews@myhost

# Pull out all the possible sources of newsgroup info

TO = `formail -xTo:`
CC = `formail -xCc:`
NGRPS = `formail -xNewsgroups:`

# Calculate the list of newsgroups:
# ....... Collapse To:+Cc: to single line of ,-separated addresses
GRPS = `echo "$TO, $CC" | tr -d "\012"`
# ....... Split into one address per line, drop addresses NOT containing $POST
GRPS = `echo $GRPS | tr "," "\012" | \
  sed -n -e "s/[^ ]*$POST[^ ]*//p"`
# ....... Merge Newsgroups:, remove extraneous characters, collapse lines
GRPS = `echo "$GRPS,$NGRPS" | tr -s ' ,()"\012' ','`
# ....... Remove any leading, trailing commas
GRPS = `echo $GRPS | sed -e "s/^,,*//" -e "s/,$//"`

# Set up the news headers: some deletions, some defaults in case of missing
# headers; only Newsgroups: is an unconditional replacement

:0fh
| formail -IFrom\  -IStatus: -IReceived: -ITo: -ICc: -IMessage-Id: \
          -a"Distribution: world" -I"Newsgroups: $GRPS" \
          -a"Organization: AT&T Global Information Solutions"

# Post article only if there are newsgroups

:0
*Newsgroups: *[^ ]
| inews
======= end of .procmailrc =====

P-)
         AT&T          
        Global         Peter Marks  <[email-masked]>
     Information       Technical TeleCommunity Center (206)489-0501
      Solutions        15307 NE 202nd Street, Woodinville, WA 98072 
         ++++