chiark / gitweb /
Initial commit as found
[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
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 print STDERR "DECISION: $decision for $ShortDirectoryName sent to $address, for $newsgroup\n";
32
33   &rmdir_rf( &article_file_name( $ShortDirectoryName ) );
34
35 }
36
37
38 ###################################################################### checkAck
39 # checks the string matches one of the substrings. A name is matched
40 # against the substrings as regexps and substrings as literal substrings.
41 #
42 # Arguments: address, listname
43 sub name_is_in_list { # address, listname
44   my $listName = pop( @_ );
45   my $address = pop( @_ );
46
47   my $item = "";
48   my $Result = "";
49
50   $address = "\L$address";
51
52   open( LIST, &full_config_file_name( $listName ) ) || return "";
53
54   while( $item = <LIST> ) {
55
56     chop $item;
57
58     next if $item =~ /^\s*$/;
59
60     my $quoted_item = quotemeta( $item );
61
62     if( eval { $address =~ /$item/i; } || $address =~ /$quoted_item/i ) {
63       $Result = $item;
64     }
65   }
66
67   close( LIST );
68
69   return $Result;
70 }
71
72
73 ######################################################################
74 # reviews incoming message and decides: approve, reject, keep
75 # in queue for human review
76 #
77 # Arguments: Newsgroup, From, Subject, Message, Dir
78 #
79 # RealSubject is the shorter subject from original posting
80 sub review_incoming_message { # Newsgroup, From, Subject, RealSubject, Message, Dir
81   my $dir = pop( @_ );
82   my $message = pop( @_ );
83   my $real_subject = pop( @_ );
84   my $subject = pop( @_ );
85   my $from = pop( @_ );
86   my $newsgroup = pop( @_ );
87
88   if( &name_is_in_list( $from, "bad.posters.list" ) ) {
89     &process_approval_decision( $subject, $newsgroup, $dir, "reject abuse", "" );
90     return;
91   }
92
93   if( &name_is_in_list( $real_subject, "bad.subjects.list" ) ) {
94     &process_approval_decision( $subject, $newsgroup, $dir, "reject thread", "" );
95     return;
96   }
97
98   if( &name_is_in_list( $message, "bad.words.list" ) ) {
99     &process_approval_decision( $subject, $newsgroup, $dir, "reject charter", 
100     "Your message has been autorejected because it appears to be off topic
101     based on our filtering criteria. Like everything, filters do not
102     always work perfectly and you can always appeal this decision." );
103     return;
104   }
105
106   my $warning_file = &article_file_name( $dir ) . "/stump-warning.txt";
107   my $match;
108
109   $ignore_demo_mode = 1;
110
111   if( $match = &name_is_in_list( $from, "watch.posters.list" ) ) {
112     &append_to_file( $warning_file, "Warning: poster '$from' matches '$match' from the list of suspicious posters\n" );
113 print STDERR "Filing Article for review because poster '$from' matches '$match'\n";
114     return; # file message
115   }
116
117   if( $match = &name_is_in_list( $real_subject, "watch.subjects.list" ) ) {
118     &append_to_file( $warning_file, "Warning: subject '$real_subject' matches '$match' from the list of suspicious subjects\n" );
119 print STDERR "Filing Article for review because subject '$subject' matches '$match'\n";
120     return; # file message
121   }
122
123   if( $match = &name_is_in_list( $message, "watch.words.list" ) ) {
124     &append_to_file( $warning_file, "Warning: article matches '$match' from the list of suspicious words\n" );
125 print STDERR "Filing Article for review because article matches '$match'\n";
126     return; # file message
127   }
128
129   if( &name_is_in_list( $from, "good.posters.list" ) ) {
130     &process_approval_decision( $subject, $newsgroup, $dir, "approve", "" );
131     return;
132   }
133
134   if( &name_is_in_list( $real_subject, "good.subjects.list" ) ) {
135     &process_approval_decision( $subject, $newsgroup, $dir, "approve", "" );
136     return;
137   }
138
139   # if the message remains here, it is stored for human review.
140
141 }
142
143 1;