fixed swopping on msgs in all places
[spider.git] / perl / DXMsg.pm
index 88371ed787a3e08119d4c2a22a42af7a0a5d487b..168a978280e56337e8b17db7de48e894b92347c1 100644 (file)
@@ -846,13 +846,14 @@ sub do_send_stuff
                                my $mycall = $main::mycall;
                                $ref = DXMsg->alloc(DXMsg::next_transno('Msgno'),
                                                                        uc $to,
-                                                                       $self->call, 
+                                                                       exists $loc->{from} ? $loc->{from} : $self->call, 
                                                                        $systime,
                                                                        $loc->{private}, 
                                                                        $loc->{subject}, 
-                                                                       $mycall,
+                                                                       exists $loc->{origin} ? $loc->{origin} : $mycall,
                                                                        '0',
                                                                        $loc->{rrreq});
+                               $ref->swop_it($self->call);
                                $ref->store($loc->{lines});
                                $ref->add_dir();
                                push @out, $self->msg('m11', $ref->{msgno}, $to);
@@ -1057,7 +1058,7 @@ sub import_msgs
        closedir(DIR);
        my $name;
        foreach $name (@names) {
-               next if $name =~ /^./;
+               next if $name =~ /^\./;
                my $fn = "$importfn/$name";
                next unless -f $fn;
                unless (open(MSG, $fn)) {
@@ -1066,7 +1067,7 @@ sub import_msgs
                        unlink($fn);
                        next;
                }
-               my @msg = map { chomp } <MSG>;
+               my @msg = map { chomp; $_ } <MSG>;
                close(MSG);
                unlink($fn);
                my @out = import_one($DXProt::me, \@msg);
@@ -1089,7 +1090,13 @@ sub import_one
        my @out;
                                
        # first line;
-       my @f = split /\s+/, shift @$ref;
+       my $line = shift @$ref;
+       my @f = split /\s+/, $line;
+       unless ($f[0] =~ /^(:?S|SP|SB|SEND)$/ ) {
+               my $m = "invalid first line in import '$line'";
+               dbg('MSG', $m );
+               return (1, $m);
+       }
        while (@f) {
                my $f = uc shift @f;
                next if $f eq 'SEND';
@@ -1103,12 +1110,14 @@ sub import_one
                        $rr = '1';
                } elsif ($f eq '@' && @f) {       # this is bbs syntax, for origin
                        $origin = uc shift @f;
+               } elsif ($f eq '<' && @f) {     # this is bbs syntax  for from call
+                       $from = uc shift @f;
                } elsif ($f =~ /^\$/) {     # this is bbs syntax  for a bid
                        next;
-               } elsif ($f =~ /^</) {     # this is bbs syntax  for from call
+               } elsif ($f =~ /^<\S+/) {     # this is bbs syntax  for from call
                        ($from) = $f =~ /^<(\S+)$/;
-               } elsif ($f eq '<' && @f) {     # this is bbs syntax  for from call
-                       $from = uc shift @f;
+               } elsif ($f =~ /^\@\S+/) {     # this is bbs syntax for origin
+                       ($origin) = $f =~ /^\@(\S+)$/;
                } else {
 
                        # callsign ?
@@ -1147,7 +1156,7 @@ sub import_one
        pop @$ref while (@$ref && ($$ref[-1] eq '' || $$ref[-1] =~ /^\s+$/));
 
        # strip off /EX or /ABORT
-       return () if (@$ref && $$ref[-1] =~ m{^/ABORT$}i); 
+       return ("aborted") if (@$ref && $$ref[-1] =~ m{^/ABORT$}i); 
        pop @$ref if (@$ref && $$ref[-1] =~ m{^/EX$}i);                                                                  
 
     # write all the messages away
@@ -1164,14 +1173,15 @@ sub import_one
                                                        $origin,
                                                        '0',
                                                        $rr);
+               $mref->swop_it($main::mycall);
                $mref->store($ref);
                $mref->add_dir();
-               push @out, $dxchan->msg('m11', $ref->{msgno}, $to);
+               push @out, $dxchan->msg('m11', $mref->{msgno}, $to);
                #push @out, "msgno $ref->{msgno} sent to $to";
                my $todxchan = DXChannel->get(uc $to);
                if ($todxchan) {
                        if ($todxchan->is_user()) {
-                               $todxchan->send($dxchan->msg('m9'));
+                               $todxchan->send($todxchan->msg('m9'));
                        }
                }
        }