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