fix console.pl max scroll depth
[spider.git] / cmd / directory.pl
1 #
2 # show the contents of the message directory
3 #
4 # Copyright (c) Dirk Koopman G1TLH
5 #
6 #
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 = 0;
16
17 # select candidates
18 my @all = grep {!$_->private || !($self->priv < 5 && $_->to ne $self->call && $_->from ne $self->call)} (DXMsg::get_all());
19 @all =  grep {!$_->delete  || ($self->priv >= 5 && $_->delete)} @all;
20
21 return (1, $self->msg('dir1')) unless @all;
22 my $sel = 0;
23 my $from = 0;
24 my $to = $all[@all-1]->msgno;
25
26 while (@f) {
27         $f = uc shift @f;
28         if ($f eq 'ALL') {
29                 @ref = @all;
30                 $n = @ref;
31                 $sel++;
32         } elsif ($f =~ /^O/o) {         # dir/own
33                 @ref = grep { $_->to eq $self->call || $_->from eq $self->call } @all;
34                 $sel++;
35         } elsif ($f =~ /^N/o) {         # dir/new
36                 @ref = grep { $_->t > $self->user->lastin } @all;
37                 $sel++;
38         } elsif ($f =~ /^S/o) {     # dir/subject
39                 $f = shift @f;
40                 if ($f) {
41                         $f =~ s{(.)}{"\Q$1"}ge;
42                         @ref = grep { $_->subject =~ m{$f}i } @all;
43                         $sel++;
44                 }
45         } elsif ($f eq '>' || $f =~ /^T/o){  
46                 $f = uc shift @f;
47                 if ($f) {
48                         $f = shellregex($f);
49                         @ref = grep { $_->to =~ m{$f} } @all;
50                         $sel++;
51                 }
52         } elsif ($f eq '<' || $f =~ /^F/o){
53                 $f = uc shift @f;
54                 if ($f) {
55                         $f = shellregex($f);
56                         @ref = grep { $_->from =~ m{$f} } @all;
57                         $sel++;
58                 }
59         } elsif ($f =~ /^(\d+)-(\d+)$/) {               # a range of items
60                 $from = $1;
61                 $to = $2;
62         } elsif ($f =~ /^\d+$/ && $f > 0) {             # a number of items
63                 $n = $f;
64         }
65 }
66
67 $n = 10 unless $n;
68 @ref = @all unless $sel || @ref;
69
70 if (@ref) {
71         if ($from != 0 || $to != $all[@all-1]->msgno) {
72                 @ref = grep {$_->msgno >= $from && $_->msgno <= $to} @ref;
73         }
74         my $i = @ref - $n;
75         $i = 0 unless $i > 0;
76         my $count;
77         while ($i < @ref) {
78                 $ref = $ref[$i++];
79                 push @out, $ref->dir;
80                 last if ++$count >= $n;
81         }
82 } else {
83         push @out, $self->msg('dir1'); 
84 }
85 return (1, @out);