added shellregex
[spider.git] / cmd / directory.pl
1 #
2 # show the contents of the message directory
3 #
4 # Copyright (c) Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $line) = @_;
10 my @f = split /\s+/, $line;
11 my @ref;
12 my $ref;
13 my @out;
14 my $f;
15 my $n;
16
17 while (@f) {
18         $f = uc shift @f;
19         if ($f eq 'ALL') {
20                 foreach $ref (DXMsg::get_all()) { 
21                         next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
22                         push @ref, $ref;
23                 }
24         } elsif ($f =~ /^O/o) {         # dir/own
25                 foreach $ref (DXMsg::get_all()) { 
26                         push @ref, $ref if $ref->private && ($ref->to eq $self->call || $ref->from eq $self->call);
27                 }
28         } elsif ($f =~ /^N/o) {         # dir/new
29                 foreach $ref (DXMsg::get_all()) { 
30                         push @ref, $ref if $ref->private && !$ref->read && $ref->to eq $self->call;
31                 }
32         } elsif ($f > 0) {              # a number of items
33                 $n = $f;
34         } else {
35                 my @all = (DXMsg::get_all());
36                 my ($i, $count);
37                 for ($i = $#all; $i > 0; $i--) {
38                         $ref = $all[$i];
39                         next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
40                         unshift @ref, $ref;
41                         last if ++$count > $n;
42                 }
43         }
44 }
45
46 foreach $ref (@ref) {
47         push @out, $ref->dir;
48 }
49
50 return (1, @out);