chiark / gitweb /
Rather unhelpful License file
[bofhbot] / autorep.pl
1 #!/usr/bin/perl
2
3 my $rcsid='$Id: testrep.channel,v 1.2 2000/08/22 23:52:51 sec Exp sec $';
4 my $len=5; # Max Size in KB of included article.
5
6 use POSIX qw(strftime);
7 use Date::Manip;
8 use strict;
9
10 $|=1;
11 while(<>){
12         chomp;
13         if(!open(ARTICLE,"/usr/lib/news/bin/sm '$_'|")){
14                 print "$0 failed to get article $_\n";
15         };
16         print "$_\n";
17         &reply();
18         close(ARTICLE);
19 };
20 print "$0 Exiting on eof.\n";
21 sleep(10);
22 exit(0);
23
24 sub reply(){
25 my @hdrs;
26 my ($nor,$date,$from,$reply,$mid,$path,$subject,$ng);
27 my ($pathe);
28 my ($nodes,@paths,$paths,$s);
29
30 while (<ARTICLE>){
31         push @hdrs,$_;
32         chomp;
33         last if /^$/;
34         $nor=1 if (/(ignore|no\s?reply)/i);
35         $date=$_ if (s/^date:\s+//i);
36         $from=$_ if (s/^from:\s+//i);
37         $reply=$_ if (s/^reply-to:\s+//i);
38         $mid=$_ if (s/^message-id:\s+//i);
39         $path=$_ if (s/^path:\s+//i);
40         $subject=$_ if (s/^subject:\s+//i);
41         $ng=$_ if (s/^newsgroups:\s+//i);
42 }
43
44 for my $k (1..10){
45         $_ = scalar <ARTICLE>;
46         push @hdrs,$_;
47         $nor=1 if (/(ignore|no\s?reply)/i);
48 }
49
50 return if ($ng =~ /,/); # Ignore cross-postings.
51 return if ($nor);       # User wanted us to ignore it.
52 return if ($from =~ /NNTP-Monitor\@hero\.vmc\.private\.ntl\.com/) ;
53                         # spammy and unmailable
54
55 my $diff=&timediff(time-
56 UnixDate(ParseDate($date),"%s")
57 ),"\n";
58
59 sub timediff(){
60         my @n=qw(second minute hour day);
61         my @t=(60,60,24,99999);
62         my $r=shift;
63         my $f=1;
64         my $p=0;
65         my $s="";
66         if ($r == 0) {
67             $s="less than one second";
68         }
69         else {
70             for my $i (0..$#t){
71                 $p=$r%$t[$i];$r=int($r/$t[$i]);
72                 #print "p: $p, r: $r\n";
73                 if($p){$s=(($f-->0 && $r>0)?"and ":"").$p." ".$n[$i].($p>1?"s":"").($f<-1?",":"").($s?" ".$s:"")}
74             }
75         }
76         return $s;
77 }
78
79 $from=$reply if ($reply);
80
81 $path =~ /([^!]*)!/; $pathe=$1;
82 $nodes = (($paths = $path)=~ s/!/ /g);
83 $s=$nodes>1?"s":"";
84
85 @paths=split(/!/,$path);
86 pop(@paths);
87 $paths=join(" ->_",reverse @paths).". ";
88 $paths=~s/([^\n]{40,75})[ \n]/$1\n/g;
89 $paths=~s/_/ /g;
90
91 my $rdate=strftime "%a %b %e %H:%M:%S UTC %Y", gmtime;
92
93 open(FOO,"|/usr/sbin/sendmail -t -f usenet-autoresponder\@ysolde.ucam.org");
94 print FOO <<EOF;
95 Subject: Response to a test message. (was: $subject)
96 From: $ng autoresponder <usenet\@ysolde.ucam.org>
97 To: $from
98 X-Rcs-Id: $rcsid
99 X-Local-Version: 0.1.0
100 Precedence: junk
101
102 This message has been generated automatically in order to help you track
103 the circulation in the $ng newsgroup. If you do not wish any reply
104 from this program, just include the words "ignore" or "no reply" in the
105 header or in the 10 first lines of the body of your message.
106
107 Your Message $mid was received by $pathe
108 at $rdate.
109
110 Assuming your clock was set correctly, this means that your article
111 travelled the network for $diff
112 before arriving here.
113
114 It had to pass through the following $nodes Usenet node$s starting with
115 your system:
116 $paths
117
118 Full headers plus the first 10 lines of your original message were:
119
120 EOF
121
122 my $str=join ("",@hdrs);
123 print FOO substr($str,0,$len*1024);
124 if (substr($str,$len*1024,1)){
125         print "\n- The above message has been trunctated, because it is longer than  $len KB.\n";
126 }
127 close(FOO);
128
129 };