fix intermittant bulletin mail forwarding?
[spider.git] / perl / DXMsg.pm
index 2cdb6a8028a15bb2d11e4ae27a1755b1e23e15d1..5f9ebc32540579447a117eb4c8b2e0bc4654b8bf 100644 (file)
@@ -27,6 +27,13 @@ use IO::File;
 use Fcntl;
 
 use strict;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
 use vars qw(%work @msg $msgdir %valid %busy $maxage $last_clean
                        @badmsg @swop $swopfn $badmsgfn $forwardfn @forward $timeout $waittime
                    $queueinterval $lastq $importfn $minchunk $maxchunk $bulltopriv);
@@ -165,10 +172,11 @@ sub process
                        # first look for any messages in the busy queue 
                        # and cancel them this should both resolve timed out incoming messages
                        # and crossing of message between nodes, incoming messages have priority
+
                        if (exists $busy{$fromnode}) {
                                my $ref = $busy{$fromnode};
                                my $tonode = $ref->{tonode};
-                               dbg("Busy, stopping msgno: $ref->{msgno} -> $fromnode") if isdbg('msg');
+                               dbg("Busy, stopping msgno: $ref->{msgno} $fromnode->$tonode") if isdbg('msg');
                                $ref->stop_msg($self->call);
                        }
 
@@ -283,7 +291,7 @@ sub process
                                                $ref->swop_it($self->call);
                                                
                                                # look for 'bad' to addresses 
-                                               if ($ref->dump_it) {
+                                               if ($ref->dump_it($self->call)) {
                                                        $ref->stop_msg($self->call);
                                                        dbg("'Bad' message $ref->{to}") if isdbg('msg');
                                                        Log('msg', "'Bad' message $ref->{to}");
@@ -579,7 +587,6 @@ sub send_tranche
 sub queue_msg
 {
        my $sort = shift;
-       my $call = shift;
        my $ref;
        my $clref;
        
@@ -633,23 +640,23 @@ sub queue_msg
                                        dbg("Route: No dxchan for $ref->{to} " . ref($clref) ) if isdbg('msg');
                                }
                        }
-               }
-               
-               # otherwise we are dealing with a bulletin or forwarded private message
-               # compare the gotit list with
-               # the nodelist up above, if there are sites that haven't got it yet
-               # then start sending it - what happens when we get loops is anyone's
-               # guess, use (to, from, time, subject) tuple?
-               foreach $dxchan (@nodelist) {
-                       my $call = $dxchan->call;
-                       next unless $call;
-                       next if $call eq $main::mycall;
-                       next if ref $ref->{gotit} && grep $_ eq $call, @{$ref->{gotit}};
-                       next unless $ref->forward_it($call);           # check the forwarding file
-
-                       # if we are here we have a node that doesn't have this message
-                       $ref->start_msg($dxchan) if !get_busy($call)  && $dxchan->state eq 'normal';
-                       last;
+               } else {
+                       
+                       # otherwise we are dealing with a bulletin or forwarded private message
+                       # compare the gotit list with
+                       # the nodelist up above, if there are sites that haven't got it yet
+                       # then start sending it - what happens when we get loops is anyone's
+                       # guess, use (to, from, time, subject) tuple?
+                       foreach $dxchan (@nodelist) {
+                               my $call = $dxchan->call;
+                               next unless $call;
+                               next if $call eq $main::mycall;
+                               next if ref $ref->{gotit} && grep $_ eq $call, @{$ref->{gotit}};
+                               next unless $ref->forward_it($call);           # check the forwarding file
+                               
+                               # if we are here we have a node that doesn't have this message
+                               $ref->start_msg($dxchan) if !get_busy($call)  && $dxchan->state eq 'normal';
+                       }
                }
 
                # if all the available nodes are busy then stop
@@ -685,7 +692,15 @@ sub start_msg
        $busy{$self->{tonode}} = $self;
        $work{$self->{tonode}} = $self;
        $self->{lastt} = $main::systime;
-       $dxchan->send(DXProt::pc28($self->{tonode}, $self->{fromnode}, $self->{to}, $self->{from}, $self->{t}, $self->{private}, $self->{subject}, $self->{origin}, $self->{rrreq}));
+       my ($fromnode, $origin);
+       if ($dxchan->is_arcluster) {
+               $fromnode = $self->{origin};
+               $origin = $self->{fromnode};
+       } else {
+               $fromnode = $self->{fromnode};
+               $origin = $self->{origin};
+       }
+       $dxchan->send(DXProt::pc28($self->{tonode}, $fromnode, $self->{to}, $self->{from}, $self->{t}, $self->{private}, $self->{subject}, $origin, $self->{rrreq}));
 }
 
 # get the ref of a busy node
@@ -776,7 +791,7 @@ sub init
                }
                
                # delete any messages to 'badmsg.pl' places
-               if ($ref->dump_it) {
+               if ($ref->dump_it('')) {
                        dbg("'Bad' TO address $ref->{to}") if isdbg('msg');
                        Log('msg', "'Bad' TO address $ref->{to}");
                        $ref->del_msg;
@@ -991,6 +1006,7 @@ sub forward_it
 sub dump_it
 {
        my $ref = shift;
+       my $call = shift;
        my $i;
        
        for ($i = 0; $i < @badmsg; $i += 3) {
@@ -1006,6 +1022,7 @@ sub dump_it
                $tested = $ref->{from} if $field eq 'F';
                $tested = $ref->{origin} if $field eq 'O';
                $tested = $ref->{subject} if $field eq 'S';
+               $tested = $call if $field eq 'I';
 
                if (!$pattern || $tested =~ m{$pattern}i) {
                        return 1;