8667d0cc35edf80ae0e21ea4a088e469c9c37bfc
[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   $f[0] = uc $f[0];
30   
31   # first deal with copies
32   if ($f[0] eq 'C' || $f[0] eq 'CC' || $f[0] eq 'COPY') {
33     my $i = 1;
34         my $rr = '0';
35         if (uc $f[$i] eq 'RR') {
36           $rr = '1';
37           $i++;
38         }
39         my $oref = DXMsg::get($f[$i]);
40     #return (0, $self->msg('esend1', $f[$i])) if !$oref;
41         #return (0, $self->msg('esend2')) if $i+1 >  @f;
42     return (0, "msgno $f[$i] not found") if !$oref;
43         return (0, "need a callsign") if $i+1 >  @f;
44       
45         # separate copy to everyone listed
46         for ($i++ ; $i < @f; $i++) {
47           my $msgno = DXMsg::next_transno('Msgno');
48           my $newsubj = "CC: " . $oref->subject;
49           my $nref = DXMsg->alloc($msgno, 
50                                   uc $f[$i], 
51                                   $self->call,  
52                                                           $main::systime, 
53                                                           '1',  
54                                                           $newsubj, 
55                                                           $main::mycall, $rr);
56           my @list;
57           my $from = $oref->from;
58           my $to = $oref->to;
59           my $date = cldate($oref->t);
60           my $time = ztime($oref->t);
61           my $buf = "Original from: $from To: $to Date: $date $time";
62           push @list, $buf; 
63           push @list, $oref->read_msg_body();
64           $nref->store(\@list);
65           $nref->add_dir();
66           #push @out, $self->msg('sendcc', $oref->msgno, $f[$i]);
67           push @out, "copy of msg $oref->{msgno} sent to $to";
68         }
69         DXMsg::queue_msg();
70         return (1, @out);
71   }
72
73   # now deal with real message inputs 
74   # parse out send line for various possibilities
75   $loc = $self->{loc} = {};
76   
77   my $i = 0;
78   $f[0] = uc $f[0];
79   $loc->{private} = '1';
80   if ($f[0] eq 'B' || $f[0] =~ /^NOP/oi) {
81     $loc->{private} = '0';
82         $i += 1;
83   } elsif ($f[0] eq 'P' || $f[0] =~ /^PRI/oi) {
84     $i += 1;
85   }
86   
87   $loc->{rrreq} = '0';
88   if (uc $f[$i] eq 'RR') {
89     $loc->{rrreq} = '1';
90         $i++;
91   }
92   
93   # check we have some callsigns
94   if ($i  >  @f) {
95     delete $self->{loc};
96     #return (0, $self->msg('esend2'));
97     return (0, "need a callsign");
98   }
99   
100   # now save all the 'to' callsigns for later
101   my @to = @f[ $i..$#f ];
102   $loc->{to} = \@to;
103
104   # find me and set the state and the function on my state variable to
105   # keep calling me for every line until I relinquish control
106   $self->func("DXMsg::do_send_stuff");
107   $self->state('send1');
108   #push @out, $self->msg('sendsubj');
109   push @out, "Enter Subject (30 characters) >";
110 }
111
112 return (1, @out);