🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #32845

My program to post to moderate news groups.

#32845
From: Robert Sandford
Date: Wed, 11 Nov 1998 00:00
270 lines
8589 bytes
This is a multi-part message in MIME format.
--------------E9203468169A488DC18404A6
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Here is a copy of my perl program that I wrote to post to moderated
newsgroups.
I am not swearing by this but it works for me. It can handle mime
articles and even
can create an expire header to what ever future date you wish. It will
only post to a single newsgroup so crossposting is currently out of the
question. This was a quick and dirty program so don't judge my code.
Since several people requested a simple program I thought I would post
it. Do what ever you want with this code. If you wish to enhance it
please do so and post it back to the newsgroup for others to use. Also
you can e-mail it back to me and I can post it upon requests

Basically its a simple perl program that will read a mail folder file,
parse it, put in the correct headers and post it to the newsgroup. It
can be modified to for any newsgroup or moderator. I only tested this on
INN so it may not work for other news servers.

To use this program you need to have the timelocal module installed for
perl. If you don't want the Expires: header simply remove the "use
Time:Local" and "sub expire_header" with the associated procedure calls
and it will work fine without this module. Also it will clear the App
folder after it posts the articles. If you want to keep the articles
save them to a different file name that this program will not use.

Hope this helps
Robert Sandford
Internet Systems Manager
Marietta College





--------------E9203468169A488DC18404A6
Content-Type: application/x-perl;
 name="mod.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mod.pl"

#!/usr/bin/perl
################################################################
# A simple perl program that will read a mail folder file, parse 
# it, put in the correct headers and post it to the newsgroup.
#
# Robert Sandford
# Internet Systems Manager
# Marietta College

use Time::Local;
use FileHandle;
use Socket;

################################################################
# This is the main stuff that needs changed.
#
# defExpireDays - this is if you want to set the Expires: header   
# a date in the future. On our local moderated groups they wish 
# to keep the articles for 30 days.
#
# server - the domain name for the news server
#
# location - All the approved news articles are stored in the app
# folder under the mail directory
#
# moderator - the e-mail address of the moderator for the Approved:
# header

$defExpireDays = 30;                  # set expire to 30 days from today
$server = "news.marietta.edu";        # news server address		
$location = "/IT/moderate/mail/app";  # saved mail file location and name
$moderator = "moderate@marietta.edu"; # set moderator address

################################################################
# Create socket connection to news server
# If you are running inn or a port other than 119 you need to  
# make the change in this procedure.

sub connect_inn
{
  $Proto = getprotobyname('tcp');
  socket(S, AF_INET, SOCK_STREAM, $Proto) or die "socket: $!";
  $InetAddr = inet_aton($server) or die "no host";
  $SockAddr = sockaddr_in(119, $InetAddr);
  connect(S, $SockAddr);
  autoflush S;
}

##############################################################
# Set Expire header 30 days from now
# This will calculate the current time to epoch seconds add    
# the future date in epoch seconds then create the appropriate
# Expire: formatted header

sub expire_header
{

  # convert local time to seconds
  $epoch = timelocal((localtime)[0,1,2,3,4,5]);

  # set future to 30 days from now
  $future =  $defExpireDays * 24 * 60 * 60;

  ($seconds, $minutes, $hour, $day_of_month, $month,
   $year, $wday, $yday, $isdst) = localtime($epoch+$future);

  @months = ('Jan','Feb','Mar','Apr','May','Jun',
             'Jul','Aug','Sep','Oct','Nov','Dec');

  $year = $year + 1900;

  $article{Expire} = "Expires: ".$day_of_month." ".$months[$month]." "
  .$year." ".$hour.":".$minutes.":".$seconds." EST\n";

}

##############################################################
# Read approved file and get information
# Parse the APP file 

sub get_info
{
  open(APP,$location) || die "Can't Open app: $!\n";
  $start = 0;
  $body = 0;
	&expire_header();
  $article{Approved} = "Approved: $moderator\n";
  while (<APP>) {

    $size = length $_;

    # you need to change this depending on the first line of the article headers    # When we receive articles by mail to send to the moderated newsgroups it
    # comes from either "From news" or "From moderator". This is used to
    # notify when I am at a new article.
 
    if ($_ =~ /From news/)
    {
      $start = $start +1;
      $body = 0;
      $found = 0;
    }
    elsif ($_ =~ /From moderate/)
    {
      $start = $start +1;
      $body = 0;
      $found = 0;
    }


    if ($body == 1)
    {
      $article{ZMessage} = $article{ZMessage} . $_;
      $size = 10;
    }

    if ($start == 1)
    {
      if ($_ =~ /From: /) {$article{From} = $_;}
      elsif ($_ =~ /Newsgroups: /) {$article{Group} = $_;}
      elsif ($_ =~ /Subject: /) {$article{Subject} = $_;}
      elsif ($_ =~ /Organization: /) {$article{Org} = $_;}
      elsif ($_ =~ /Lines: /) {$article{Lines} = $_;}
      elsif ($_ =~ /Reply-To: /) {$article{Reply} = $_;}
      elsif ($_ =~ /Content-Type: /)
      {
        if ($found == 0) {
          $article{Type} = $_;
        }
        $found = $found + 1;
      }
      elsif ($_ =~ /boundary="/)
      {
        $boundary = $_;
        chomp($boundary);
        chomp($article{Type});
        $content = $article{Type} . $boundary;
        $article{Type} = $content;
      }
      elsif ($_ =~ /Mime-Version: /) {$article{Mime} = $_;}
			elsif ($_ =~ /Control: /) {$article{Mime} = $_;}
      elsif ($_ =~ /X-Keywords: /) {$article{Words} = $_;}
      elsif ($_ =~ /X-UID: /) {$article{UID} = $_;}
      elsif ($size == 1)
      {
        $body = 1;
        $article{ZMessage} = $article{ZMessage} . $_;
      }
   }

   if ($start > 1)
   {
     $article{ZMessageBody} = $message;
     print "Posting Article From $article{From}\n";
     &post_info();
     $start = 1;
     $article{ZMessage} = "";
   }

  }
  $article{ZMessageBody} = $message;
  print "Posting Article From $article{From}\n";
  &post_info();

}

##############################################################
# Post article to select news group

sub post_info
{
  &connect_inn();
  while ($line = <S>)
  {
		print "$line\n";
    # 200 server ready - posting allowed
    if ($line =~ /200/)
    {
      $newsgroups = $article{Group};
      chomp($newsgroups);
      ($header, $newsgroup) = split /: /,$newsgroups;
      print S "group $newsgroup \n";
    }

    # 211 group selected
    if ($line =~ /211/)
    {
    print S 'post',"\n";;
    }

    # 340 send article to be posted.
    if ($line =~ /340/)
    {
     foreach $item (keys %article)
     {
       if (exists $article{$item})
       {
         print S "$article{$item} \r\n";
       }
     }
     print S "\.","\r\n";
     print S "\r\n";
    }

    # 240 Article Posted Ok
    if ($line =~ /240/)
    {
      print S "QUIT","\r\n";
    }
  }
}

$fsize = -s $location;
if ($fsize > 0)
{
 &get_info();
 exec("rm $location;touch $location");
 exec("chmod 600 $location");
} else {
  print "The app folder contains no articles\n";
}

--------------E9203468169A488DC18404A6--


Technical Details
Message-ID: <364A1742.D4E2C490@marietta.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <364A1742.D4E2C490@marietta.edu>
Subject: My program to post to moderate news groups.
Date: Wed, 11 Nov 1998 00:00:00 +0000
From: Robert Sandford <sandforr@marietta.edu>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 410900602
X-Accept-Language: en
Content-Type: multipart/mixed; boundary="------------E9203468169A488DC18404A6"
X-Complaints-To: news@marietta.edu
X-Trace: mcnet.marietta.edu 910825361 4629 205.133.147.67 (11 Nov 1998 23:02:41 GMT)
Organization: Marietta College
Mime-Version: 1.0
Reply-To: sandforr@marietta.edu
NNTP-Posting-Date: 11 Nov 1998 23:02:41 GMT
Newsgroups: news.software.nntp