fix swearing logging so that it is better.
[spider.git] / perl / DXMsg.pm
index 04ef99cb8ecffccfb21d7215b590a886497d2a8d..f4a1b7aba0e66dd6818d288e1e229b90d03a30b3 100644 (file)
@@ -151,7 +151,10 @@ sub process
        }
 
        # clean the message queue
-       clean_old() if $main::systime - $last_clean > 3600 ;
+       if ($main::systime >= $last_clean+3600) {
+               clean_old();
+               $last_clean = $main::systime;
+       }
        
        # actual remove all the 'deleted' messages in one hit.
        # this has to be delayed until here otherwise it only does one at 
@@ -161,7 +164,6 @@ sub process
                $_->del_msg;
        }
        
-       $last_clean = $main::systime;
 }
 
 # incoming message
@@ -312,6 +314,14 @@ sub handle_32
                                $ref->store($ref->{lines});
                        } else {
 
+                               # is it too old
+                               if ($ref->{t}+$maxage < $main::systime ) {
+                                       $ref->stop_msg($fromnode);
+                                       dbg("old message from $ref->{from} -> $ref->{to} " . atime($ref->{t}) . " ignored") if isdbg('msg');
+                                       Log('msg', "old message from $ref->{from} -> $ref->{to} " . cldatetime($ref->{t}) . " ignored");
+                                       return;
+                               }
+
                                # does an identical message already exist?
                                my $m;
                                for $m (@msg) {
@@ -336,17 +346,22 @@ sub handle_32
                                }
 
                                # check the message for bad words 
+                               my @bad;
                                my @words;
+                               @bad = BadWords::check($ref->{subject});
+                               push @words, [$ref->{subject}, @bad] if @bad; 
                                for (@{$ref->{lines}}) {
-                                       push @words, BadWords::check($_);
+                                       @bad = BadWords::check($_);
+                                       push @words, [$_, @bad] if @bad;
                                }
-                               push @words, BadWords::check($ref->{subject});
                                if (@words) {
-                                       dbg("$ref->{from} swore: '@words' -> $ref->{to} '$ref->{subject}' origin: $ref->{origin} via " . $dxchan->call) if isdbg('msg');
-                                       Log('msg',"$ref->{from} swore: '@words' -> $ref->{to} origin: $ref->{origin} via " . $dxchan->call);
+                                       dbg("$ref->{from} swore: $ref->{to} '$ref->{subject}' origin: $ref->{origin} via " . $dxchan->call) if isdbg('msg');
+                                       Log('msg',"$ref->{from} swore: $ref->{to} origin: $ref->{origin} via " . $dxchan->call);
+                                   dbg("subject: $ref->{subject}");
                                        Log('msg',"subject: $ref->{subject}");
-                                       for (@{$ref->{lines}}) {
-                                               Log('msg', "line: $_");
+                                       for (@words) {
+                                               dbg("line: $_->[0] (using words: ". join(',',@{$_->[1]}).")");
+                                               Log('msg', "line: $_->[0] (using words: ". join(',',@{$_->[1]}).")");
                                        }
                                        $ref->stop_msg($fromnode);
                                        return;
@@ -469,7 +484,7 @@ sub notify
        my $ref = shift;
        my $to = $ref->{to};
        my $uref = DXUser->get_current($to);
-       my $dxchan = DXChannel->get($to);
+       my $dxchan = DXChannel::get($to);
        if (((*Net::SMTP && $email_server) || $email_prog) && $uref && $uref->wantemail) {
                my $email = $uref->email;
                if ($email) {