Gnus development mailing list
 help / color / mirror / Atom feed
From: Michael Cook <cook@sightpath.com>
Subject: Re: Mail to news (and back again)
Date: 26 Sep 1999 14:41:19 -0400	[thread overview]
Message-ID: <80k8pdcy7k.fsf@lucy.sightpath.com> (raw)
In-Reply-To: Lars Magne Ingebrigtsen's message of "26 Sep 1999 19:27:42 +0200"

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]

Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> Is there some sort of ready-made procmail (or whatever) setup for
> having all the mail that's sent to, say "ding@quimby.gnus.org" spooled 
> in inn?  I guess one should run, er, rnews on the mail, after
> massaging it slightly.  (Like adding the Newsgroups: gnus.ding" header 
> and possibly renaming any offending headers (like NNTP-Posting-Host
> and the like.))

Here's what I use.


[-- Attachment #2: nntp-post --]
[-- Type: text/plain, Size: 3234 bytes --]

#!/usr/bin/perl -w
#
# Post a news article via an NNTP server.
#
# Example:
#  nntp-post \
#    --insert="Newsgroups: local.pokemon.d" \
#    --insert="Approved: cook" \
#    --delete=received \
#    files...
#
# Michael Cook <cook@sightpath.com>
# Thu Mar  6 22:39:14 EST 1997
#

use strict;
use Net::NNTP;
use Getopt::Long;

my @DELETE;
my @INSERT;
my $DUPLICATE;
my $NEWSGROUP;
my $HOST;
my $DEBUG;

Getopt::Long::config("bundling");
GetOptions
("--delete=s" => \@DELETE, "-d" => \@DELETE,
 #
 # Headers to remove.  Example: -d xref -d nntp-posting-host String is
 # caseless, not a pattern or regex, with no trailing colon.
 #

 "--insert=s" => \@INSERT, "-i" => \@INSERT,
 #
 # Headers to insert.  Example: -i "Approved: moi" String is inserted as-is,
 # with a newline appended.  (Deletes (--delete) are done before inserts.)
 #

 "--duplicate" => \$DUPLICATE, "-u" => \$DUPLICATE,
 #
 # If the server rejects the article claiming that it is a duplicate, remove
 # the Message-Id header and try again.
 #

 "--newsgroup=s" => \$NEWSGROUP, "-g=s" => \$NEWSGROUP,
 #
 # Same as: --delete=xref --delete=received --insert="Newsgroups: $NEWSGROUP"
 #

 "--host=s" => \$HOST, "-h=s" => \$HOST,
 #
 # Which host to connect to.
 # Default is defined in Net::NNTP.
 #

 "--debug" => \$DEBUG,
)
or die "usage: $0 [files...]\n";

if (defined $NEWSGROUP)
{
    push @DELETE, "xref";
    push @DELETE, "received";
    push @INSERT, "Newsgroups: $NEWSGROUP";
}

my %DELETE = map { lc($_) => 1 } @DELETE;
for (@INSERT) { $_ .= "\n" }

my @nntp = ($HOST);
push @nntp, Debug => 1
    if $DEBUG;
my $nntp = Net::NNTP->new(@nntp)
    or die "cannot connect to NNTP server";

@ARGV = ("-")
    unless @ARGV;

my $exit = 0;
for my $arg (@ARGV)
{
    unless (open FH, "< $arg")
    {
	warn "cannot open `$arg': $!";
	$exit = 1;
	next;
    }
    my @article = <FH>;
    close FH;

    print("original article:\n +----\n",
          (map { " | $_" } @article),
          " +----\n")
	if $DEBUG;

    for (@article)
    {
	s/\r$//;
    }

    my $lno = 0;
    if (@article && $article[0] =~ /^From /)
    {
	warn "(warning) eschewing unix `From ' line, first line of `$arg'";
	shift @article;
	$lno++;
    }

    my @header;
    while (@article && $article[0] !~ /^$/)
    {
	$_ = shift @article;
	$lno++;
	while (@article && $article[0] =~ /^[ \t]/)
	{
	    $_ .= shift @article;
	    $lno++;
	}
	unless (/^([^\s:]+):/)
	{
	    warn "(warning) file \"$arg\", line $lno: malformed header:\n--\n$_--";
	    push @header, $_;
	    next;
	}
	push @header, $_
	    unless $DELETE{lc($1)};
    }
    unshift @article, @header, @INSERT;

    print("posting article:\n +----\n",
          (map { " | $_" } @article),
          " +----\n")
	if $DEBUG;

    #next if $DEBUG;
    next if $nntp->post(\@article);
    my $msg = (reverse $nntp->message())[0];
    chomp $msg;
    if ($DUPLICATE && $msg =~ /^435 Duplicate$/)
    {
	warn "server says this message is a duplicate; retrying...";
	for (@article)
	{
	    $_ = "" if /^message-id:/i;
	    last if /^\n/;
	}
	next if $nntp->post(\@article);
	$msg = (reverse $nntp->message())[0];
	chomp $msg;
    }
    warn "failed to post `$arg': (" . $nntp->code() . ") $msg";
    $exit = 1;
}

$nntp->quit;
exit $exit;

[-- Attachment #3: Type: text/plain, Size: 1140 bytes --]


If you use sendmail on quimby, you might add an alias like this:

ding: "|/local/bin/nntp-post local.ding --delete=NNTP-Posting-Host"

Actually, to make the news-to-mail and mail-to-news gatewaying
complete, I'd setup the ding newsgroup as being moderated.  (Use an
`m' instead of a `y' as the 3rd argument to ctlinnd.)  Have
ding-moderator@gnus.org be the moderator (see the moderators file,
often /etc/news/moderators; see also moderators(5)).  Then, I'd
create aliases like this:

ding: ding-list ding-news

ding-list: :include:/whatever/lists/ding

ding-news: "|/local/bin/nntp-post local.ding
 --insert=Approved:auto
 --delete=NNTP-Posting-Host"

ding-moderator: ding

Or some such.

So, mail sent to `ding@gnus.org' goes to everyone on the mailing
list, and also gets fed to the nntp server after having an Approved
header added.

When someone posts an article to the newsgroup, it won't
(ordinarily) have the Approved header, and so inn will mail it to
ding-moderator.  Mail to ding-moderator gets forwarded to everyone
on the ding mailing list, and also gets fed back to the nntp server
after having the Approved header added.

M.

  parent reply	other threads:[~1999-09-26 18:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-26 17:27 Lars Magne Ingebrigtsen
1999-09-26 18:23 ` Lars Balker Rasmussen
1999-09-26 19:02   ` Lars Magne Ingebrigtsen
1999-09-26 20:22     ` Jason R Mastaler
1999-09-26 20:33       ` Lars Magne Ingebrigtsen
1999-09-26 18:33 ` Harry Putnam
1999-09-26 18:41 ` Michael Cook [this message]
1999-09-26 19:46   ` Eric Marsden
1999-09-27 14:09   ` Lars Magne Ingebrigtsen
1999-09-28  8:13     ` Steinar Bang
1999-11-05 23:03       ` Lars Magne Ingebrigtsen
1999-11-10 14:41         ` Steinar Bang
1999-11-10 17:04           ` Simon Josefsson
1999-11-11  7:39             ` Steinar Bang
1999-11-11 10:43               ` Simon Josefsson
1999-09-27  3:28 ` Russ Allbery
1999-09-27 14:29   ` Lars Balker Rasmussen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=80k8pdcy7k.fsf@lucy.sightpath.com \
    --to=cook@sightpath.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).