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