#! /usr/bin/perl -w use strict; my $server="mailserver2002"; # NNTP server my $group="frontier.misc"; # group my $summarylength = 60; # maximum summary length, in characters my $since = 24*60*60; # retrieve messages up to this many seconds ago my $appendCGIheader = 1; # append CGI header? # ------------------- my $CRLF = "\015\012"; sub QuoteHtml { my ($html) = @_; $html =~ s/&/&/g; $html =~ s//>/g; if (1) { # Make an official option? $html =~ s/&([#a-zA-Z0-9]+);/&$1;/g; # Allow character references } $html =~ s/[\x80-\xFF]//g; return $html; } use Net::NNTP; my $nntp = Net::NNTP->new($server); my $timenow = $nntp->date(); $nntp->group($group); my $msgids = $nntp->newnews($timenow - $since); if($appendCGIheader) { print "Content-Type: text/xml".$CRLF.$CRLF; } print <
$group news:$group RSS feed of newsgroup $group on $server. nntp2rss.pl (moonshadow at toothycat.net) HEADER ; foreach my $msgid(@$msgids) { my $header = $nntp->head($msgid); my $body = $nntp->body($msgid); my $date=''; my $subject=''; my $summary = ''; # Join up body. Attempt to cull quoted text. foreach my $line(@$body) { if(($line =~ /^\>/) || ($line =~ /\> wrote in message/)) { # $summary .= '.'; } else { $summary .= $line; } } # Cull line breaks. $summary =~ s/\r//g; $summary =~ s/\n/ /g; # Trim to maximum length. if((length $summary) > $summarylength) { $summary = substr($summary, 0, $summarylength-3) . '...'; } # Cull illegal chars $summary = &QuoteHtml($summary); foreach my $headerline(@$header) { $headerline = &QuoteHtml($headerline); if ($headerline =~ /^Date: (.+)/) { $date = $1; } elsif ($headerline =~ /^Subject: (.+)/) { $subject = $1; } } print "\n $subject\n $date\n $summary\n\n\n"; } print ""; $nntp->quit;