chiark / gitweb /
891f7c926f7a17b4774db47f19c57b26f123342a
[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
48 sub name_is_in_list { # address, listname
49   my $listName = pop( @_ );
50   my $address = pop( @_ );
51
52   my $item = "";
53   my $Result = "";
54
55   open( LIST, &full_config_file_name( $listName ) ) || return "";
56
57   while( $item = <LIST> ) {
58
59     chomp $item;
60
61     next unless $item =~ /\S/;
62     next if $item =~ /^\s*\#/;
63
64     if ($listName eq 'good.posters.list') {
65         if( lc $address eq lc $item ) {
66             $Result = $item;
67         }
68     } else {
69         if( eval { $address =~ /$item/i; } ) {
70             $Result = $item;
71         }
72     }
73   }
74
75   close( LIST );
76
77   return $Result;
78 }
79
80 ######################################################################
81 # reviews incoming message and decides: approve, reject, keep
82 # in queue for human review
83 #
84 # Arguments: Newsgroup, From, Subject, Message, Dir
85 #
86 # RealSubject is the shorter subject from original posting
87 sub review_incoming_message { # Newsgroup, From, Subject, RealSubject, Message, Dir
88   my $dir = pop( @_ );
89   my $message = pop( @_ );
90   my $real_subject = pop( @_ );
91   my $subject = pop( @_ );
92   my $from = pop( @_ );
93   my $newsgroup = pop( @_ );
94
95   my $warning_file = &article_file_name( $dir ) . "/stump-warning.txt";
96   my $match;
97
98   $ignore_demo_mode = 1;
99
100   if( $match = &name_is_in_list( $from, "watch.posters.list" ) ) {
101     &append_to_file( $warning_file, "Warning: poster '$from' matches '$match' from the list of suspicious posters\n" );
102 print STDERR "Filing Article for review because poster '$from' matches '$match'\n";
103     return; # file message
104   }
105
106   if( $match = &name_is_in_list( $message, "watch.words.list" ) ) {
107     &append_to_file( $warning_file, "Warning: article matches '$match' from the list of suspicious words\n" );
108 print STDERR "Filing Article for review because article matches '$match'\n";
109     return; # file message
110   }
111
112   if( &name_is_in_list( $from, "good.posters.list" ) ) {
113     &process_approval_decision( $subject, $newsgroup, $dir, "approve", "",
114                                 "auto good poster" );
115     return;
116   }
117
118   # if the message remains here, it is stored for human review.
119
120 }
121
122 1;