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