1. Crossed fingers, got rid of the instabilities caused by execing programs
[spider.git] / perl / DXMsg.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the message handling for a dx cluster
4 #
5 # Copyright (c) 1998 Dirk Koopman G1TLH
6 #
7 # $Id$
8 #
9 #
10 # Notes for implementors:-
11 #
12 # PC28 field 11 is the RR required flag
13 # PC28 field 12 is a VIA routing (ie it is a node call) 
14
15 package DXMsg;
16
17 @ISA = qw(DXProt DXChannel);
18
19 use DXUtil;
20 use DXChannel;
21 use DXUser;
22 use DXM;
23 use DXCluster;
24 use DXProtVars;
25 use DXProtout;
26 use DXDebug;
27 use DXLog;
28 use FileHandle;
29 use Carp;
30
31 use strict;
32 use vars qw(%work @msg $msgdir %valid %busy $maxage $last_clean);
33
34 %work = ();                                             # outstanding jobs
35 @msg = ();                                              # messages we have
36 %busy = ();                                             # station interlocks
37 $msgdir = "$main::root/msg";    # directory contain the msgs
38 $maxage = 30 * 86400;                   # the maximum age that a message shall live for if not marked 
39 $last_clean = 0;                                # last time we did a clean
40
41 %valid = (
42                   fromnode => '9,From Node',
43                   tonode => '9,To Node',
44                   to => '0,To',
45                   from => '0,From',
46                   t => '0,Msg Time,cldatetime',
47                   private => '9,Private',
48                   subject => '0,Subject',
49                   linesreq => '0,Lines per Gob',
50                   rrreq => '9,Read Confirm',
51                   origin => '0,Origin',
52                   lines => '5,Data',
53                   stream => '9,Stream No',
54                   count => '9,Gob Linecnt',
55                   file => '9,File?,yesno',
56                   gotit => '9,Got it Nodes,parray',
57                   lines => '9,Lines,parray',
58                   'read' => '9,Times read',
59                   size => '0,Size',
60                   msgno => '0,Msgno',
61                   keep => '0,Keep this?,yesno',
62                  );
63
64 # allocate a new object
65 # called fromnode, tonode, from, to, datetime, private?, subject, nolinesper  
66 sub alloc                  
67 {
68         my $pkg = shift;
69         my $self = bless {}, $pkg;
70         $self->{msgno} = shift;
71         my $to = shift;
72         #  $to =~ s/-\d+$//o;
73         $self->{to} = $to;
74         my $from = shift;
75         $from =~ s/-\d+$//o;
76         $self->{from} = uc $from;
77         $self->{t} = shift;
78         $self->{private} = shift;
79         $self->{subject} = shift;
80         $self->{origin} = shift;
81         $self->{'read'} = shift;
82         $self->{rrreq} = shift;
83         $self->{gotit} = [];
84     
85         return $self;
86 }
87
88 sub workclean
89 {
90         my $ref = shift;
91         delete $ref->{lines};
92         delete $ref->{linesreq};
93         delete $ref->{tonode};
94         delete $ref->{fromnode};
95         delete $ref->{stream};
96         delete $ref->{lines};
97         delete $ref->{file};
98         delete $ref->{count};
99 }
100
101 sub process
102 {
103         my ($self, $line) = @_;
104         my @f = split /[\^\~]/, $line;
105         my ($pcno) = $f[0] =~ /^PC(\d\d)/; # just get the number
106         
107  SWITCH: {
108                 if ($pcno == 28) {              # incoming message
109                         my $t = cltounix($f[5], $f[6]);
110                         my $stream = next_transno($f[2]);
111                         my $ref = DXMsg->alloc($stream, uc $f[3], $f[4], $t, $f[7], $f[8], $f[13], '0', $f[11]);
112                         
113                         # fill in various forwarding state variables
114                         $ref->{fromnode} = $f[2];
115                         $ref->{tonode} = $f[1];
116                         $ref->{rrreq} = $f[11];
117                         $ref->{linesreq} = $f[10];
118                         $ref->{stream} = $stream;
119                         $ref->{count} = 0;      # no of lines between PC31s
120                         dbg('msg', "new message from $f[4] to $f[3] '$f[8]' stream $stream\n");
121                         $work{"$f[2]$stream"} = $ref; # store in work
122                         $busy{$f[2]} = $ref; # set interlock
123                         $self->send(DXProt::pc30($f[2], $f[1], $stream)); # send ack
124                         last SWITCH;
125                 }
126                 
127                 if ($pcno == 29) {              # incoming text
128                         my $ref = $work{"$f[2]$f[3]"};
129                         if ($ref) {
130                                 push @{$ref->{lines}}, $f[4];
131                                 $ref->{count}++;
132                                 if ($ref->{count} >= $ref->{linesreq}) {
133                                         $self->send(DXProt::pc31($f[2], $f[1], $f[3]));
134                                         dbg('msg', "stream $f[3]: $ref->{count} lines received\n");
135                                         $ref->{count} = 0;
136                                 }
137                         }
138                         last SWITCH;
139                 }
140                 
141                 if ($pcno == 30) {              # this is a incoming subject ack
142                         my $ref = $work{$f[2]}; # note no stream at this stage
143                         if ($ref) {
144                                 delete $work{$f[2]};
145                                 $ref->{stream} = $f[3];
146                                 $ref->{count} = 0;
147                                 $ref->{linesreq} = 5;
148                                 $work{"$f[2]$f[3]"} = $ref;     # new ref
149                                 dbg('msg', "incoming subject ack stream $f[3]\n");
150                                 $busy{$f[2]} = $ref; # interlock
151                                 $ref->{lines} = [];
152                                 push @{$ref->{lines}}, ($ref->read_msg_body);
153                                 $ref->send_tranche($self);
154                         } else {
155                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
156                         } 
157                         last SWITCH;
158                 }
159                 
160                 if ($pcno == 31) {              # acknowledge a tranche of lines
161                         my $ref = $work{"$f[2]$f[3]"};
162                         if ($ref) {
163                                 dbg('msg', "tranche ack stream $f[3]\n");
164                                 $ref->send_tranche($self);
165                         } else {
166                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
167                         } 
168                         last SWITCH;
169                 }
170                 
171                 if ($pcno == 32) {              # incoming EOM
172                         dbg('msg', "stream $f[3]: EOM received\n");
173                         my $ref = $work{"$f[2]$f[3]"};
174                         if ($ref) {
175                                 $self->send(DXProt::pc33($f[2], $f[1], $f[3])); # acknowledge it
176                                 
177                                 # get the next msg no - note that this has NOTHING to do with the stream number in PC protocol
178                                 # store the file or message
179                                 # remove extraneous rubbish from the hash
180                                 # remove it from the work in progress vector
181                                 # stuff it on the msg queue
182                                 if ($ref->{lines} && @{$ref->{lines}} > 0) { # ignore messages with 0 lines
183                                         if ($ref->{file}) {
184                                                 $ref->store($ref->{lines});
185                                         } else {
186
187                                                 # does an identical message already exist?
188                                                 my $m;
189                                                 for $m (@msg) {
190                                                         if ($ref->{subject} eq $m->{subject} && $ref->{t} == $m->{t} && $ref->{from} eq $m->{from}) {
191                                                                 $ref->stop_msg($self);
192                                                                 my $msgno = $m->{msgno};
193                                                                 dbg('msg', "duplicate message to $msgno\n");
194                                                                 Log('msg', "duplicate message to $msgno");
195                                                                 return;
196                                                         }
197                                                 }
198
199                                                 $ref->{msgno} = next_transno("Msgno");
200                                                 push @{$ref->{gotit}}, $f[2]; # mark this up as being received
201                                                 $ref->store($ref->{lines});
202                                                 add_dir($ref);
203                                                 my $dxchan = DXChannel->get($ref->{to});
204                                                 $dxchan->send("New mail has arrived for you") if $dxchan;
205                                                 Log('msg', "Message $ref->{msgno} from $ref->{from} received from $f[2] for $ref->{to}");
206                                         }
207                                 }
208                                 $ref->stop_msg($self);
209                                 queue_msg(0);
210                         } else {
211                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
212                         }
213                         queue_msg(0);
214                         last SWITCH;
215                 }
216                 
217                 if ($pcno == 33) {              # acknowledge the end of message
218                         my $ref = $work{"$f[2]$f[3]"};
219                         if ($ref) {
220                                 if ($ref->{private}) { # remove it if it private and gone off site#
221                                         Log('msg', "Message $ref->{msgno} from $ref->{from} sent to $f[2] and deleted");
222                                         $ref->del_msg;
223                                 } else {
224                                         Log('msg', "Message $ref->{msgno} from $ref->{from} sent to $f[2]");
225                                         push @{$ref->{gotit}}, $f[2]; # mark this up as being received
226                                         $ref->store($ref->{lines});     # re- store the file
227                                 }
228                                 $ref->stop_msg($self);
229                         } else {
230                                 $self->send(DXProt::pc42($f[2], $f[1], $f[3])); # unknown stream
231                         } 
232                         queue_msg(0);
233                         last SWITCH;
234                 }
235                 
236                 if ($pcno == 40) {              # this is a file request
237                         $f[3] =~ s/\\/\//og; # change the slashes
238                         $f[3] =~ s/\.//og;      # remove dots
239                         $f[3] =~ s/^\///o;   # remove the leading /
240                         $f[3] = lc $f[3];       # to lower case;
241                         dbg('msg', "incoming file $f[3]\n");
242                         last SWITCH if $f[3] =~ /^(perl|cmd|local|src|lib|include|sys|msg|connect)/; # prevent access to executables
243                         
244                         # create any directories
245                         my @part = split /\//, $f[3];
246                         my $part;
247                         my $fn = "$main::root";
248                         pop @part;                      # remove last part
249                         foreach $part (@part) {
250                                 $fn .= "/$part";
251                                 next if -e $fn;
252                                 last SWITCH if !mkdir $fn, 0777;
253                                 dbg('msg', "created directory $fn\n");
254                         }
255                         my $stream = next_transno($f[2]);
256                         my $ref = DXMsg->alloc($stream, "$main::root/$f[3]", $self->call, time, !$f[4], $f[3], ' ', '0', '0');
257                         
258                         # forwarding variables
259                         $ref->{fromnode} = $f[1];
260                         $ref->{tonode} = $f[2];
261                         $ref->{linesreq} = $f[5];
262                         $ref->{stream} = $stream;
263                         $ref->{count} = 0;      # no of lines between PC31s
264                         $ref->{file} = 1;
265                         $work{"$f[2]$stream"} = $ref; # store in work
266                         $self->send(DXProt::pc30($f[2], $f[1], $stream)); # send ack 
267                         
268                         last SWITCH;
269                 }
270                 
271                 if ($pcno == 42) {              # abort transfer
272                         dbg('msg', "stream $f[3]: abort received\n");
273                         my $ref = $work{"$f[2]$f[3]"};
274                         if ($ref) {
275                                 $ref->stop_msg($self);
276                                 $ref = undef;
277                         }
278                         
279                         last SWITCH;
280                 }
281
282                 if ($pcno == 49) {      # global delete on subject
283                         for (@msg) {
284                                 if ($_->{subject} eq $f[2]) {
285                                         $_->del_msg();
286                                         Log('msg', "Message $_->{msgno} fully deleted by $f[1]");
287                                 }
288                         }
289                 }
290         }
291         
292         clean_old() if $main::systime - $last_clean > 3600 ; # clean the message queue
293 }
294
295
296 # store a message away on disc or whatever
297 #
298 # NOTE the second arg is a REFERENCE not a list
299 sub store
300 {
301         my $ref = shift;
302         my $lines = shift;
303         
304         # we only proceed if there are actually any lines in the file
305         if (!$lines || @{$lines} == 0) {
306                 return;
307         }
308         
309         if ($ref->{file}) {                     # a file
310                 dbg('msg', "To be stored in $ref->{to}\n");
311                 
312                 my $fh = new FileHandle "$ref->{to}", "w";
313                 if (defined $fh) {
314                         my $line;
315                         foreach $line (@{$lines}) {
316                                 print $fh "$line\n";
317                         }
318                         $fh->close;
319                         dbg('msg', "file $ref->{to} stored\n");
320                         Log('msg', "file $ref->{to} from $ref->{from} stored" );
321                 } else {
322                         confess "can't open file $ref->{to} $!";  
323                 }
324         } else {                                        # a normal message
325
326                 # attempt to open the message file
327                 my $fn = filename($ref->{msgno});
328                 
329                 dbg('msg', "To be stored in $fn\n");
330                 
331                 # now save the file, overwriting what's there, YES I KNOW OK! (I will change it if it's a problem)
332                 my $fh = new FileHandle "$fn", "w";
333                 if (defined $fh) {
334                         my $rr = $ref->{rrreq} ? '1' : '0';
335                         my $priv = $ref->{private} ? '1': '0';
336                         print $fh "=== $ref->{msgno}^$ref->{to}^$ref->{from}^$ref->{t}^$priv^$ref->{subject}^$ref->{origin}^$ref->{'read'}^$rr\n";
337                         print $fh "=== ", join('^', @{$ref->{gotit}}), "\n";
338                         my $line;
339                         $ref->{size} = 0;
340                         foreach $line (@{$lines}) {
341                                 $ref->{size} += (length $line) + 1;
342                                 print $fh "$line\n";
343                         }
344                         $fh->close;
345                         dbg('msg', "msg $ref->{msgno} stored\n");
346                         Log('msg', "msg $ref->{msgno} from $ref->{from} to $ref->{to} stored" );
347                 } else {
348                         confess "can't open msg file $fn $!";  
349                 }
350         }
351 }
352
353 # delete a message
354 sub del_msg
355 {
356         my $self = shift;
357         
358         # remove it from the active message list
359         @msg = map { $_ != $self ? $_ : () } @msg;
360         
361         # belt and braces (one day I will ask someone if this is REALLY necessary)
362         delete $self->{gotit};
363         delete $self->{list};
364         
365         # remove the file
366         unlink filename($self->{msgno});
367         dbg('msg', "deleting $self->{msgno}\n");
368 }
369
370 # clean out old messages from the message queue
371 sub clean_old
372 {
373         my $ref;
374         
375         # mark old messages for deletion
376         foreach $ref (@msg) {
377                 if (!$ref->{keep} && $ref->{t} < $main::systime - $maxage) {
378                         $ref->{deleteme} = 1;
379                         delete $ref->{gotit};
380                         delete $ref->{list};
381                         unlink filename($ref->{msgno});
382                         dbg('msg', "deleting old $ref->{msgno}\n");
383                 }
384         }
385         
386         # remove them all from the active message list
387         @msg = map { $_->{deleteme} ? () : $_ } @msg;
388         $last_clean = $main::systime;
389 }
390
391 # read in a message header
392 sub read_msg_header
393
394         my $fn = shift;
395         my $file;
396         my $line;
397         my $ref;
398         my @f;
399         my $size;
400         
401         $file = new FileHandle;
402         if (!open($file, $fn)) {
403                 print "Error reading $fn $!\n";
404                 return undef;
405         }
406         $size = -s $fn;
407         $line = <$file>;                        # first line
408         chomp $line;
409         $size -= length $line;
410         if (! $line =~ /^===/o) {
411                 print "corrupt first line in $fn ($line)\n";
412                 return undef;
413         }
414         $line =~ s/^=== //o;
415         @f = split /\^/, $line;
416         $ref = DXMsg->alloc(@f);
417         
418         $line = <$file>;                        # second line
419         chomp $line;
420         $size -= length $line;
421         if (! $line =~ /^===/o) {
422                 print "corrupt second line in $fn ($line)\n";
423                 return undef;
424         }
425         $line =~ s/^=== //o;
426         $ref->{gotit} = [];
427         @f = split /\^/, $line;
428         push @{$ref->{gotit}}, @f;
429         $ref->{size} = $size;
430         
431         close($file);
432         
433         return $ref;
434 }
435
436 # read in a message header
437 sub read_msg_body
438 {
439         my $self = shift;
440         my $msgno = $self->{msgno};
441         my $file;
442         my $line;
443         my $fn = filename($msgno);
444         my @out;
445         
446         $file = new FileHandle;
447         if (!open($file, $fn)) {
448                 print "Error reading $fn $!\n";
449                 return undef;
450         }
451         chomp (@out = <$file>);
452         close($file);
453         
454         shift @out if $out[0] =~ /^=== /;
455         shift @out if $out[0] =~ /^=== /;
456         return @out;
457 }
458
459 # send a tranche of lines to the other end
460 sub send_tranche
461 {
462         my ($self, $dxchan) = @_;
463         my @out;
464         my $to = $self->{tonode};
465         my $from = $self->{fromnode};
466         my $stream = $self->{stream};
467         my $lines = $self->{lines};
468         my ($c, $i);
469         
470         for ($i = 0, $c = $self->{count}; $i < $self->{linesreq} && $c < @$lines; $i++, $c++) {
471                 push @out, DXProt::pc29($to, $from, $stream, $lines->[$c]);
472     }
473     $self->{count} = $c;
474
475     push @out, DXProt::pc32($to, $from, $stream) if $i < $self->{linesreq};
476         $dxchan->send(@out);
477 }
478
479         
480 # find a message to send out and start the ball rolling
481 sub queue_msg
482 {
483         my $sort = shift;
484         my $call = shift;
485         my $ref;
486         my $clref;
487         my $dxchan;
488         my @nodelist = DXProt::get_all_ak1a();
489         
490         # bat down the message list looking for one that needs to go off site and whose
491         # nearest node is not busy.
492
493         dbg('msg', "queue msg ($sort)\n");
494         foreach $ref (@msg) {
495                 # firstly, is it private and unread? if so can I find the recipient
496                 # in my cluster node list offsite?
497                 if ($ref->{private}) {
498                         if ($ref->{'read'} == 0) {
499                                 $clref = DXCluster->get_exact($ref->{to});
500                                 unless ($clref) {             # otherwise look for a homenode
501                                         my $uref = DXUser->get($ref->{to});
502                                         my $hnode =  $uref->homenode if $uref;
503                                         $clref = DXCluster->get_exact($hnode) if $hnode;
504                                 }
505                                 if ($clref && !grep { $clref->{dxchan} == $_ } DXCommandmode::get_all) {
506                                         $dxchan = $clref->{dxchan};
507                                         $ref->start_msg($dxchan) if $clref && !get_busy($dxchan->call) && $dxchan->state eq 'normal';
508                                 }
509                         }
510                 } elsif (!$sort) {
511                         # otherwise we are dealing with a bulletin, compare the gotit list with
512                         # the nodelist up above, if there are sites that haven't got it yet
513                         # then start sending it - what happens when we get loops is anyone's
514                         # guess, use (to, from, time, subject) tuple?
515                         my $noderef;
516                         foreach $noderef (@nodelist) {
517                                 next if $noderef->call eq $main::mycall;
518                                 next if $noderef->isolate;               # maybe add code for stuff originated here?
519                                 next if grep { $_ eq $noderef->call } @{$ref->{gotit}};
520                                 
521                                 # if we are here we have a node that doesn't have this message
522                                 $ref->start_msg($noderef) if !get_busy($noderef->call)  && $noderef->state eq 'normal';
523                                 last;
524                         }
525                 }
526                 
527                 # if all the available nodes are busy then stop
528                 last if @nodelist == scalar grep { get_busy($_->call) } @nodelist;
529         }
530 }
531
532 # start the message off on its travels with a PC28
533 sub start_msg
534 {
535         my ($self, $dxchan) = @_;
536         
537         dbg('msg', "start msg $self->{msgno}\n");
538         $self->{linesreq} = 5;
539         $self->{count} = 0;
540         $self->{tonode} = $dxchan->call;
541         $self->{fromnode} = $main::mycall;
542         $busy{$dxchan->call} = $self;
543         $work{"$self->{tonode}"} = $self;
544         $dxchan->send(DXProt::pc28($self->{tonode}, $self->{fromnode}, $self->{to}, $self->{from}, $self->{t}, $self->{private}, $self->{subject}, $self->{origin}, $self->{rrreq}));
545 }
546
547 # get the ref of a busy node
548 sub get_busy
549 {
550         my $call = shift;
551         return $busy{$call};
552 }
553
554 # get the busy queue
555 sub get_all_busy
556 {
557         return values %busy;
558 }
559
560 # get the forwarding queue
561 sub get_fwq
562 {
563         return values %work;
564 }
565
566 # stop a message from continuing, clean it out, unlock interlocks etc
567 sub stop_msg
568 {
569         my ($self, $dxchan) = @_;
570         my $node = $dxchan->call;
571         
572         dbg('msg', "stop msg $self->{msgno} stream $self->{stream}\n");
573         delete $work{$node};
574         delete $work{"$node$self->{stream}"};
575         $self->workclean;
576         delete $busy{$node};
577 }
578
579 # get a new transaction number from the file specified
580 sub next_transno
581 {
582         my $name = shift;
583         $name =~ s/\W//og;                      # remove non-word characters
584         my $fn = "$msgdir/$name";
585         my $msgno;
586         
587         my $fh = new FileHandle;
588         if (sysopen($fh, $fn, O_RDWR|O_CREAT, 0666)) {
589                 $fh->autoflush(1);
590                 $msgno = $fh->getline;
591                 chomp $msgno;
592                 $msgno++;
593                 seek $fh, 0, 0;
594                 $fh->print("$msgno\n");
595                 dbg('msg', "msgno $msgno allocated for $name\n");
596                 $fh->close;
597         } else {
598                 confess "can't open $fn $!";
599         }
600         return $msgno;
601 }
602
603 # initialise the message 'system', read in all the message headers
604 sub init
605 {
606         my $dir = new FileHandle;
607         my @dir;
608         my $ref;
609         
610         # read in the directory
611         opendir($dir, $msgdir) or confess "can't open $msgdir $!";
612         @dir = readdir($dir);
613         closedir($dir);
614         
615         for (sort @dir) {
616                 next if /^\./o;
617                 next if ! /^m\d+/o;
618                 
619                 $ref = read_msg_header("$msgdir/$_");
620                 next if !$ref;
621                 
622                 # add the message to the available queue
623                 add_dir($ref); 
624                 
625         }
626 }
627
628 # add the message to the directory listing
629 sub add_dir
630 {
631         my $ref = shift;
632         confess "tried to add a non-ref to the msg directory" if !ref $ref;
633         push @msg, $ref;
634 }
635
636 # return all the current messages
637 sub get_all
638 {
639         return @msg;
640 }
641
642 # get a particular message
643 sub get
644 {
645         my $msgno = shift;
646         for (@msg) {
647                 return $_ if $_->{msgno} == $msgno;
648                 last if $_->{msgno} > $msgno;
649         }
650         return undef;
651 }
652
653 # return the official filename for a message no
654 sub filename
655 {
656         return sprintf "$msgdir/m%06d", shift;
657 }
658
659 #
660 # return a list of valid elements 
661
662
663 sub fields
664 {
665         return keys(%valid);
666 }
667
668 #
669 # return a prompt for a field
670 #
671
672 sub field_prompt
673
674         my ($self, $ele) = @_;
675         return $valid{$ele};
676 }
677
678 #
679 # send a message state machine
680 sub do_send_stuff
681 {
682         my $self = shift;
683         my $line = shift;
684         my @out;
685         
686         if ($self->state eq 'send1') {
687                 #  $DB::single = 1;
688                 confess "local var gone missing" if !ref $self->{loc};
689                 my $loc = $self->{loc};
690                 $loc->{subject} = $line;
691                 $loc->{lines} = [];
692                 $self->state('sendbody');
693                 #push @out, $self->msg('sendbody');
694                 push @out, "Enter Message /EX (^Z) to send or /ABORT (^Y) to exit";
695         } elsif ($self->state eq 'sendbody') {
696                 confess "local var gone missing" if !ref $self->{loc};
697                 my $loc = $self->{loc};
698                 if ($line eq "\032" || uc $line eq "/EX") {
699                         my $to;
700                         
701                         if (@{$loc->{lines}} > 0) {
702                                 foreach $to (@{$loc->{to}}) {
703                                         my $ref;
704                                         my $systime = $main::systime;
705                                         my $mycall = $main::mycall;
706                                         $ref = DXMsg->alloc(DXMsg::next_transno('Msgno'),
707                                                                                 uc $to,
708                                                                                 $self->call, 
709                                                                                 $systime,
710                                                                                 $loc->{private}, 
711                                                                                 $loc->{subject}, 
712                                                                                 $mycall,
713                                                                                 '0',
714                                                                                 $loc->{rrreq});
715                                         $ref->store($loc->{lines});
716                                         $ref->add_dir();
717                                         #push @out, $self->msg('sendsent', $to);
718                                         push @out, "msgno $ref->{msgno} sent to $to";
719                                         my $dxchan = DXChannel->get(uc $to);
720                                         if ($dxchan) {
721                                                 if ($dxchan->is_user()) {
722                                                         $dxchan->send("New mail has arrived for you");
723                                                 }
724                                         }
725                                 }
726                         }
727                         delete $loc->{lines};
728                         delete $loc->{to};
729                         delete $self->{loc};
730                         $self->state('prompt');
731                         $self->func(undef);
732                         DXMsg::queue_msg(0);
733                 } elsif ($line eq "\031" || uc $line eq "/ABORT" || uc $line eq "/QUIT") {
734                         #push @out, $self->msg('sendabort');
735                         push @out, "aborted";
736                         delete $loc->{lines};
737                         delete $loc->{to};
738                         delete $self->{loc};
739                         $self->func(undef);
740                         $self->state('prompt');
741                 } else {
742                         
743                         # i.e. it ain't and end or abort, therefore store the line
744                         push @{$loc->{lines}}, length($line) > 0 ? $line : " ";
745                 }
746         }
747         return (1, @out);
748 }
749
750 # return the standard directory line for this ref 
751 sub dir
752 {
753         my $ref = shift;
754         return sprintf "%6d%s%s%5d %8.8s %8.8s %-6.6s %5.5s %-30.30s", 
755                 $ref->msgno, $ref->read ? '-' : ' ', $ref->private ? 'p' : ' ', $ref->size,
756                         $ref->to, $ref->from, cldate($ref->t), ztime($ref->t), $ref->subject;
757 }
758
759 no strict;
760 sub AUTOLOAD
761 {
762         my $self = shift;
763         my $name = $AUTOLOAD;
764         return if $name =~ /::DESTROY$/;
765         $name =~ s/.*:://o;
766         
767         confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
768         @_ ? $self->{$name} = shift : $self->{$name} ;
769 }
770
771 1;
772
773 __END__