use strict;
use vars qw(%work @msg $msgdir %valid %busy $maxage $last_clean
- @badmsg $badmsgfn $forwardfn @forward $timeout $waittime
+ @badmsg @swop $swopfn $badmsgfn $forwardfn @forward $timeout $waittime
$queueinterval $lastq);
%work = (); # outstanding jobs
$maxage = 30 * 86400; # the maximum age that a message shall live for if not marked
$last_clean = 0; # last time we did a clean
@forward = (); # msg forward table
+@badmsg = (); # bad message table
+@swop = (); # swop table
$timeout = 30*60; # forwarding timeout
-$waittime = 60*60; # time an aborted outgoing message waits before trying again
-$queueinterval = 2*60; # run the queue every 2 minutes
+$waittime = 30*60; # time an aborted outgoing message waits before trying again
+$queueinterval = 1*60; # run the queue every 1 minute
$lastq = 0;
$badmsgfn = "$msgdir/badmsg.pl"; # list of TO address we wont store
$forwardfn = "$msgdir/forward.pl"; # the forwarding table
+$swopfn = "$msgdir/swop.pl"; # the swopping table
%valid = (
fromnode => '5,From Node',
# this is periodic processing
if (!$self || !$line) {
- # wander down the work queue stopping any messages that have timed out
- for (keys %busy) {
- my $node = $_;
- my $ref = $busy{$_};
- if (exists $ref->{lastt} && $main::systime > $ref->{lastt} + $timeout) {
- dbg('msg', "Timeout, stopping msgno: $ref->{msgno} -> $node");
- $ref->stop_msg($node);
+ if ($main::systime > $lastq + $queueinterval) {
- # delay any outgoing messages that fail
- $ref->{waitt} = $main::systime + $waittime + rand(120) if $node ne $main::mycall;
+ # wander down the work queue stopping any messages that have timed out
+ for (keys %busy) {
+ my $node = $_;
+ my $ref = $busy{$_};
+ if (exists $ref->{lastt} && $main::systime >= $ref->{lastt} + $timeout) {
+ dbg('msg', "Timeout, stopping msgno: $ref->{msgno} -> $node");
+ $ref->stop_msg($node);
+
+ # delay any outgoing messages that fail
+ $ref->{waitt} = $main::systime + $waittime + rand(120) if $node ne $main::mycall;
+ }
}
- }
- # queue some message if the interval timer has gone off
- if ($main::systime > $lastq + $queueinterval) {
+ # queue some message if the interval timer has gone off
queue_msg(0);
$lastq = $main::systime;
}
return;
}
}
-
+
+ # swop addresses
+ $ref->swop_it($self->call);
+
# look for 'bad' to addresses
- if (grep $ref->{to} eq $_, @badmsg) {
+# if (grep $ref->{to} eq $_, @badmsg) {
+ if ($ref->dump_it($self->call)) {
$ref->stop_msg($self->call);
- dbg('msg', "'Bad' TO address $ref->{to}");
- Log('msg', "'Bad' TO address $ref->{to}");
+ dbg('msg', "'Bad' message $ref->{to}");
+ Log('msg', "'Bad' message $ref->{to}");
return;
}
$ref->stop_msg($self->call);
$ref = undef;
}
-
last SWITCH;
}
my $call = shift;
my $ref;
my $clref;
- my @nodelist = DXProt::get_all_ak1a();
+ my @nodelist = DXChannel::get_all_ak1a();
# bat down the message list looking for one that needs to go off site and whose
# nearest node is not busy.
# deal with routed private messages
my $noderef;
if ($ref->{private}) {
+ next if $ref->{'read'}; # if it is read, it is stuck here
$clref = DXCluster->get_exact($ref->{to});
unless ($clref) { # otherwise look for a homenode
my $uref = DXUser->get($ref->{to});
my $dir = new IO::File;
my @dir;
my $ref;
-
+
# load various control files
- my @in = load_badmsg();
- print "@in\n" if @in;
- @in = load_forward();
- print "@in\n" if @in;
+ print "load badmsg: ", (load_badmsg() or "Ok"), "\n";
+ print "load forward: ", (load_forward() or "Ok"), "\n";
+ print "load swop: ", (load_swop() or "Ok"), "\n";
# read in the directory
opendir($dir, $msgdir) or confess "can't open $msgdir $!";
} elsif ($self->state eq 'sendbody') {
confess "local var gone missing" if !ref $self->{loc};
my $loc = $self->{loc};
- if ($line eq "\032" || uc $line eq "/EX") {
+ if ($line eq "\032" || $line eq '%1A' || uc $line eq "/EX") {
my $to;
if (@{$loc->{lines}} > 0) {
sub load_forward
{
my @out;
- do "$forwardfn" if -e "$forwardfn";
- push @out, $@ if $@;
+ my $s = readfilestr($forwardfn);
+ if ($s) {
+ eval $s;
+ push @out, $@ if $@;
+ }
return @out;
}
sub load_badmsg
{
my @out;
- do "$badmsgfn" if -e "$badmsgfn";
- push @out, $@ if $@;
+ my $s = readfilestr($badmsgfn);
+ if ($s) {
+ eval $s;
+ push @out, $@ if $@;
+ }
+ return @out;
+}
+
+# load the swop message table
+sub load_swop
+{
+ my @out;
+ my $s = readfilestr($swopfn);
+ if ($s) {
+ eval $s;
+ push @out, $@ if $@;
+ }
return @out;
}
# select field
$tested = $ref->{to} if $field eq 'T';
- my $at = $ref->{to} =~ /\@\s*(\S+)/;
- $tested = $at if $field eq '\@';
$tested = $ref->{from} if $field eq 'F';
$tested = $ref->{origin} if $field eq 'O';
$tested = $ref->{subject} if $field eq 'S';
return 0;
}
+sub dump_it
+{
+ my $ref = shift;
+ my $call = shift;
+ my $i;
+
+ for ($i = 0; $i < @badmsg; $i += 3) {
+ my ($sort, $field, $pattern) = @badmsg[$i..($i+2)];
+ my $tested;
+
+ # are we interested?
+ next if $ref->{private} && $sort ne 'P';
+ next if !$ref->{private} && $sort ne 'B';
+
+ # select field
+ $tested = $ref->{to} if $field eq 'T';
+ $tested = $ref->{from} if $field eq 'F';
+ $tested = $ref->{origin} if $field eq 'O';
+ $tested = $ref->{subject} if $field eq 'S';
+
+ if (!$pattern || $tested =~ m{$pattern}i) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+sub swop_it
+{
+ my $ref = shift;
+ my $call = shift;
+ my $i;
+ my $count = 0;
+
+ for ($i = 0; $i < @swop; $i += 5) {
+ my ($sort, $field, $pattern, $tfield, $topattern) = @swop[$i..($i+4)];
+ my $tested;
+ my $swop;
+ my $old;
+
+ # are we interested?
+ next if $ref->{private} && $sort ne 'P';
+ next if !$ref->{private} && $sort ne 'B';
+
+ # select field
+ $tested = $ref->{to} if $field eq 'T';
+ $tested = $ref->{from} if $field eq 'F';
+ $tested = $ref->{origin} if $field eq 'O';
+ $tested = $ref->{subject} if $field eq 'S';
+
+ # select swop field
+ $old = $swop = $ref->{to} if $tfield eq 'T';
+ $old = $swop = $ref->{from} if $tfield eq 'F';
+ $old = $swop = $ref->{origin} if $tfield eq 'O';
+ $old = $swop = $ref->{subject} if $tfield eq 'S';
+
+ if ($tested =~ m{$pattern}i) {
+ if ($tested eq $swop) {
+ $swop =~ s{$pattern}{$topattern}i;
+ } else {
+ $swop = $topattern;
+ }
+ Log('msg', "Msg $ref->{msgno}: $tfield $old -> $swop");
+ Log('dbg', "Msg $ref->{msgno}: $tfield $old -> $swop");
+ $ref->{to} = $swop if $tfield eq 'T';
+ $ref->{from} = $swop if $tfield eq 'F';
+ $ref->{origin} = $swop if $tfield eq 'O';
+ $ref->{subject} = $swop if $tfield eq 'S';
+ ++$count;
+ }
+ }
+ return $count;
+}
+
no strict;
sub AUTOLOAD
{