chiark / gitweb /
Send webstump CGI logs to "errs" too to capture all of the decisions
[modbot-mtm.git] / webstump / scripts / filter.lib.pl
1 #
2 #
3 # This library of functions is used for filtering messages.
4 #
5
6
7 # processes approval decision.
8 #
9 # Arguments: 
10 #
11 # Subject, newsgroup, ShortDirectoryName, decision, comment
12
13 sub process_approval_decision {
14   my $cathow = @_>=6 ? pop(@_) : "UNKNOWN";
15   my $comment = pop( @_ );
16   my $decision = pop( @_ );
17   my $ShortDirectoryName = pop( @_ );
18   my $newsgroup = pop( @_ );
19   my $Subject = pop( @_ );
20
21   my $address = $newsgroups_index{$newsgroup};
22
23   my $message = "To: $newsgroups_index{$newsgroup}\n" .
24                 "Subject: $Subject\n" .
25                 "Organization: http://www.algebra.com/~ichudov/stump\n";
26
27   $message .= "\n$decision\n";
28   $message .= "comment $comment\n" if $comment;
29   &email_message( $message, $address );
30
31   my $sanisubj= $Subject;
32   $sanisubj =~ s/.*\:\://;
33
34 print STDERR "DECISION: $newsgroup | $ShortDirectoryName | $decision | $cathow | $sanisubj\n";
35
36   &rmdir_rf( &article_file_name( $ShortDirectoryName ) );
37
38 }
39
40
41 ###################################################################### checkAck
42 # checks the string matches one of the substrings. A name is matched
43 # against the substrings as regexps and substrings as literal substrings.
44 #
45 # Arguments: address, listname
46 sub name_is_in_list { # address, listname
47   my $listName = pop( @_ );
48   my $address = pop( @_ );
49
50   my $item = "";
51   my $Result = "";
52
53   $address = "\L$address";
54
55   open( LIST, &full_config_file_name( $listName ) ) || return "";
56
57   while( $item = <LIST> ) {
58
59     chop $item;
60
61     next if $item =~ /^\s*$/;
62
63     my $quoted_item = quotemeta( $item );
64
65     if( eval { $address =~ /$item/i; } || $address =~ /$quoted_item/i ) {
66       $Result = $item;
67     }
68   }
69
70   close( LIST );
71
72   return $Result;
73 }
74
75
76 ######################################################################
77 # reviews incoming message and decides: approve, reject, keep
78 # in queue for human review
79 #
80 # Arguments: Newsgroup, From, Subject, Message, Dir
81 #
82 # RealSubject is the shorter subject from original posting
83 sub review_incoming_message { # Newsgroup, From, Subject, RealSubject, Message, Dir
84   my $dir = pop( @_ );
85   my $message = pop( @_ );
86   my $real_subject = pop( @_ );
87   my $subject = pop( @_ );
88   my $from = pop( @_ );
89   my $newsgroup = pop( @_ );
90
91   if( &name_is_in_list( $from, "bad.posters.list" ) ) {
92     &process_approval_decision( $subject, $newsgroup, $dir, "reject abuse", "", "auto bad poster" );
93     return;
94   }
95
96   if( &name_is_in_list( $real_subject, "bad.subjects.list" ) ) {
97     &process_approval_decision( $subject, $newsgroup, $dir, "reject thread", "", "auto bad subject" );
98     return;
99   }
100
101   if( &name_is_in_list( $message, "bad.words.list" ) ) {
102     &process_approval_decision( $subject, $newsgroup, $dir, "reject charter", 
103     "Your message has been autorejected because it appears to be off topic
104     based on our filtering criteria. Like everything, filters do not
105     always work perfectly and you can always appeal this decision.",
106                                 "auto bad word" );
107     return;
108   }
109
110   my $warning_file = &article_file_name( $dir ) . "/stump-warning.txt";
111   my $match;
112
113   $ignore_demo_mode = 1;
114
115   if( $match = &name_is_in_list( $from, "watch.posters.list" ) ) {
116     &append_to_file( $warning_file, "Warning: poster '$from' matches '$match' from the list of suspicious posters\n" );
117 print STDERR "Filing Article for review because poster '$from' matches '$match'\n";
118     return; # file message
119   }
120
121   if( $match = &name_is_in_list( $real_subject, "watch.subjects.list" ) ) {
122     &append_to_file( $warning_file, "Warning: subject '$real_subject' matches '$match' from the list of suspicious subjects\n" );
123 print STDERR "Filing Article for review because subject '$subject' matches '$match'\n";
124     return; # file message
125   }
126
127   if( $match = &name_is_in_list( $message, "watch.words.list" ) ) {
128     &append_to_file( $warning_file, "Warning: article matches '$match' from the list of suspicious words\n" );
129 print STDERR "Filing Article for review because article matches '$match'\n";
130     return; # file message
131   }
132
133   if( &name_is_in_list( $from, "good.posters.list" ) ) {
134     &process_approval_decision( $subject, $newsgroup, $dir, "approve", "",
135                                 "auto good poster" );
136     return;
137   }
138
139   if( &name_is_in_list( $real_subject, "good.subjects.list" ) ) {
140     &process_approval_decision( $subject, $newsgroup, $dir, "approve", "",
141                                 "auto good subject" );
142     return;
143   }
144
145   # if the message remains here, it is stored for human review.
146
147 }
148
149 1;