1845b4d1516720ddf97951871791aa216dcd49de
[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) {
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         $ref->read($ref->read() + 1);
46         $ref->store(\@body);    # note call by reference!
47
48         # if it had a read receipt on it generate a new message to send back to
49         # the sender.
50         if ($ref->rrreq) {
51                 my $sub = $ref->subject;
52                 $sub = "Re: $sub" unless $sub =~ /^\s*re:/i;
53                 my $to = $ref->to;
54                 my $from = $ref->from;
55                 my $rref = DXMsg->alloc(1, $from, $main::mycall, time, 
56                                                                 1, $sub, $main::mycall, 0, 0 );
57                 my $msgno = DXMsg::next_transno("Msgno");
58                 $rref->msgno($msgno);
59                 $rref->gotit( [ "$main::mycall" ] );
60                 $rref->store( [ "Return receipt from delivering node. Message read by $to." ] );
61                 DXMsg::add_dir($rref);
62                 DXMsg::queue_msg(0);
63         }
64         
65         # remember this one as the last one read
66         $self->lastread($msgno);
67 }
68
69 return (1, @out);
70
71