1. fix read so that sysop reading doesn't increment the read counter for
[spider.git] / cmd / read.pl
1 #
2 # read a message
3 #
4 # Copyright (c) Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my @f = split /\s+/, $line;
11 my $msgno;
12 my @out;
13 my @body;
14 my $ref;
15
16 # if there are no specified message numbers, try and find a private one
17 # that I haven't read yet
18 if (@f == 0) {
19         foreach $ref (DXMsg::get_all()) {
20                 if ($ref->to eq $self->call && $ref->private && !$ref->read && !$ref->delete) {
21                         push @f, $ref->msgno;
22                         last;
23                 }
24         }
25 }
26
27 return (1, $self->msg('read1')) if @f == 0;
28
29 for $msgno (@f) {
30         $ref = DXMsg::get($msgno);
31         if (!$ref) {
32                 push @out, $self->msg('read2', $msgno);
33                 next;
34         }
35         if ($self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call ) {
36                 push @out, $self->msg('read3', $msgno);
37                 next;
38         }
39         push @out, sprintf "Msg: %d From: %s Date: %6.6s %5.5s Subj: %-30.30s", $msgno,
40                 $ref->from, cldate($ref->t), ztime($ref->t), $ref->subject;
41         @body = $ref->read_msg_body;
42         push @out, @body;
43         
44         # mark it as read
45         unless ($ref->private && $ref->to ne $self->call) {
46                 $ref->read($ref->read() + 1);
47                 $ref->store(\@body);    # note call by reference!
48
49                 # if it had a read receipt on it generate a new message to send back to
50                 # the sender.
51                 if ($ref->rrreq) {
52                         my $sub = $ref->subject;
53                         $sub = "Re: $sub" unless $sub =~ /^\s*re:/i;
54                         my $to = $ref->to;
55                         my $from = $ref->from;
56                         my $rref = DXMsg->alloc(1, $from, $main::mycall, time, 
57                                                                         1, $sub, $main::mycall, 0, 0 );
58                         my $msgno = DXMsg::next_transno("Msgno");
59                         $rref->msgno($msgno);
60                         $rref->gotit( [ "$main::mycall" ] );
61                         $rref->store( [ "Return receipt from delivering node. Message read by $to." ] );
62                         DXMsg::add_dir($rref);
63                         DXMsg::queue_msg(0);
64                 }
65         
66                 # remember this one as the last one read
67                 $self->lastread($msgno);
68         }
69 }
70
71 return (1, @out);
72
73