1. changed help command so that it works correctly with multiple title lines.
[spider.git] / cmd / send.pl
1 #
2 # send a message
3 #
4 # this should handle
5 #
6 # send <call> [<call> .. ]
7 # send private <call> [<call> .. ]
8 # send private rr <call> [<call> .. ]
9 # send rr <call> [<call> .. ]
10 # send noprivate <call> [<call> .. ]
11 # send b <call> [<call> .. ]
12 # send copy <call> [<call> .. ]
13 # send copy rr <call> [<call> .. ]
14
15 # Copyright (c) Dirk Koopman G1TLH
16 #
17 # $Id$
18 #
19 my ($self, $line) = @_;
20 my @out;
21 my $loc;
22
23 # $DB::single = 1;
24
25 if ($self->state eq "prompt") {
26
27         my @f = split /\s+/, $line;
28
29         # any thing after send?
30         return (1, $self->msg('e6')) if !@f;
31   
32         $f[0] = uc $f[0];
33   
34         # first deal with copies
35         if ($f[0] eq 'C' || $f[0] eq 'CC' || $f[0] eq 'COPY') {
36                 my $i = 1;
37                 my $rr = '0';
38                 if (uc $f[$i] eq 'RR') {
39                         $rr = '1';
40                         $i++;
41                 }
42                 my $oref = DXMsg::get($f[$i]);
43                 #return (0, $self->msg('esend1', $f[$i])) if !$oref;
44                 #return (0, $self->msg('esend2')) if $i+1 >  @f;
45                 return (0, "msgno $f[$i] not found") if !$oref;
46                 return (0, "need a callsign") if $i+1 >  @f;
47       
48                 # separate copy to everyone listed
49                 for ($i++ ; $i < @f; $i++) {
50                         my $msgno = DXMsg::next_transno('Msgno');
51                         my $newsubj = "CC: " . $oref->subject;
52                         my $newcall = uc $f[$i];
53                         my $nref = DXMsg->alloc($msgno, 
54                                                                         $newcall, 
55                                                                         $self->call,  
56                                                                         $main::systime, 
57                                                                         '1',  
58                                                                         $newsubj, 
59                                                                         $main::mycall,
60                                                                         '0',
61                                                                         $rr);
62                         my @list;
63                         my $from = $oref->from;
64                         my $to = $oref->to;
65                         my $date = cldate($oref->t);
66                         my $time = ztime($oref->t);
67                         my $buf = "Original from: $from To: $to Date: $date $time";
68                         push @list, $buf; 
69                         push @list, $oref->read_msg_body();
70                         $nref->store(\@list);
71                         $nref->add_dir();
72                         push @out, $self->msg('m2', $oref->msgno, $newcall);
73                 }
74                 DXMsg::queue_msg();
75                 return (1, @out);
76         }
77
78         # now deal with real message inputs 
79         # parse out send line for various possibilities
80         $loc = $self->{loc} = {};
81   
82         my $i = 0;
83         $f[0] = uc $f[0];
84         $loc->{private} = '1';
85         if ($f[0] eq 'B' || $f[0] =~ /^NOP/oi) {
86                 $loc->{private} = '0';
87                 $i += 1;
88         } elsif ($f[0] eq 'P' || $f[0] =~ /^PRI/oi) {
89                 $i += 1;
90         }
91   
92         $loc->{rrreq} = '0';
93         if (uc $f[$i] eq 'RR') {
94                 $loc->{rrreq} = '1';
95                 $i++;
96         }
97   
98         # check we have some callsigns
99         if ($i  >=  @f) {
100                 delete $self->{loc};
101                 return (1, $self->msg('e6'));
102         }
103
104         # now save all the 'to' callsigns for later
105         # first check the 'to' addresses for 'badness'
106     my $t;
107         my @to;
108         splice @f, 0, $i-1 if $i > 0;
109         foreach  $t (@f) {
110                 $t = uc $t;
111
112         # is this callsign a distro?
113                 my $fn = "/spider/msg/distro/$t.pl";
114                 if (-e $fn) {
115                         my $fh = new IO::File $fn;
116                         if ($fh) {
117                                 local $/ = undef;
118                                 my $s = <$fh>;
119                                 $fh->close;
120                                 my @call;
121                 @call = eval $s;
122                                 return (1, "Error in Distro $t.pl:", $@) if $@;
123                                 if (@call > 0) {
124                                         push @f, @call;
125                                         next;
126                                 }
127                         }
128                 }
129                 if (grep $_ eq $t, @DXMsg::badmsg) {
130                         push @out, $self->msg('m3', $t);
131                 } else {
132                         push @to, $t;
133                 }
134         }
135         if (@to) {
136                 $loc->{to} = \@to;
137         } else {
138                 return (1, @out);
139         }
140
141         # find me and set the state and the function on my state variable to
142         # keep calling me for every line until I relinquish control
143         $self->func("DXMsg::do_send_stuff");
144         $self->state('send1');
145         push @out, $self->msg('m1');
146 }
147
148 return (1, @out);