some detail changes
[spider.git] / perl / DXMsg.pm
index e949c6827223b4b5f2b8c8079854f6051c0748ce..f916ff5405da91ca8d27ea4a5383426414fd3070 100644 (file)
@@ -134,9 +134,17 @@ sub process
          my $ref = $work{"$f[1]$f[2]$f[3]"};
          if ($ref) {
            $self->send(DXProt::pc33($f[2], $f[1], $f[3]));# acknowledge it
-               $ref->store($ref->{lines});                    # store it (whatever that may mean)
+               
+               # get the next msg no - note that this has NOTHING to do with the stream number in PC protocol
+                # store the file or message
+                # remove extraneous rubbish from the hash
+                # remove it from the work in progress vector
+                # stuff it on the msg queue
+               $ref->{msgno} = next_transno("Msgno") if !$ref->{file};
+               $ref->store($ref->{lines});             
                $ref->workclean;
-               delete $work{"$f[1]$f[2]$f[3]"};       # remove the reference from the work vector
+               delete $work{"$f[1]$f[2]$f[3]"};       
+               push @msg, $ref;           
          }
          last SWITCH;
        }
@@ -210,29 +218,25 @@ sub store
 #      push @{$ref->{gotit}}, $ref->{fromnode} if $ref->{fromnode};
   } else {              # a normal message
 
-    # get the next msg no - note that this has NOTHING to do with the stream number in PC protocol
-       my $msgno = next_transno("Msgno");
-
     # attempt to open the message file
-       my $fn = filename($msgno);
+       my $fn = filename($ref->{msgno});
 
     dbg('msg', "To be stored in $fn\n");
   
     my $fh = new FileHandle "$fn", "w";
        if (defined $fh) {
-      print $fh "=== $msgno^$ref->{to}^$ref->{from}^$ref->{t}^$ref->{private}^$ref->{subject}^$ref->{origin}^$ref->{read}\n";
+      print $fh "=== $ref->{msgno}^$ref->{to}^$ref->{from}^$ref->{t}^$ref->{private}^$ref->{subject}^$ref->{origin}^$ref->{read}\n";
          print $fh "=== $ref->{fromnode}\n";
          my $line;
+         $ref->{size} = 0;
          foreach $line (@{$lines}) {
         $ref->{size} += (length $line) + 1;
                print $fh "$line\n";
          }
          $ref->{gotit} = [];
-         $ref->{msgno} = $msgno;
          push @{$ref->{gotit}}, $ref->{fromnode} if $ref->{fromnode};
-         push @msg, $ref;           # add this message to the incore message list
          $fh->close;
-         dbg('msg', "msg $msgno stored\n");
+         dbg('msg', "msg $ref->{msgno} stored\n");
     } else {
       confess "can't open msg file $fn $!";  
     }
@@ -314,8 +318,8 @@ sub read_msg_body
   chomp (@out = <$file>);
   close($file);
   
-  shift @out if $out[0] =~ /^=== \d+\^/;
-  shift @out if $out[0] =~ /^=== \d+\^/;
+  shift @out if $out[0] =~ /^=== /;
+  shift @out if $out[0] =~ /^=== /;
   return @out;
 }
 
@@ -374,6 +378,17 @@ sub get_all
   return @msg;
 }
 
+# get a particular message
+sub get
+{
+  my $msgno = shift;
+  for (@msg) {
+    return $_ if $_->{msgno} == $msgno;
+    last if $_->{msgno} > $msgno;
+  }
+  return undef;
+}
+
 # return the official filename for a message no
 sub filename
 {