added regex to sh/files
[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 = 10;
16
17 if (!@f) {
18         my @all = (DXMsg::get_all());
19         my ($i, $count);
20         for ($i = $#all; $i > 0; $i--) {
21                 $ref = $all[$i];
22                 next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
23                 unshift @ref, $ref;
24                 last if ++$count >= $n;
25         }
26 }
27
28 while (@f) {
29         $f = uc shift @f;
30         if ($f eq 'ALL') {
31                 foreach $ref (DXMsg::get_all()) { 
32                         next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
33                         push @ref, $ref;
34                 }
35                 last;
36         } elsif ($f =~ /^O/o) {         # dir/own
37                 foreach $ref (DXMsg::get_all()) { 
38                         push @ref, $ref if $ref->private && ($ref->to eq $self->call || $ref->from eq $self->call);
39                 }
40         } elsif ($f =~ /^N/o) {         # dir/new
41                 foreach $ref (DXMsg::get_all()) { 
42                         push @ref, $ref if $ref->private && !$ref->read && $ref->to eq $self->call;
43                 }
44         } elsif ($f eq '>' || $f eq 'TO'){
45                 $f = uc shift @f;
46                 if ($f) {
47                         $f = shellregex($f);
48                         foreach $ref (DXMsg::get_all()) { 
49                                 next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
50                                 next unless $ref->to =~ m{$f};
51                                 push @ref, $ref;
52                         }
53                 }
54         } elsif ($f eq '<' || $f eq 'FROM'){
55                 $f = uc shift @f;
56                 if ($f) {
57                         $f = shellregex($f);
58                         foreach $ref (DXMsg::get_all()) { 
59                                 next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call;
60                                 next unless $ref->from =~ m{$f};
61                                 push @ref, $ref;
62                         }
63                 }
64         } elsif ($f =~ /^\d+$/ && $f > 0) {             # a number of items
65                 $n = $f;
66         }
67 }
68
69 if (@ref) {
70         my $i = @ref - $n;
71         $i = 0 unless $i > 0;
72         my $count;
73         while ($i < @ref) {
74                 $ref = $ref[$i++];
75                 push @out, $ref->dir;
76                 last if ++$count >= $n;
77         }
78 } else {
79         push @out, $self->msg('e3', 'directory', $line); 
80 }
81 return (1, @out);