preparing for 1.23 release
[spider.git] / perl / DXMsg.pm
index 80895a55fbfc0ae82966bdb91ffa26214b539d92..8dcb09924630aab7de7c3a3547b6988f54dd75fc 100644 (file)
@@ -201,7 +201,7 @@ sub process
                                                $ref->store($ref->{lines});
                                                add_dir($ref);
                                                my $dxchan = DXChannel->get($ref->{to});
-                                               $dxchan->send("New mail has arrived for you") if $dxchan;
+                                               $dxchan->send($dxchan->msg('msgnew')) if $dxchan;
                                                Log('msg', "Message $ref->{msgno} from $ref->{from} received from $f[2] for $ref->{to}");
                                        }
                                }
@@ -497,9 +497,14 @@ sub queue_msg
                if ($ref->{private}) {
                        if ($ref->{'read'} == 0) {
                                $clref = DXCluster->get_exact($ref->{to});
+                               unless ($clref) {             # otherwise look for a homenode
+                                       my $uref = DXUser->get($ref->{to});
+                                       my $hnode =  $uref->homenode if $uref;
+                                       $clref = DXCluster->get_exact($hnode) if $hnode;
+                               }
                                if ($clref && !grep { $clref->{dxchan} == $_ } DXCommandmode::get_all) {
                                        $dxchan = $clref->{dxchan};
-                                       $ref->start_msg($dxchan) if $clref && !get_busy($dxchan->call) && $dxchan->state eq 'normal';
+                                       $ref->start_msg($dxchan) if $dxchan && $clref && !get_busy($dxchan->call) && $dxchan->state eq 'normal';
                                }
                        }
                } elsif (!$sort) {
@@ -524,6 +529,21 @@ sub queue_msg
        }
 }
 
+# is there a message for me?
+sub for_me
+{
+       my $call = uc shift;
+       my $ref;
+       
+       foreach $ref (@msg) {
+               # is it for me, private and unread? 
+               if ($ref->{to} eq $call && $ref->{private}) {
+                       return 1 if !$ref->{'read'};
+               }
+       }
+       return 0;
+}
+
 # start the message off on its travels with a PC28
 sub start_msg
 {
@@ -606,7 +626,8 @@ sub init
        opendir($dir, $msgdir) or confess "can't open $msgdir $!";
        @dir = readdir($dir);
        closedir($dir);
-       
+
+       @msg = ();
        for (sort @dir) {
                next if /^\./o;
                next if ! /^m\d+/o;
@@ -722,9 +743,9 @@ sub do_send_stuff
                        delete $loc->{lines};
                        delete $loc->{to};
                        delete $self->{loc};
-                       $self->state('prompt');
                        $self->func(undef);
                        DXMsg::queue_msg(0);
+                       $self->state('prompt');
                } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
                        #push @out, $self->msg('sendabort');
                        push @out, "aborted";