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