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