#!/usr/bin/perl -- -*-Perl-*- # The purpose of this script is to post alt.ql.creative stories # on both alt.ql.creative and alt.tv.quantum-leap.creative. # Note: It might be nice to post to alt.drwho.creative # or alt.tv.x-files or other *.creative newsgroups if possible... # We might be in the directory to post if we were given no arguments $debug = 0; $verbose = 0; $cc_author = 0; $standard_user = 'ql-archive@NOSPAMemployeesPLEASE.org'; $user = $standard_user; if (scalar(@ARGV) == 0) { chop($dir = `pwd`); unshift(@ARGV, $dir); } while ($ARGV[0] =~ /^-/) { if ($ARGV[0] eq "-d") { $debug++; # turn on debugging shift; } elsif ($ARGV[0] eq "-v") { $verbose = 1; shift; } elsif ($ARGV[0] eq "-a") { $cc_author = 1; shift; } elsif ($ARGV[0] eq "-u") { shift; $user = shift; print "From: $user\n" if ($debug); } else { print STDERR "Usage: $0 [-v] [-d] [-u user] directory...\n"; exit(1); } } foreach $dir (@ARGV) { chop($dir) while ($dir =~ m,/$,); ($pdir = $dir) =~ s,[^/]*/,,g; print "pdir is $pdir\n" if ($verbose); if (! -d $dir) { if (-d "/users/ftp/mdb/ql-archive/alt.ql.creative/$dir") { $dir = "/users/ftp/mdb/ql-archive/alt.ql.creative/$dir"; } else { print "\n$pdir is not the name of a story directory\n"; next; } } opendir(DIR, $dir) || die "unable to open $dir: $!"; @files = (); while($file = readdir(DIR)) { next if ($file eq '.ls_allowed'); next if ( -d $file); push(@files, $file); } closedir(DIR); @guides = grep(/guide$/, @files); @parts = sort(grep(/\.p\d+$/, @files)); $xguide = 0; $title = ''; $author = ''; foreach $file (@guides) { print "READING $dir/$file ...\n" if ($debug); @guide_text = &read_file("$dir/$file"); ($nop, $title) = split(': ', shift(@guide_text), 2); ($nop, $author) = split(': ', shift(@guide_text), 2); if ($title eq '') { die "problem reading title from $dir/$file\n"; } print "title: $title\n" if ($verbose); if ($author eq '') { die "problem reading author from $dir/$file\n"; } print "author: $author\n" if ($verbose); $xtitle{$file} = $title; $xauthor{$file} = $author; } if (scalar(@guides) > 1) { print("too many guide files found:\n", join("\n",@guides), "\n") if ($verbose); $title = ''; $author = ''; $xguide = 1; } ($firstp = $parts[$[]) =~ s/^.*\.p//; ($lastp = $parts[$#parts]) =~ s/^.*\.p//; $lastpart = sprintf("%-2.2d", scalar(@parts)); print "First part is $firstp (1)\n" if ($verbose); print "Last part is $lastp ($lastpart)\n" if ($verbose); $partnum = 0; foreach $file (@parts) { ($partnum = $file) =~ s/^.*\.p//; if ($xguide) { $title = $xtitle{$file.'guide'}; $author = $xauthor{$file.'guide'}; } $subject = sprintf("NEW STORY: $title, Part%-2.2d/%-2.2d", $partnum, $lastp); @text = &read_file("$dir/$file"); @header = (); while (scalar(@text) && ($text[$[] ne '')) { $line = shift(@text); if ($line =~ /^(From:|Subject:|Date:)/) { push(@header, $line); } } if ($title eq '') { print "Problem with title... skipping\n"; next; } if ($debug) { print "Subject: $subject\n"; next; } if ( -x "/usr/lib/sendmail" ) { $sendto = 'alt#ql#creative@newsgate.cisco.com'; $sendto .= ',alt#tv#quantum-leap#creative@newsgate.cisco.com'; $sendto .= ",$user" if ($cc_user && ($user ne $standard_user)); if (open(MAIL, "|/usr/lib/sendmail -f $user $sendto")) { print MAIL "To: $standard_user (alt.ql.creative,alt.tv.quantum-leap.creative)\n"; print MAIL "From: $standard_user (Mark D. Baushke)\n"; print MAIL "Subject: $subject\n"; print MAIL "Precedence: bulk\n"; print MAIL "Organization: Quantum Leap\n"; # print MAIL "Followup-To: rec.arts.sf.tv.quantum-leap\n"; print MAIL "\n"; print MAIL "Submitted-by: $author\n"; print MAIL "Archive-URL: ftp://ftp-eng.cisco.com/ql-archive/alt.ql.creative/\n"; print MAIL "Archive-name: $pdir/$file\n\n\n"; print MAIL join("\n",@header),"\n"; print MAIL join("\n", @text); close(MAIL); } } if ($user eq $standard_user) { print "Sent article w/Subject: $subject\n"; print "(Sent part $partnum to \'$sendto\'.)\n\n"; } else { print "Sent article w/Subject: $subject\n"; } sleep(10); } } exit 0; sub read_file { local(@text); local($filename) = @_; open(FILE, "<$filename") || return ("OOPS: reading $filename: $!"); while () { chop; push(@text, $_); } close(FILE); @text; }