fix sending msgs to g1tlh-2 (and not to g1tlh, - and 2)
[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 return (1, $self->msg('e5')) if $self->remotecmd;
21
22 my @out;
23 my $loc = $self->{loc} = {};
24 my $notincalls = 1;
25 my @to;
26
27 # set up defaults
28 $loc->{private} = '1';
29 $loc->{rrreq} = '0';
30
31 # $DB::single = 1;
32
33 if ($self->state eq "prompt") {
34
35         my @f = split /([\s\@\$])/, $line;
36         @f = map {s/\s+//g; length $_ ? $_ : ()} @f;
37         
38         # any thing after send?
39         return (1, $self->msg('e6')) if !@f;
40
41         while (@f) {
42                 my $f = uc shift @f; 
43
44                 # first deal with copies
45                 if ($f eq 'C' || $f eq 'CC' || $f eq 'COPY') {
46                         my $rr = '0';
47                         if (@f && uc $f[0] eq 'RR') {
48                                 shift @f;
49                                 $rr = '1';
50                         }
51                         
52                         if (@f) {
53                                 my $m = shift @f;
54                                 my $oref = DXMsg::get($m);
55                                 return (0, $self->msg('m4', $m)) unless $oref;
56                                 return (0, $self->msg('m16')) unless @f;
57                         
58                                 # separate copy to everyone listed
59                                 while (@f) {
60                                         my $newcall = uc shift @f;
61                                         my $msgno = DXMsg::next_transno('Msgno');
62                                         my $newsubj = "CC: " . $oref->subject;
63                                         my $nref = DXMsg->alloc($msgno, 
64                                                                                         $newcall, 
65                                                                                         $self->call,  
66                                                                                         $main::systime, 
67                                                                                         '1',  
68                                                                                         $newsubj, 
69                                                                                         $main::mycall,
70                                                                                         '0',
71                                                                                         $rr);
72                                         my @list;
73                                         my $from = $oref->from;
74                                         my $to = $oref->to;
75                                         my $date = cldate($oref->t);
76                                         my $time = ztime($oref->t);
77                                         my $buf = "Original from: $from To: $to Date: $date $time";
78                                         push @list, $buf; 
79                                         push @list, $oref->read_msg_body();
80                                         $nref->store(\@list);
81                                         $nref->add_dir();
82                                         push @out, $self->msg('m2', $oref->msgno, $newcall);
83                                 } 
84                         }
85                         DXMsg::queue_msg();
86                         return (1, @out);
87                 }
88
89                 # private / noprivate / rr
90                 if ($notincalls && ($f eq 'B' || $f =~ /^NOP/oi)) {
91                         $loc->{private} = '0';
92                 } elsif ($notincalls && ($f eq 'P' || $f =~ /^PRI/oi)) {
93                         ;
94                 } elsif ($notincalls && ($f eq 'RR')) {
95                         $loc->{rrreq} = '1';
96                 } elsif ($f eq '<' && @f) {     # this is bbs syntax  for from call
97                         $loc->{from} = uc shift @f;
98                 } elsif (($f =~ /^[\@\.\#\$]$/ || $f eq '.#') && @f) {       # this is bbs syntax, for send it 'to node'
99                         shift @f;
100                 } elsif ($f =~ /^\$/) {     # this is bbs syntax  for a bid
101                         next;
102                 } elsif ($f =~ /^<(\S+)/) {     # this is bbs syntax  for from call
103                         $loc->{from} = $1;
104                 } elsif ($f =~ /^\$\S+/) {     # this is bbs syntax  for bid
105                         ;
106                 } else {
107
108                         # callsign ?
109                         $notincalls = 0;
110
111                         # is this callsign a distro?
112                         my $fn = "/spider/msg/distro/$f.pl";
113                         if (-e $fn) {
114                                 my $fh = new IO::File $fn;
115                                 if ($fh) {
116                                         local $/ = undef;
117                                         my $s = <$fh>;
118                                         $fh->close;
119                                         my @call;
120                                         @call = eval $s;
121                                         return (1, "Error in Distro $f.pl:", $@) if $@;
122                                         if (@call > 0) {
123                                                 push @f, @call;
124                                                 next;
125                                         }
126                                 }
127                         }
128
129                         if (grep $_ eq $f, @DXMsg::badmsg) {
130                                 push @out, $self->msg('m3', $f);
131                         } else {
132                                 push @to, $f;
133                         }
134                 }
135         }
136
137         # check we have some callsigns
138         if (@to) {
139                 $loc->{to} = \@to;
140         } else {
141                 delete $self->{loc};
142                 return (1, $self->msg('e6'));
143         }
144         $loc->{from} ||= $self->call;
145         unless (is_callsign($loc->{from})) {
146                 delete $self->{loc};
147                 return (1, $self->msg('e22', $loc->{from}));
148         }
149
150         # find me and set the state and the function on my state variable to
151         # keep calling me for every line until I relinquish control
152         $self->func("DXMsg::do_send_stuff");
153         $self->state('send1');
154         push @out, $self->msg('m1');
155 } else {
156         push @out, $self->msg('m17', $self->state);
157 }
158
159 return (1, @out);