got a working read message command WITH private marking (ie store works)
authordjk <djk>
Wed, 30 Sep 1998 23:07:57 +0000 (23:07 +0000)
committerdjk <djk>
Wed, 30 Sep 1998 23:07:57 +0000 (23:07 +0000)
cmd/read.pl
perl/DXMsg.pm

index c72be605ba37786b9f907de3869fe74495d0a5db..9df5edad1e68910760ff155d0f61da12bd0b88d2 100644 (file)
@@ -5,3 +5,34 @@
 #
 # $Id$
 #
+
+my ($self, $line) = @_;
+my @f = split /\s+/, $line;
+my $msgno;
+my @out;
+my @body;
+my $ref;
+
+for $msgno (@f) {
+  $ref = DXMsg::get($msgno);
+  if (!$ref) {
+    push @out, "Msg $msgno not found";
+       next;
+  }
+  if ($ref->private && $self->priv < 9 && $ref->to ne $ref->call) {
+    push @out, "Msg $msgno not available";
+       next;
+  }
+  push @out, sprintf "Msg: %d From: %s Date: %6.6s %5.5s Subj: %-30.30s", $msgno,
+                     $ref->from, cldate($ref->t), ztime($ref->t), $ref->subject;
+  @body = $ref->read_msg_body;
+  push @out, @body;
+  
+  # mark my privates as read
+  if ($ref->private && $self->call eq $ref->to && $ref->read == 0) {
+    $ref->read(1);
+    $ref->store(\@body);    # note call by reference!
+  }
+}
+
+return (1, @out);
index e949c6827223b4b5f2b8c8079854f6051c0748ce..47a8e67466e64d9d9c6a3dbbd854669b775c0714 100644 (file)
@@ -134,9 +134,14 @@ 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
+               
+               # get the next msg no - note that this has NOTHING to do with the stream number in PC protocol
+               my $msgno = next_transno("Msgno") if !$ref->{file};
+
                $ref->store($ref->{lines});                    # store it (whatever that may mean)
                $ref->workclean;
                delete $work{"$f[1]$f[2]$f[3]"};       # remove the reference from the work vector
+               push @msg, $ref;           # add this message to the incore message list
          }
          last SWITCH;
        }
@@ -210,17 +215,14 @@ 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;
          foreach $line (@{$lines}) {
@@ -228,11 +230,9 @@ sub store
                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 +314,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 +374,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
 {