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