diff options
author | Matěj Cepl <mcepl@redhat.com> | 2014-07-24 14:45:29 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2014-07-24 14:45:29 +0200 |
commit | b140c056546efdfa69fa48098db8eef7b45077c0 (patch) | |
tree | ee2dd059ab5f2c3fb0391fd092f509c494b2d0c1 /examples/drhyde-news2mail-and-mail2news/mail2news | |
parent | f03c3eac2c17e730f4da66ac28acec978c18c20e (diff) | |
download | pygn-b140c056546efdfa69fa48098db8eef7b45077c0.tar.gz |
Adding examples and documents
Diffstat (limited to 'examples/drhyde-news2mail-and-mail2news/mail2news')
-rw-r--r-- | examples/drhyde-news2mail-and-mail2news/mail2news | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/drhyde-news2mail-and-mail2news/mail2news b/examples/drhyde-news2mail-and-mail2news/mail2news new file mode 100644 index 0000000..1f026a0 --- /dev/null +++ b/examples/drhyde-news2mail-and-mail2news/mail2news @@ -0,0 +1,58 @@ +#!/usr/local/bin/perl + +use warnings; +use strict; + +use Data::Dumper; +use Net::NNTP; +use News::Article; + +use constant DEBUG => 0; + +select(STDERR); $| = 1; select(STDOUT); + +die("mail2news hasn't been configured.\n") unless(-r '/etc/mail2newsrc'); + +my $subs = { do '/etc/mail2newsrc' }; + +my $group = shift; +die("mail2news must be told what group to post to\n") unless($group); + +my $article = News::Article->new(); +$article->read(\*STDIN); +$article->set_headers(Newsgroups => $group); +$article->drop_headers(qw(date to received)); +$article->add_date(); + +my $posted_ok = 0; +foreach my $server (grep { $subs->{$_}->{$group} } keys %{$subs}) { + my($auth, $host) = split('@', $server); + ($auth, $host) = (':', $auth) if(!$host); + my($user, $pass) = split(':', $auth); + ($host, my $port) = split(':', $host); + $port ||= 119; + + my $client = Net::NNTP->new($host, Port => $port); + $client->authinfo($user => $pass) if($user); + + unless($client->postok()) { + print STDERR "mail2news configured to post to $group via\n". + "$server, but it didn't say we can post. Bother and damnation!\n"; + next; + } + + eval { $article->post($client); }; + die("Error in posting to $server: $@\n") if($@); + $posted_ok++; +} + +if(!$posted_ok) { + die "mail2news couldn't post to $group on any configured server.\n\n". + "Your message read:\n\n". + join("\n\n", + join("\n", $article->headers()), + join("\n", $article->body()) + )."\n\n". + "And the environment was:\n\n". + join("\n", map { join(":\t", $_, $ENV{$_}) } sort keys %ENV); +} |