chiark / gitweb /
Error handling fixes including new log file
[modbot-mtm.git] / webstump / scripts / gatekeeper-file-message.pl
1 #!/usr/bin/perl
2 #
3 # This script reads a message from stdin, figures out which newsgroup's
4 # queue it should be saved to, and saves it.
5 #
6 #
7 # Figure out the home directory
8 #
9
10 if( !($0 =~ /\/scripts\/gatekeeper-file-message\.pl$/) ) {
11   die "This script can only be called with full path name!!!";
12 }
13
14 $webstump_home = $0;
15 $webstump_home =~ s/\/scripts\/gatekeeper-file-message\.pl$//;
16
17 require "$webstump_home/config/webstump.cfg";
18 require "$webstump_home/scripts/webstump.lib.pl";
19
20 &init_webstump;
21
22 $Subject = "";
23
24 $newsgroup = @ARGV[0] || die "Syntax: $0 newsgroup.name";
25
26 $queue_dir = &getQueueDir( $newsgroup ) 
27         || die "Newsgroup $newsgroup is not listed in the newsgroups database";
28
29 mkdir $queue_dir, 0700; # it is OK if this fails
30
31 die "$queue_dir does not exist or is not writable"
32         if( ! -d $queue_dir || ! -w $queue_dir );
33
34 $time = time;
35 $file = "$queue_dir/$time.$$";
36 open( QUEUE_FILE, ">$file" ) || die "Could not open $file for writing";
37
38 while( <STDIN> ) {
39   print QUEUE_FILE or die $!;
40 }
41
42 close( QUEUE_FILE ) or die $!;