#!/usr/athena/bin/perl
#
# Mini NNTP server which accepts a nonstreaming header-only feeds in
# order to collect path entries from messages
#
# kolya 2001/Oct/29
#

$| = 1;

print "200 pathscan ready to collect path entires\r\n";

$ts = 0+time();

open(NINPATHS, "| /news/bin/ninpaths -p -d /news/paths/inpaths.$ts.$$");

while (<>) {
 $_ =~ s/[\r\n]*$//g;
 if(/^mode headfeed$/i) { print "250 mode ok\r\n"; }
 elsif(/^check (.*)$/i) { print "238 $1\r\n"; }
 elsif(/^takethis (.*)$/i) {
  $msgid=$1;
  &take_article;
  print "239 $msgid\r\n"; }
 elsif(/^ihave (.*)$/i) {
  $msgid=$1;
  print "335 $msgid\r\n";
  &take_article;
  print "235 $msgid\r\n"; }
 elsif(/^quit/i) { &done; }
 else { print "500 not implemented\r\n"; }
}

&done;

sub done {
 close(NINPATHS);
 print "205 bye-bye\r\n";
 exit;
}

sub take_article {
 $header="\n";
 $in="";
 while($in !~ /^.$/) {
  &done unless $in = <>;
  $in=~s/[\r\n]*$//g;
  last if ($in eq "");
  if($in ne ".") {
   if(substr($line, 0, 1) eq ".") {
    $header_line = substr($in, 1). "\n";
   } else {
    $header_line = $in. "\n";
   }
  }

  if ($header_line =~ /^Path:/) {
    print NINPATHS $header_line;
  }
 }

 while($in !~ /^.$/) {
  $in=<>; $in=~s/[\r\n]*$//g;
 }
}
